dcf51c7fd96f533896d959d68b14df46b7ee53b4
[zf2.biz/galerie.git] / module / Galerie / src / Galerie / Model / GalerieC.php
1 <?php
2
3 namespace Galerie\Model;
4
5 class GalerieC
6 {
7     public $id;
8     public $id_user;
9     public $name;
10     public $description;
11     public $created;
12     public $updated;
13
14
15     protected $columns = array(
16         'id',
17         'id_user',
18         'name',
19         'description',
20         'created',
21         'updated',
22     );
23
24     protected $updatable_columns = array(
25         'id_user',
26         'name',
27         'description',
28         'created',
29         'updated',
30     );
31
32     protected $primary_columns = array(
33         'id',
34     );
35
36     public function exchangeArray($data, $overwrite=true)
37     {
38         foreach($this->columns as $col) {
39             if (array_key_exists($col, $data)) {
40                 $this->$col = $data[$col];
41             } elseif ($overwrite) {
42                 $this->$col = null;
43             }
44         }
45     }
46
47     public function toArray() {
48         $result = array();
49         foreach($this->columns as $col) {
50             $result[$col] = $this->$col;
51         }
52         return $result;
53     }
54
55     public function toUpdatableArray() {
56         $result = array();
57         foreach($this->updatable_columns as $col) {
58             $result[$col] = $this->$col;
59         }
60         return $result;
61     }
62
63     public function toPrimaryArray() {
64         $result = array();
65         foreach($this->primary_columns as $col) {
66             $result[$col] = $this->$col;
67         }
68         return $result;
69     }
70
71 }