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