text changes to registration mail content
[namibia] / module / Stock / src / Stock / Entity / Accessory.php
1 <?php
2 namespace Stock\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7 /**
8  * @ORM\Entity
9  * @ORM\Table(name="vehicle_accessory", uniqueConstraints={@ORM\UniqueConstraint(name="unique_accessory",
10  *                                      columns={"name"})})
11  */
12 class Accessory
13 {
14
15         /**
16          * Can archive records.
17          */
18         const ARCHIVE = true;
19         /**
20          * Pull Synchronization Strategy for this table.
21          */
22         const PULL_SYNCH_STRATEGY = 'Update';
23         /**
24          * Push Synchronization Strategy for this table.
25          */
26         const PUSH_SYNCH_STRATEGY = 'Update';
27
28
29         /**
30          * @ORM\Id
31          * @ORM\Column(type="integer");
32          * @ORM\GeneratedValue(strategy="AUTO")
33          */
34         protected $id;
35
36         /**
37          * @ORM\Column(type="string", length=75, unique=true)
38          */
39         protected $name;
40
41         /**
42          * @ORM\Column(type="smallint", nullable=true, name="create_version", options={"unsigned"=true})
43          */
44         protected $createVersion;
45
46         /**
47          * @ORM\Column(type="smallint", nullable=true, name="update_version", options={"unsigned"=true})
48          */
49         protected $updateVersion;
50
51         /**
52          * @ORM\Column(type="boolean");
53          */
54         protected $archived = false;
55
56
57
58         /**
59          * Magic getter to expose protected properties.
60          * @param string $property
61          * @return mixed
62          */
63         public function __get($property)
64         {
65                 return $this->$property;
66         }
67
68         /**
69          * Magic setter to save protected properties.
70          * @param string $property
71          * @param mixed  $value
72          */
73         public function __set($property, $value)
74         {
75                 $this->$property = $value;
76         }
77
78         /**
79          * @ORM\PrePersist
80          */
81         public function setCreateVersion()
82         {
83                 $version = 1;
84                 $items = \Utility\Registry::getEntityManager()
85                         ->getRepository('Stock\\Entity\\Accessory')
86                         ->findAll();
87                 foreach ($items as $item)
88                 {
89                         if ($item->createVersion > $version)
90                         {
91                                 $version = $item->createVersion;
92                         }
93                         if ($item->updateVersion > $version)
94                         {
95                                 $version = $item->updateVersion;
96                         }
97                 }
98                 $this->createVersion = $version;
99         }
100
101         /**
102          * @ORM\PreUpdate
103          */
104         public function setUpdateVersion()
105         {
106                 $version = 1;
107                 $items = \Utility\Registry::getEntityManager()
108                         ->getRepository('Stock\\Entity\\Accessory')
109                         ->findAll();
110                 foreach ($items as $item)
111                 {
112                         if ($item->createVersion > $version)
113                         {
114                                 $version = $item->createVersion;
115                         }
116                         if ($item->updateVersion > $version)
117                         {
118                                 $version = $item->updateVersion;
119                         }
120                 }
121                 $this->updateVersion = $version;
122         }
123
124         /**
125          * Convert the object to an array.
126          * @param array $expand
127          * @param array $intersect
128          * @return array
129          */
130         public function toArray(array $expand = array(), array $intersect = array())
131         {
132                 !empty($intersect)
133                 && $intersect = array_flip($intersect);
134                 $includeAll = empty($intersect);
135                 $data       = array();
136                 ($includeAll || isset($intersect['id']))
137                 && $data['id'] = $this->id;
138                 ($includeAll || isset($intersect['name']))
139                 && $data['name'] = $this->name;
140                 return $data;
141         }
142
143         /**
144          * Convert the object to an array for synchronization.
145          * @return array
146          */
147         public function toSynchArray()
148         {
149                 return array(
150                         'id'   => $this->id,
151                         'name' => $this->name
152                 );
153         }
154
155         /**
156          * Populate from an array.
157          * @param array $data
158          */
159         public function fromArray($data = array())
160         {
161                 isset($data['id'])
162                 && $this->id = $data['id'];
163                 isset($data['name'])
164                 && $this->name = $data['name'];
165                 isset($data['createVersion'])
166                 && $this->createVersion = $data['createVersion'];
167                 isset($data['updateVersion'])
168                 && $this->updateVersion = $data['updateVersion'];
169         }
170
171 }