initial commit
[namibia] / module / Valuation / src / Valuation / Entity / ValuationAppointments.php
1 <?php
2 namespace Valuation\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5 use Zend\XmlRpc\Value\DateTime;
6
7
8 /**
9  * A valuation.
10  *
11  * @ORM\Entity
12  * @ORM\HasLifecycleCallbacks
13  * @ORM\Table(name="valuation_appointments")
14  */
15 class ValuationAppointments
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 = 'Build';
26         /**
27          * Push Synchronization Strategy for this table.
28          */
29         const PUSH_SYNCH_STRATEGY = 'Update';
30         /**
31          * Post insert action must be called after new entity is flushed to database.
32          */
33         const HAVE_POST_INSERT = true;
34         /**
35          * Handle as a job queue for mobile devices.
36          */
37         const JOB_QUEUE = true;
38
39         /* ------------------------------------ Identification ------------------------------------ */
40         /**
41          * @ORM\Id
42          * @ORM\Column(type="integer");
43          * @ORM\GeneratedValue(strategy="AUTO")
44          */
45         protected $id;
46
47     /**
48      * @ORM\ManyToOne(targetEntity="\Valuation\Entity\ValuationTimeSlots", cascade={"all"})
49      * @ORM\JoinColumn(nullable=false, name="time_slot_id")
50      **/
51     protected $timeSlot;
52
53     /**
54      * @ORM\ManyToOne(targetEntity="\User\Entity\Profile", cascade={"all"})
55      * @ORM\JoinColumn(nullable=false, name="valuator_profile_id")
56      **/
57     protected $valuator;
58
59     /**
60      * @ORM\ManyToOne(targetEntity="\Valuation\Entity\Valuation", cascade={"all"})
61      * @ORM\JoinColumn(nullable=false, name="valuation_id")
62      **/
63     protected $valuation;
64
65
66     /**
67      * @ORM\Column(type="datetime", nullable=false, name="appointment_date");
68      */
69     protected $appointmentDate;
70
71     /**
72      * @ORM\Column(type="boolean", name="appointment_completed");
73      */
74     protected $appointmentCompleted = false;
75
76
77     /**
78      * @ORM\Column(type="boolean", name="appointment_cancelled");
79      */
80     protected $appointmentCancelled = false;
81     /**
82      * @ORM\Column(type="datetime", name="appointment_date_cancelled", nullable=true);
83      */
84     protected $appointmentDateCancelled;
85     /**
86      * @ORM\Column(type="text", name="appointment_cancelled_comments", nullable=true);
87      */
88     protected $appointmentCancelledComments;
89
90
91
92
93         /**
94          * @ORM\Column(type="datetime");
95          */
96         protected $created;
97
98         /**
99          * @ORM\Column(type="datetime", nullable=true);
100          */
101         protected $updated;
102
103         /**
104          * @ORM\Column(type="boolean");
105          */
106         protected $archived = false;
107
108
109     /**
110      * Magic getter to expose protected properties.
111      *
112      * @param string $property
113      * @return mixed
114      */
115     public function __get($property)
116     {
117         return $this->$property;
118     }
119
120     /**
121      * Magic setter to save protected properties.
122      *
123      * @param string $property
124      * @param mixed $value
125      */
126     public function __set($property, $value)
127     {
128         $this->$property = $value;
129     }
130
131         /**
132          * @ORM\PrePersist
133          */
134         public function setCreateTime()
135         {
136                 $this->created = new \DateTime("now");
137         }
138
139         /**
140          * @ORM\PreUpdate
141          */
142         public function setUpdateTime()
143         {
144                 $this->updated = new \DateTime("now");
145
146         if($this->appointmentCancelled)
147         {
148             $this->appointmentDateCancelled = new \DateTime("now");
149         }
150         }
151
152
153
154         /**
155          * Convert the object to an array.
156          * @param array $expand
157          * @param array $intersect
158          * @param boolean $showIdentifiers
159          * @param integer $expandAll
160          * @return array
161          */
162         public function toArray(
163                         array $expand = array(), array $intersect = array(),
164                         $showIdentifiers = false, $expandAll = 0
165                         )
166         {
167                 $intersect = array_flip($intersect);
168                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
169                 $includeAll = empty($intersect);
170                 $data = array();
171                 ($includeAll || isset($intersect['id']))
172                         && $data['id'] = $this->id;
173
174         ($includeAll || isset($intersect['timeSlot']))
175         && $data['timeSlot'] = (in_array('timeSlot', $expand) || $expandAll || $showIdentifiers)
176         && !is_null($this->timeSlot)
177             ? (!$showIdentifiers || in_array('timeSlot', $expand) ? $this->timeSlot->toArray(
178                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
179             ) : $this->timeSlot->id)
180             : null;
181
182
183         ($includeAll || isset($intersect['valuator']))
184         && $data['valuator'] = (in_array('valuator', $expand) || $expandAll || $showIdentifiers)
185         && !is_null($this->valuator)
186             ? (!$showIdentifiers || in_array('valuator', $expand) ? $this->valuator->toArray(
187                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
188             ) : $this->valuator->id)
189             : null;
190
191         ($includeAll || isset($intersect['valuation']))
192         && $data['valuation'] = (in_array('valuation', $expand) || $expandAll || $showIdentifiers)
193         && !is_null($this->valuation)
194             ? (!$showIdentifiers || in_array('valuation', $expand) ? $this->valuation->toArray(
195                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
196             ) : $this->valuation->id)
197             : null;
198
199
200         ($includeAll || isset($intersect['appointmentDate']))
201         && $data['appointmentDate'] = !is_null($this->appointmentDate)
202             ? $this->appointmentDate->format($dateTimeFormat)
203             : null;
204
205                 ($includeAll || isset($intersect['created']))
206                         && $data['created'] = !is_null($this->created)
207                                 ? $this->created->format($dateTimeFormat)
208                                 : null;
209                 ($includeAll || isset($intersect['updated']))
210                         && $data['updated'] = !is_null($this->updated)
211                                 ? $this->updated->format($dateTimeFormat)
212                                 : null;
213         ($includeAll || isset($intersect['archived']))
214             && $data['archived'] = $this->archived;
215
216         ($includeAll || isset($intersect['appointmentCompleted']))
217         && $data['appointmentCompleted'] = $this->appointmentCompleted;
218         ($includeAll || isset($intersect['appointmentCancelled']))
219         && $data['appointmentCancelled'] = $this->appointmentCancelled;
220
221         ($includeAll || isset($intersect['appointmentDateCancelled']))
222         && $data['appointmentDateCancelled'] = !is_null($this->appointmentDateCancelled)
223             ? $this->appointmentDateCancelled->format($dateTimeFormat)
224             : null;
225
226         ($includeAll || isset($intersect['appointmentCancelledComments']))
227         && $data['appointmentCancelledComments'] = $this->appointmentCancelledComments;
228
229                 return $data;
230         }
231
232
233
234         /**
235          * Populate from an array.
236          * @param array $data
237          */
238         public function fromArray($data = array())
239         {
240 //        unset($data['id']);
241 //        unset($data['timeSlot']);
242 //        unset($data['valuator']);
243 //        unset($data['valuation']);
244 //        unset($data['appointmentCompleted']);
245 //        unset($data['appointmentCancelled']);
246 //        unset($data['appointmentDateCancelled']);
247 //        unset($data['appointmentDateCancelled']);
248 //        unset($data['appointmentCancelledComments']);
249
250
251 //        \Utility\Debug::errorLog('$data',$data);
252
253                 isset($data['id'])
254                         && $this->id = $data['id'];
255
256                 isset($data['timeSlot'])
257                         && $this->timeSlot = $data['timeSlot'];
258                 isset($data['valuator'])
259                         && $this->valuator = $data['valuator'];
260         isset($data['valuation'])
261             && $this->valuation = $data['valuation'];
262         isset($data['appointmentDate'])
263         && $this->appointmentDate = (is_object($data['appointmentDate'])
264             ? $data['appointmentDate']
265             : new \DateTime($data['appointmentDate']));
266         isset($data['appointmentCompleted'])
267         && $this->appointmentCompleted = $data['appointmentCompleted'];
268         isset($data['appointmentCancelled'])
269         && $this->appointmentCancelled = $data['appointmentCancelled'];
270
271         isset($data['appointmentDateCancelled'])
272         && $this->appointmentDateCancelled = (is_object($data['appointmentDateCancelled'])
273             ? $data['appointmentDateCancelled']
274             : new \DateTime($data['appointmentDateCancelled']));
275
276         isset($data['appointmentCancelledComments'])
277         && $this->appointmentCancelledComments = $data['appointmentCancelledComments'];
278
279
280 //        if (isset($data['appointmentDate']))
281 //        {
282 //            $data['appointmentDate'] = explode(' ', $data['appointmentDate']);
283 //            $this->appointmentDate = new \DateTime($data['appointmentDate'][0]);
284 //        }
285 //
286 //
287 //        \Utility\Debug::errorLog('$data[appointmentDate]',$data['appointmentDate']);
288 //
289 //        \Utility\Debug::errorLog('$this->appointmentDate',$this->appointmentDate);
290 //
291 //        $this->updated = new \DateTime("now");
292 //
293 //        $this->appointmentDateCancelled = new \DateTime("now");
294
295         }
296
297     /**
298      * Convert the object to an array for synchronization.
299      * @return array
300      */
301     public function toSynchArray()
302     {
303         return array(
304             'id'                                        => $this->id,
305             'appointmentDate'               => $this->appointmentDate,
306             'appointmentCompleted'              => $this->appointmentCompleted,
307             'appointmentCancelled'              => $this->appointmentCancelled,
308             'appointmentDateCancelled'      => $this->appointmentDateCancelled,
309             'appointmentCancelledComments'      => $this->appointmentCancelledComments
310         );
311     }
312
313
314 }
315