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