initial commit
[namibia] / module / Stock / src / Stock / Entity / Model.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_model")
12  */
13 class Model
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="Make", inversedBy="models")
38          * @ORM\JoinColumn(name="vehicle_make_id", referencedColumnName="id")
39          **/
40         protected $make;
41
42         /**
43          * @ORM\Column(type="string", length=75)
44          */
45         protected $name;
46
47         /**
48          * @ORM\Column(type="datetime");
49          */
50         protected $created;
51
52         /**
53          * @ORM\Column(type="datetime", nullable=true);
54          */
55         protected $updated;
56
57         /**
58          * @ORM\Column(type="smallint", nullable=true, name="create_version", options={"unsigned"=true})
59          */
60         protected $createVersion;
61
62         /**
63          * @ORM\Column(type="smallint", nullable=true, name="update_version", options={"unsigned"=true})
64          */
65         protected $updateVersion;
66
67         /**
68          * @ORM\Column(type="boolean");
69          */
70         protected $archived = false;
71
72         /**
73          * @ORM\OneToMany(targetEntity="Type", mappedBy="model", fetch="EXTRA_LAZY")
74          **/
75         private $types;
76
77
78         /**
79          * Initialize collections.
80          */
81         public function __construct()
82         {
83                 $this->types = new \Doctrine\Common\Collections\ArrayCollection();
84         }
85
86         /**
87          * Add a new Region to this Country.
88          * @param Type $type
89          * @return \Stock\Entity\Region
90          */
91         public function addType(Type $type)
92         {
93                 $this->types[] = $type;
94                 return $this;
95         }
96
97         /**
98          * Magic getter to expose protected properties.
99          * @param string $property
100          * @return mixed
101          */
102         public function __get($property)
103         {
104                 return $this->$property;
105         }
106
107         /**
108          * Magic setter to save protected properties.
109          * @param string $property
110          * @param mixed $value
111          */
112         public function __set($property, $value)
113         {
114                 $this->$property = $value;
115         }
116
117         /**
118          * @ORM\PrePersist
119          */
120         public function setCreateTime()
121         {
122                 $this->created = new \DateTime("now");
123         }
124
125         /**
126          * @ORM\PreUpdate
127          */
128         public function setUpdateTime()
129         {
130                 $this->updated = new \DateTime("now");
131         }
132
133         /**
134          * Convert the object to an array.
135          * @param array $expand
136          * @param array $intersect
137          * @return array
138          */
139         public function toArray(array $expand = array(), array $intersect = array())
140         {
141                 $includeAll = empty($intersect);
142                 $data = array();
143                 ($includeAll || isset($intersect['id']))
144                         && $data['id'] = $this->id;
145                 ($includeAll || isset($intersect['make']))
146                         && in_array('make', $expand)
147                         && $data['make'] = $this->make->toArray($expand, $intersect);
148                 ($includeAll || isset($intersect['name']))
149                         && $data['name'] = $this->name;
150                 return $data;
151         }
152
153         /**
154          * Convert the object to an array for synchronization.
155          * @return array
156          */
157         public function toSynchArray()
158         {
159                 return array(
160                                 'id'   => $this->id,
161                                 'make' => $this->make->id,
162                                 'name' => $this->name
163                 );
164         }
165
166         /**
167          * Populate from an array.
168          * @param array $data
169          */
170         public function fromArray($data = array())
171         {
172                 isset($data['id'])
173                         && $this->id = $data['id'];
174                 isset($data['make'])
175                         && $this->make  = $data['make'];
176                 isset($data['name'])
177                         && $this->name  = $data['name'];
178                 isset($data['createVersion'])
179                         && $this->createVersion  = $data['createVersion'];
180                 isset($data['updateVersion'])
181                         && $this->updateVersion  = $data['updateVersion'];
182         }
183
184 }