initial commit
[namibia] / module / Company / src / Company / Entity / DeviceRegistration.php
1 <?php
2 namespace Company\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A company mobile device registration.
10  *
11  * @ORM\Entity
12  * @ORM\HasLifecycleCallbacks
13  * @ORM\Table(name="company_device_registration")
14  */
15 class DeviceRegistration
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\ManyToOne(targetEntity="\Company\Entity\Company")
40          * @ORM\JoinColumn(nullable=false, name="company_id")
41          **/
42         protected $company;
43
44         /**
45          * @ORM\ManyToOne(targetEntity="\User\Entity\Profile")
46          * @ORM\JoinColumn(nullable=false, name="profile_id")
47          **/
48         protected $profile;
49
50         /**
51          * @ORM\ManyToOne(targetEntity="\Company\Entity\Device")
52          * @ORM\JoinColumn(nullable=false, name="device_id")
53          **/
54         protected $device;
55
56         /**
57          * @ORM\Column(type="string", length=100, name="push_key", nullable=false)
58          */
59         protected $pushKey;
60
61         /**
62          * @ORM\Column(type="datetime");
63          */
64         protected $created;
65
66         /**
67          * @ORM\Column(type="datetime", nullable=true);
68          */
69         protected $updated;
70
71         /**
72          * @ORM\Column(type="boolean");
73          */
74         protected $archived = false;
75
76
77
78
79
80         /**
81          * Magic getter to expose protected properties.
82          * @param string $property
83          * @return mixed
84          */
85         public function __get($property)
86         {
87                 return $this->$property;
88         }
89
90         /**
91          * Magic setter to save protected properties.
92          * @param string $property
93          * @param mixed $value
94          */
95         public function __set($property, $value)
96         {
97                 $this->$property = $value;
98         }
99
100         /**
101          * @ORM\PrePersist
102          */
103         public function setCreateTime()
104         {
105                 $this->created = new \DateTime("now");
106         }
107
108         /**
109          * @ORM\PreUpdate
110          */
111         public function setUpdateTime()
112         {
113                 $this->updated = new \DateTime("now");
114         }
115
116         /**
117          * Convert the object to an array.
118          * @param array $expand
119          * @param array $intersect
120          * @param boolean $showIdentifiers
121          * @param integer $expandAll
122          * @return array
123          */
124         public function toArray(
125                         array $expand = array(), array $intersect = array(),
126                         $showIdentifiers = false, $expandAll = 0
127                         )
128         {
129                 $intersect = array_flip($intersect);
130                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
131                 $includeAll = empty($intersect);
132                 $recExpand = $expand;
133                 foreach($recExpand as $i => $val)
134                 {
135                         if ('company' == $val || 'tradeCenter' == $val)
136                         {
137                                 unset($recExpand[$i]);
138                         }
139                 }
140                 $data = array();
141                 ($includeAll || isset($intersect['id']))
142                         && $data['id'] = $this->id;
143                 ($includeAll || isset($intersect['pushKey']))
144                         && $data['pushKey'] = $this->pushKey;
145                 ($includeAll || isset($intersect['company']))
146                         && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
147                                                                         && !is_null($this->company)
148                                 ? (!$showIdentifiers || in_array('company', $expand) ? $this->company->toArray(
149                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
150                                                 ) : $this->company->id)
151                                 : null;
152                 ($includeAll || isset($intersect['profile']))
153                         && $data['profile'] = (in_array('profile', $expand) || $expandAll || $showIdentifiers)
154                                                                         && !is_null($this->profile)
155                                 ? (!$showIdentifiers || in_array('profile', $expand) ? $this->profile->toArray(
156                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
157                                                 ) : $this->profile->id)
158                                 : null;
159                 ($includeAll || isset($intersect['device']))
160                         && $data['device'] = (in_array('device', $expand) || $expandAll || $showIdentifiers)
161                                                                         && !is_null($this->device)
162                                 ? (!$showIdentifiers || in_array('device', $expand) ? $this->device->toArray(
163                                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
164                                                 ) : $this->device->id)
165                                 : null;
166                 ($includeAll || isset($intersect['created']))
167                         && $data['created'] = !is_null($this->created)
168                                 ? $this->created->format($dateTimeFormat)
169                                 : null;
170                 ($includeAll || isset($intersect['updated']))
171                         && $data['updated'] = !is_null($this->updated)
172                                 ? $this->updated->format($dateTimeFormat)
173                                 : null;
174                 return $data;
175         }
176
177         /**
178          * Populate from an array.
179          * @param array $data
180          */
181         public function fromArray($data = array())
182         {
183                 isset($data['id'])
184                         && $this->id = $data['id'];
185                 isset($data['pushKey'])
186                         && $this->pushKey = $data['pushKey'];
187                 isset($data['company'])
188                         && $this->company = $data['company'];
189                 isset($data['profile'])
190                         && $this->profile = $data['profile'];
191                 isset($data['device'])
192                         && $this->device = $data['device'];
193         }
194
195 }