initial commit
[namibia] / module / Company / src / Company / Entity / Device.php
1 <?php
2 namespace Company\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A company mobile device.
10  *
11  * @ORM\Entity
12  * @ORM\HasLifecycleCallbacks
13  * @ORM\Table(name="company_device")
14  */
15 class Device
16 {
17
18         /**
19          * Can archive records.
20          */
21         const ARCHIVE = true;
22         /**
23          * Pull Synchronization Strategy for this table.
24          */
25         const PULL_SYNCH_STRATEGY = false;
26         /**
27          * Push Synchronization Strategy for this table.
28          */
29         const PUSH_SYNCH_STRATEGY = false;
30
31         /**
32          * @ORM\Id
33          * @ORM\Column(type="integer");
34          * @ORM\GeneratedValue(strategy="AUTO")
35          */
36         protected $id;
37
38         /**
39          * @ORM\Column(type="string", length=100, name="android_id", nullable=false)
40          */
41         protected $deviceId;
42
43         /**
44          * @ORM\Column(type="string", length=200, name="registration_id", nullable=true)
45          */
46         protected $registrationId;
47
48         /**
49          * @ORM\OneToMany(targetEntity="DeviceRegistration", mappedBy="device", fetch="EXTRA_LAZY")
50          **/
51         protected $deviceRegistrations;
52
53         /**
54          * @ORM\Column(type="datetime");
55          */
56         protected $created;
57
58         /**
59          * @ORM\Column(type="datetime", nullable=true);
60          */
61         protected $updated;
62
63         /**
64          * @ORM\Column(type="boolean");
65          */
66         protected $archived = false;
67
68
69
70         /**
71          * Initialize collections.
72          */
73         public function __construct()
74         {
75                 $this->deviceRegistrations = new \Doctrine\Common\Collections\ArrayCollection();
76         }
77
78
79         /**
80          * Magic getter to expose protected properties.
81          * @param string $property
82          * @return mixed
83          */
84         public function __get($property)
85         {
86                 return $this->$property;
87         }
88
89         /**
90          * Magic setter to save protected properties.
91          * @param string $property
92          * @param mixed $value
93          */
94         public function __set($property, $value)
95         {
96                 $this->$property = $value;
97         }
98
99         /**
100          * @ORM\PrePersist
101          */
102         public function setCreateTime()
103         {
104                 $this->created = new \DateTime("now");
105         }
106
107         /**
108          * @ORM\PreUpdate
109          */
110         public function setUpdateTime()
111         {
112                 $this->updated = new \DateTime("now");
113         }
114
115         /**
116          * Convert the object to an array.
117          * @param array $expand
118          * @param array $intersect
119          * @param boolean $showIdentifiers
120          * @param integer $expandAll
121          * @return array
122          */
123         public function toArray(
124                         array $expand = array(), array $intersect = array(),
125                         $showIdentifiers = false, $expandAll = 0
126                         )
127         {
128                 $intersect = array_flip($intersect);
129                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
130                 $includeAll = empty($intersect);
131                 $recExpand = $expand;
132                 foreach($recExpand as $i => $val)
133                 {
134                         if ('company' == $val || 'tradeCenter' == $val)
135                         {
136                                 unset($recExpand[$i]);
137                         }
138                 }
139                 $data = array();
140                 ($includeAll || isset($intersect['id']))
141                         && $data['id'] = $this->id;
142                 ($includeAll || isset($intersect['deviceId']))
143                         && $data['deviceId'] = $this->deviceId;
144                 ($includeAll || isset($intersect['registrationId']))
145                         && $data['registrationId'] = $this->registrationId;
146                 ($includeAll || isset($intersect['created']))
147                         && $data['created'] = !is_null($this->created)
148                                 ? $this->created->format($dateTimeFormat)
149                                 : null;
150                 ($includeAll || isset($intersect['updated']))
151                         && $data['updated'] = !is_null($this->updated)
152                                 ? $this->updated->format($dateTimeFormat)
153                                 : null;
154                 return $data;
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['deviceId'])
166                         && $this->deviceId = $data['deviceId'];
167                 isset($data['registrationId'])
168                 && $this->registrationId = $data['registrationId'];
169         }
170
171 }