Rajout du modèle C
[zf2.biz/galerie.git] / module / Galerie / src / Galerie / Model / GalerieC.php
diff --git a/module/Galerie/src/Galerie/Model/GalerieC.php b/module/Galerie/src/Galerie/Model/GalerieC.php
new file mode 100644 (file)
index 0000000..dcf51c7
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+namespace Galerie\Model;
+
+class GalerieC
+{
+    public $id;
+    public $id_user;
+    public $name;
+    public $description;
+    public $created;
+    public $updated;
+
+
+    protected $columns = array(
+        'id',
+        'id_user',
+        'name',
+        'description',
+        'created',
+        'updated',
+    );
+
+    protected $updatable_columns = array(
+        'id_user',
+        'name',
+        'description',
+        'created',
+        'updated',
+    );
+
+    protected $primary_columns = array(
+        'id',
+    );
+
+    public function exchangeArray($data, $overwrite=true)
+    {
+        foreach($this->columns as $col) {
+            if (array_key_exists($col, $data)) {
+                $this->$col = $data[$col];
+            } elseif ($overwrite) {
+                $this->$col = null;
+            }
+        }
+    }
+
+    public function toArray() {
+        $result = array();
+        foreach($this->columns as $col) {
+            $result[$col] = $this->$col;
+        }
+        return $result;
+    }
+
+    public function toUpdatableArray() {
+        $result = array();
+        foreach($this->updatable_columns as $col) {
+            $result[$col] = $this->$col;
+        }
+        return $result;
+    }
+
+    public function toPrimaryArray() {
+        $result = array();
+        foreach($this->primary_columns as $col) {
+            $result[$col] = $this->$col;
+        }
+        return $result;
+    }
+
+}