Rajout d'une bibliothèque Custom
[zf2.biz/application_blanche.git] / vendor / zf2biz / Custom / Model / Entity.php
diff --git a/vendor/zf2biz/Custom/Model/Entity.php b/vendor/zf2biz/Custom/Model/Entity.php
new file mode 100644 (file)
index 0000000..7788491
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+namespace Custom\Model;
+
+class Entity
+{
+
+    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;
+    }
+}