initial commit
[namibia] / module / Stock / src / Stock / Entity / Type.php
1 <?php
2 namespace Stock\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * @ORM\Entity
10  * @ORM\HasLifecycleCallbacks
11  * @ORM\Table(name="vehicle_type")
12  */
13 class Type
14 {
15
16         /**
17          * Can archive records.
18          */
19         const ARCHIVE = true;
20         /**
21          * Pull Synchronization Strategy for this table.
22          */
23         const PULL_SYNCH_STRATEGY = 'Update';
24         /**
25          * Push Synchronization Strategy for this table.
26          */
27         const PUSH_SYNCH_STRATEGY = 'Update';
28
29         /**
30          * @ORM\Id
31          * @ORM\Column(type="integer");
32          * @ORM\GeneratedValue(strategy="AUTO")
33          */
34         protected $id;
35
36         /**
37          * @ORM\ManyToOne(targetEntity="Model", inversedBy="types")
38          * @ORM\JoinColumn(name="vehicle_model_id", referencedColumnName="id")
39          **/
40         protected $model;
41
42         /**
43          * @ORM\ManyToOne(targetEntity="Category")
44          * @ORM\JoinColumn(name="vehicle_category_id", referencedColumnName="id")
45          **/
46         protected $category;
47
48         /**
49          * @ORM\Column(type="string", length=150)
50          */
51         protected $name;
52
53         /**
54          * @ORM\Column(type="string", length=10, name="mm_code")
55          */
56         protected $mmCode;
57
58         /**
59          * @ORM\ManyToOne(targetEntity="Year")
60          * @ORM\JoinColumn(nullable=false, name="intro_vehicle_year_id")
61          **/
62         private $introYear;
63
64         /**
65          * @ORM\Column(type="smallint", name="intro_month")
66          */
67         protected $introMonth;
68
69         /**
70          * @ORM\ManyToOne(targetEntity="Year")
71          * @ORM\JoinColumn(nullable=true, name="disc_vehicle_year_id")
72          **/
73         protected $discYear;
74
75         /**
76          * @ORM\Column(type="smallint", nullable=true, name="disc_month")
77          */
78         protected $discMonth;
79
80         /**
81          * @ORM\Column(type="smallint", nullable=true)
82          */
83         protected $cylinders;
84
85         /**
86          * @ORM\Column(type="integer", nullable=true, name="cubic_capacity")
87          */
88         protected $cubicCapacity;
89
90         /**
91          * @ORM\Column(type="smallint", nullable=true)
92          */
93         protected $kilowatts;
94
95         /**
96          * @ORM\Column(type="string", nullable=true, length=25, name="body_type")
97          */
98         protected $bodyType;
99
100         /**
101          * @ORM\Column(type="smallint", nullable=true)
102          */
103         protected $doors;
104
105
106         /**
107          * @ORM\Column(type="datetime");
108          */
109         protected $created;
110
111         /**
112          * @ORM\Column(type="datetime", nullable=true);
113          */
114         protected $updated;
115
116         /**
117          * @ORM\Column(type="smallint", nullable=true, name="create_version", options={"unsigned"=true})
118          */
119         protected $createVersion;
120
121         /**
122          * @ORM\Column(type="smallint", nullable=true, name="update_version", options={"unsigned"=true})
123          */
124         protected $updateVersion;
125
126         /**
127          * @ORM\Column(type="boolean");
128          */
129         protected $archived = false;
130
131
132         /**
133          * Magic getter to expose protected properties.
134          *
135          * @param string $property
136          * @return mixed
137          */
138         public function __get($property)
139         {
140                 return $this->$property;
141         }
142
143         /**
144          * Magic setter to save protected properties.
145          *
146          * @param string $property
147          * @param mixed $value
148          */
149         public function __set($property, $value)
150         {
151                 $this->$property = $value;
152         }
153
154         /**
155          * @ORM\PrePersist
156          */
157         public function setCreateTime()
158         {
159                 $this->created = new \DateTime("now");
160         }
161
162         /**
163          * @ORM\PreUpdate
164          */
165         public function setUpdateTime()
166         {
167                 $this->updated = new \DateTime("now");
168         }
169
170         /**
171          * Convert the object to an array.
172          * @param array $expand
173          * @param array $intersect
174          * @return array
175          */
176         public function toArray(array $expand = array(), array $intersect = array())
177         {
178                 $includeAll = empty($intersect);
179                 $data = array();
180                 ($includeAll || isset($intersect['id']))
181                         && $data['id'] = $this->id;
182                 ($includeAll || isset($intersect['model']))
183                         && in_array('model', $expand)
184                         && $data['model'] = $this->model->toArray($expand, $intersect);
185                 ($includeAll || isset($intersect['category']))
186                         && in_array('category', $expand)
187                         && $data['category'] = $this->category->toArray($expand, $intersect);
188                 ($includeAll || isset($intersect['name']))
189                         && $data['name'] = $this->name;
190                 ($includeAll || isset($intersect['mmCode']))
191                         && $data['mmCode'] = $this->mmCode;
192                 ($includeAll || isset($intersect['introYear']))
193                         && in_array('introYear', $expand)
194                         && $data['introYear'] = $this->introYear->toArray($expand, $intersect);
195                 ($includeAll || isset($intersect['introMonth']))
196                         && $data['introMonth'] = $this->introMonth;
197                 ($includeAll || isset($intersect['discYear']))
198                         && in_array('discYear', $expand)
199                         && $data['discYear'] = !is_null($this->discYear)
200                                 ? $this->discYear->toArray($expand, $intersect)
201                                 : null;
202                 ($includeAll || isset($intersect['discMonth']))
203                         && $data['discMonth'] = $this->discMonth;
204                 ($includeAll || isset($intersect['created']))
205                         && $data['created'] = !is_null($this->created)
206                                 ? $this->created->format(\Utility\Registry::getConfigParam('DateTimeFormat'))
207                                 : null;
208                 ($includeAll || isset($intersect['updated']))
209                         && $data['updated'] = !is_null($this->updated)
210                                 ? $this->updated->format(\Utility\Registry::getConfigParam('DateTimeFormat'))
211                                 : null;
212                 return $data;
213         }
214
215         /**
216          * Convert the object to an array for synchronization.
217          * @return array
218          */
219         public function toSynchArray()
220         {
221                 return array(
222                                 'id'        => $this->id,
223                                 'model'     => $this->model->id,
224                                 'category'  => $this->category->id,
225                                 'name'      => $this->name,
226                                 'mmCode'    => $this->mmCode,
227                                 'introYear' => $this->introYear->id,
228                                 'diskYear'  => !is_null($this->discYear)
229                                                                         ? $this->discYear->id
230                                                                         : 0
231                 );
232         }
233
234         /**
235          * Populate from an array.
236          * @param array $data
237          */
238         public function fromArray($data = array())
239         {
240                 isset($data['id'])
241                         && $this->id = $data['id'];
242                 isset($data['model'])
243                         && $this->model  = $data['model'];
244                 isset($data['category'])
245                         && $this->category  = $data['category'];
246                 isset($data['name'])
247                         && $this->name  = $data['name'];
248                 isset($data['mmCode'])
249                         && $this->mmCode  = $data['mmCode'];
250                 isset($data['introYear'])
251                         && $this->introYear  = $data['introYear'];
252                 isset($data['introMonth'])
253                         && $this->introMonth  = $data['introMonth'];
254                 isset($data['discYear'])
255                         && $this->discYear  = $data['discYear'];
256                 isset($data['discMonth'])
257                         && $this->discMonth  = $data['discMonth'];
258                 isset($data['cylinders'])
259                         && $this->cylinders  = $data['cylinders'];
260                 isset($data['cubicCapacity'])
261                         && $this->cubicCapacity  = $data['cubicCapacity'];
262                 isset($data['kilowatts'])
263                         && $this->kilowatts  = $data['kilowatts'];
264                 isset($data['bodyType'])
265                         && $this->bodyType  = $data['bodyType'];
266                 isset($data['doors'])
267                         && $this->doors  = $data['doors'];
268                 isset($data['createVersion'])
269                         && $this->createVersion  = $data['createVersion'];
270                 isset($data['updateVersion'])
271                         && $this->updateVersion  = $data['updateVersion'];
272         }
273
274 }