Correction sur Model\Entity
[zf2.biz/galerie.git] / vendor / zf2biz / Custom / Model / Entity.php
1 <?php
2
3 namespace Custom\Model;
4
5
6 use Zend\InputFilter\Factory as InputFactory;
7 use Zend\InputFilter\InputFilter;
8 use Zend\InputFilter\InputFilterInterface;
9 use Zend\InputFilter\InputFilterAwareInterface;
10
11
12 class Entity implements InputFilterAwareInterface
13 {
14
15     protected $inputFilter;
16
17     public function exchangeArray($data, $overwrite=false)
18     {
19         foreach($this->columns as $col) {
20             if (array_key_exists($col, $data)) {
21                 $this->$col = $data[$col];
22             } elseif ($overwrite) {
23                 $this->$col = null;
24             }
25         }
26     }
27
28     public function toArray() {
29         $result = array();
30         foreach($this->columns as $col) {
31             $result[$col] = $this->$col;
32         }
33         return $result;
34     }
35
36     public function getArrayCopy() {
37         $result = array();
38         foreach($this->columns as $col) {
39             $result[$col] = $this->$col;
40         }
41         return $result;
42     }
43
44     public function toUpdatableArray() {
45         $result = array();
46         foreach($this->updatable_columns as $col) {
47             $result[$col] = $this->$col;
48         }
49         return $result;
50     }
51
52     public function toPrimaryArray() {
53         $result = array();
54         foreach($this->primary_columns as $col) {
55             $result[$col] = $this->$col;
56         }
57         return $result;
58     }
59
60
61
62     public function setInputFilter(InputFilterInterface $inputfilter)
63     {
64         $this->inputFilter = $inputFilter;
65     }
66
67     public function getInputFilter()
68     {
69         if (!$this->inputFilter) {
70             $this->setDefaultInputFilter();
71         }
72         return $this->inputFilter;
73     }
74
75     protected function setDefaultInputFilter()
76     {
77         $inputFilter = new InputFilter;
78         $factory = new InputFactory;
79
80         foreach ($this->getDefaultInputFilterArrays() as $params) {
81             $inputFilter->add($factory->createInput($params));
82         }
83         $this->inputFilter = $inputFilter;
84
85         return $this->inputFilter;
86
87     }
88
89     protected function getDefaultInputFilterArrays()
90     {
91         return array();
92     }
93
94 }