2 namespace Valuation\Entity;
4 use Doctrine\ORM\Mapping as ORM;
5 use Zend\XmlRpc\Value\DateTime;
12 * @ORM\HasLifecycleCallbacks
13 * @ORM\Table(name="valuation_appointments")
15 class ValuationAppointments
19 * Can archive records.
23 * Pull Synchronization Strategy for this table.
25 const PULL_SYNCH_STRATEGY = 'Build';
27 * Push Synchronization Strategy for this table.
29 const PUSH_SYNCH_STRATEGY = 'Update';
31 * Post insert action must be called after new entity is flushed to database.
33 const HAVE_POST_INSERT = true;
35 * Handle as a job queue for mobile devices.
37 const JOB_QUEUE = true;
39 /* ------------------------------------ Identification ------------------------------------ */
42 * @ORM\Column(type="integer");
43 * @ORM\GeneratedValue(strategy="AUTO")
48 * @ORM\ManyToOne(targetEntity="\Valuation\Entity\ValuationTimeSlots", cascade={"all"})
49 * @ORM\JoinColumn(nullable=false, name="time_slot_id")
54 * @ORM\ManyToOne(targetEntity="\User\Entity\Profile", cascade={"all"})
55 * @ORM\JoinColumn(nullable=false, name="valuator_profile_id")
60 * @ORM\ManyToOne(targetEntity="\Valuation\Entity\Valuation", cascade={"all"})
61 * @ORM\JoinColumn(nullable=false, name="valuation_id")
67 * @ORM\Column(type="datetime", nullable=false, name="appointment_date");
69 protected $appointmentDate;
72 * @ORM\Column(type="boolean", name="appointment_completed");
74 protected $appointmentCompleted = false;
78 * @ORM\Column(type="boolean", name="appointment_cancelled");
80 protected $appointmentCancelled = false;
82 * @ORM\Column(type="datetime", name="appointment_date_cancelled", nullable=true);
84 protected $appointmentDateCancelled;
86 * @ORM\Column(type="text", name="appointment_cancelled_comments", nullable=true);
88 protected $appointmentCancelledComments;
94 * @ORM\Column(type="datetime");
99 * @ORM\Column(type="datetime", nullable=true);
104 * @ORM\Column(type="boolean");
106 protected $archived = false;
110 * Magic getter to expose protected properties.
112 * @param string $property
115 public function __get($property)
117 return $this->$property;
121 * Magic setter to save protected properties.
123 * @param string $property
124 * @param mixed $value
126 public function __set($property, $value)
128 $this->$property = $value;
134 public function setCreateTime()
136 $this->created = new \DateTime("now");
142 public function setUpdateTime()
144 $this->updated = new \DateTime("now");
146 if($this->appointmentCancelled)
148 $this->appointmentDateCancelled = new \DateTime("now");
155 * Convert the object to an array.
156 * @param array $expand
157 * @param array $intersect
158 * @param boolean $showIdentifiers
159 * @param integer $expandAll
162 public function toArray(
163 array $expand = array(), array $intersect = array(),
164 $showIdentifiers = false, $expandAll = 0
167 $intersect = array_flip($intersect);
168 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
169 $includeAll = empty($intersect);
171 ($includeAll || isset($intersect['id']))
172 && $data['id'] = $this->id;
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)
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)
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)
200 ($includeAll || isset($intersect['appointmentDate']))
201 && $data['appointmentDate'] = !is_null($this->appointmentDate)
202 ? $this->appointmentDate->format($dateTimeFormat)
205 ($includeAll || isset($intersect['created']))
206 && $data['created'] = !is_null($this->created)
207 ? $this->created->format($dateTimeFormat)
209 ($includeAll || isset($intersect['updated']))
210 && $data['updated'] = !is_null($this->updated)
211 ? $this->updated->format($dateTimeFormat)
213 ($includeAll || isset($intersect['archived']))
214 && $data['archived'] = $this->archived;
216 ($includeAll || isset($intersect['appointmentCompleted']))
217 && $data['appointmentCompleted'] = $this->appointmentCompleted;
218 ($includeAll || isset($intersect['appointmentCancelled']))
219 && $data['appointmentCancelled'] = $this->appointmentCancelled;
221 ($includeAll || isset($intersect['appointmentDateCancelled']))
222 && $data['appointmentDateCancelled'] = !is_null($this->appointmentDateCancelled)
223 ? $this->appointmentDateCancelled->format($dateTimeFormat)
226 ($includeAll || isset($intersect['appointmentCancelledComments']))
227 && $data['appointmentCancelledComments'] = $this->appointmentCancelledComments;
235 * Populate from an array.
238 public function fromArray($data = array())
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']);
251 // \Utility\Debug::errorLog('$data',$data);
254 && $this->id = $data['id'];
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'];
271 isset($data['appointmentDateCancelled'])
272 && $this->appointmentDateCancelled = (is_object($data['appointmentDateCancelled'])
273 ? $data['appointmentDateCancelled']
274 : new \DateTime($data['appointmentDateCancelled']));
276 isset($data['appointmentCancelledComments'])
277 && $this->appointmentCancelledComments = $data['appointmentCancelledComments'];
280 // if (isset($data['appointmentDate']))
282 // $data['appointmentDate'] = explode(' ', $data['appointmentDate']);
283 // $this->appointmentDate = new \DateTime($data['appointmentDate'][0]);
287 // \Utility\Debug::errorLog('$data[appointmentDate]',$data['appointmentDate']);
289 // \Utility\Debug::errorLog('$this->appointmentDate',$this->appointmentDate);
291 // $this->updated = new \DateTime("now");
293 // $this->appointmentDateCancelled = new \DateTime("now");
298 * Convert the object to an array for synchronization.
301 public function toSynchArray()
305 'appointmentDate' => $this->appointmentDate,
306 'appointmentCompleted' => $this->appointmentCompleted,
307 'appointmentCancelled' => $this->appointmentCancelled,
308 'appointmentDateCancelled' => $this->appointmentDateCancelled,
309 'appointmentCancelledComments' => $this->appointmentCancelledComments