Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
69.05% |
87 / 126 |
|
54.90% |
28 / 51 |
CRAP | |
0.00% |
0 / 1 |
Scope | |
69.05% |
87 / 126 |
|
54.90% |
28 / 51 |
336.56 | |
0.00% |
0 / 1 |
getDefaults | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getShortName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEmailFrom | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEmailRequired | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTelephoneActivated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTelephoneRequired | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCustomTextfieldActivated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCustomTextfieldRequired | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCustomTextfieldLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCustomTextfield2Activated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCustomTextfield2Required | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCustomTextfield2Label | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCaptchaActivatedRequired | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getInfoForAppointment | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getInfoForAllAppointments | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSlotsPerAppointment | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getProvider | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
5.93 | |||
getProviderId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDayoffList | |
28.57% |
2 / 7 |
|
0.00% |
0 / 1 |
24.86 | |||
getClosureList | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
56 | |||
getRequestList | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getNotificationPreferences | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getConfirmationContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getHeadsUpContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPreference | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContactEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getScopeInfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getScopeHint | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAlternateRedirectUrl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getAppointmentsPerMail | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getWhitelistedMails | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getReservationDuration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWaitingTimeFromQueueList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getCalculatedWorkstationCount | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
getBookableStartDate | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getBookableEndDate | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
updateStatusQueue | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
4 | |||
hasEmailFrom | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
hasNotificationEnabled | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
hasNotificationReminderEnabled | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
isEmailRequired | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
isTelephoneRequired | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
hasAccess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
withLessData | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
5 | |||
setStatusQueue | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setStatusAvailability | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
isNewerThan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__toString | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities; |
4 | |
5 | use BO\Zmsentities\Collection\ClosureList; |
6 | use BO\Zmsentities\Collection\DayoffList; |
7 | |
8 | /** |
9 | * @SuppressWarnings(Complexity) |
10 | */ |
11 | class Scope extends Schema\Entity implements Useraccount\AccessInterface |
12 | { |
13 | public const PRIMARY = 'id'; |
14 | |
15 | public static $schema = "scope.json"; |
16 | |
17 | public function getDefaults() |
18 | { |
19 | return [ |
20 | 'id' => 0, |
21 | 'source' => 'dldb', |
22 | 'contact' => new Contact(), |
23 | 'provider' => new Provider(), |
24 | 'shortName' => '', |
25 | 'dayoff' => new DayoffList() |
26 | ]; |
27 | } |
28 | |
29 | public function getSource() |
30 | { |
31 | return $this->toProperty()->source->get(); |
32 | } |
33 | |
34 | public function getShortName() |
35 | { |
36 | return $this->toProperty()->shortName->get(); |
37 | } |
38 | |
39 | public function getEmailFrom() |
40 | { |
41 | return $this->getPreference('client', 'emailFrom', null); |
42 | } |
43 | |
44 | public function getEmailRequired() |
45 | { |
46 | return $this->getPreference('client', 'emailRequired', null); |
47 | } |
48 | |
49 | public function getTelephoneActivated() |
50 | { |
51 | return $this->getPreference('client', 'telephoneActivated', null); |
52 | } |
53 | |
54 | public function getTelephoneRequired() |
55 | { |
56 | return $this->getPreference('client', 'telephoneRequired', null); |
57 | } |
58 | |
59 | public function getCustomTextfieldActivated() |
60 | { |
61 | return $this->getPreference('client', 'customTextfieldActivated', null); |
62 | } |
63 | |
64 | public function getCustomTextfieldRequired() |
65 | { |
66 | return $this->getPreference('client', 'customTextfieldRequired', null); |
67 | } |
68 | |
69 | public function getCustomTextfieldLabel() |
70 | { |
71 | return $this->getPreference('client', 'customTextfieldLabel', ''); |
72 | } |
73 | |
74 | public function getCustomTextfield2Activated() |
75 | { |
76 | return $this->getPreference('client', 'customTextfield2Activated', null); |
77 | } |
78 | |
79 | public function getCustomTextfield2Required() |
80 | { |
81 | return $this->getPreference('client', 'customTextfield2Required', null); |
82 | } |
83 | |
84 | public function getCustomTextfield2Label() |
85 | { |
86 | return $this->getPreference('client', 'customTextfield2Label', ''); |
87 | } |
88 | |
89 | public function getCaptchaActivatedRequired() |
90 | { |
91 | return $this->getPreference('client', 'captchaActivatedRequired', null); |
92 | } |
93 | |
94 | public function getInfoForAppointment() |
95 | { |
96 | return $this->getPreference('appointment', 'infoForAppointment', null); |
97 | } |
98 | |
99 | public function getInfoForAllAppointments() |
100 | { |
101 | return $this->getPreference('appointment', 'infoForAllAppointments', null); |
102 | } |
103 | |
104 | public function getSlotsPerAppointment() |
105 | { |
106 | return $this->getPreference('client', 'slotsPerAppointment', null); |
107 | } |
108 | |
109 | public function getProvider() |
110 | { |
111 | if (!isset($this->provider)) { |
112 | throw new Exception\ScopeMissingProvider("Provider is missing", 500); |
113 | } |
114 | if (!$this->provider instanceof Provider) { |
115 | $this->provider = new Provider($this->toProperty()->provider->get()); |
116 | } |
117 | if (!isset($this->provider['id']) || !$this->provider->id) { |
118 | $exception = new Exception\ScopeMissingProvider("No reference to a provider found for scope $this->id"); |
119 | $exception->data['scope'] = $this->getArrayCopy(); |
120 | throw $exception; |
121 | } |
122 | return $this->provider; |
123 | } |
124 | |
125 | public function getProviderId() |
126 | { |
127 | return $this->getProvider()->id; |
128 | } |
129 | |
130 | public function getDayoffList() |
131 | { |
132 | if (!isset($this->dayoff) || !$this->dayoff instanceof Collection\DayoffList) { |
133 | $this->dayoff = (!isset($this->dayoff) || !is_array($this->dayoff)) ? [] : $this->dayoff; |
134 | $this->dayoff = new Collection\DayoffList($this->dayoff); |
135 | foreach ($this->dayoff as $key => $dayoff) { |
136 | if (!$dayoff instanceof Dayoff) { |
137 | $this->dayoff[$key] = new Dayoff($dayoff); |
138 | } |
139 | } |
140 | } |
141 | return $this->dayoff; |
142 | } |
143 | |
144 | public function getClosureList() |
145 | { |
146 | if (!isset($this->closure) || !$this->closure instanceof Collection\ClosureList) { |
147 | $this->closure = (!isset($this->closure) || !is_array($this->closure)) ? [] : $this->closure; |
148 | $this->closure = new Collection\ClosureList($this->closure); |
149 | foreach ($this->closure as $key => $closure) { |
150 | if (!$closure instanceof Closure) { |
151 | $this->closure[$key] = new Closure($closure); |
152 | } |
153 | } |
154 | } |
155 | return $this->closure; |
156 | } |
157 | |
158 | public function getRequestList() |
159 | { |
160 | return $this->getProvider()->getRequestList(); |
161 | } |
162 | |
163 | public function getNotificationPreferences() |
164 | { |
165 | return $this->toProperty()->preferences->notifications->get(); |
166 | } |
167 | |
168 | public function getConfirmationContent() |
169 | { |
170 | return $this->toProperty()->preferences->notifications->confirmationContent->get(); |
171 | } |
172 | |
173 | public function getHeadsUpContent() |
174 | { |
175 | return $this->toProperty()->preferences->notifications->headsUpContent->get(); |
176 | } |
177 | |
178 | public function getPreference($preferenceKey, $index, $isBool = false, $default = null) |
179 | { |
180 | $preference = $this->toProperty()->preferences->$preferenceKey->$index->get($default); |
181 | return ($isBool) ? ($preference ? 1 : 0) : $preference; |
182 | } |
183 | |
184 | public function getStatus($statusKey, $index) |
185 | { |
186 | return $this->toProperty()->status->$statusKey->$index->get(); |
187 | } |
188 | |
189 | public function getContactEmail() |
190 | { |
191 | return $this->toProperty()->contact->email->get(); |
192 | } |
193 | |
194 | public function getName() |
195 | { |
196 | return $this->toProperty()->contact->name->get(); |
197 | } |
198 | |
199 | public function getScopeInfo() |
200 | { |
201 | return $this->toProperty()->preferences->ticketprinter->buttonName->get(); |
202 | } |
203 | |
204 | public function getScopeHint() |
205 | { |
206 | return $this->toProperty()->hint->get(); |
207 | } |
208 | |
209 | public function getAlternateRedirectUrl() |
210 | { |
211 | $alternateUrl = $this->toProperty()->preferences->client->alternateAppointmentUrl->get(); |
212 | |
213 | return ($alternateUrl) ? $alternateUrl : null; |
214 | } |
215 | |
216 | public function getAppointmentsPerMail() |
217 | { |
218 | $appointmentsPerMail = $this->toProperty()->preferences->client->appointmentsPerMail->get(); |
219 | |
220 | return ($appointmentsPerMail) ? $appointmentsPerMail : null; |
221 | } |
222 | |
223 | public function getWhitelistedMails() |
224 | { |
225 | $emails = $this->toProperty()->preferences->client->whitelistedMails->get(); |
226 | |
227 | return ($emails) ? $emails : ''; |
228 | } |
229 | |
230 | public function getReservationDuration() |
231 | { |
232 | return $this->toProperty()->preferences->appointment->reservationDuration->get(); |
233 | } |
234 | |
235 | public function getWaitingTimeFromQueueList(Collection\QueueList $queueList, \DateTimeInterface $dateTime) |
236 | { |
237 | return $queueList->getEstimatedWaitingTime( |
238 | $this->getPreference('queue', 'processingTimeAverage'), |
239 | $this->getCalculatedWorkstationCount(), |
240 | $dateTime |
241 | ); |
242 | } |
243 | |
244 | public function getCalculatedWorkstationCount() |
245 | { |
246 | $workstationCount = null; |
247 | if ($this->getStatus('queue', 'workstationCount') > 0) { |
248 | $workstationCount = $this->getStatus('queue', 'workstationCount'); |
249 | } elseif (! $workstationCount && $this->getStatus('queue', 'ghostWorkstationCount') > 0) { |
250 | $workstationCount = $this->getStatus('queue', 'ghostWorkstationCount'); |
251 | } |
252 | return $workstationCount; |
253 | } |
254 | |
255 | /** |
256 | * Get last bookable start date of a scope |
257 | * |
258 | * @return \DateTimeImmutable $scopeEndDate |
259 | */ |
260 | public function getBookableStartDate(\DateTimeInterface $now) |
261 | { |
262 | $now = Helper\DateTime::create($now); |
263 | $scopeStartDate = $this->toProperty()->preferences->appointment->startInDaysDefault->get(); |
264 | return ($scopeStartDate) ? $now->modify('+' . $scopeStartDate . 'days') : $now; |
265 | } |
266 | |
267 | /** |
268 | * Get last bookable end date of a scope |
269 | * |
270 | * @return \DateTimeImmutable $scopeEndDate |
271 | */ |
272 | public function getBookableEndDate(\DateTimeInterface $now) |
273 | { |
274 | $now = Helper\DateTime::create($now); |
275 | $scopeEndDate = $this->toProperty()->preferences->appointment->endInDaysDefault->get(); |
276 | return ($scopeEndDate) ? $now->modify('+' . $scopeEndDate . 'days') : $now; |
277 | } |
278 | |
279 | public function updateStatusQueue(\DateTimeInterface $dateTime) |
280 | { |
281 | $lastQueueUpdateDate = Helper\DateTime::create() |
282 | ->setTimestamp($this->getStatus('queue', 'lastGivenNumberTimestamp')); |
283 | if ($lastQueueUpdateDate->format('Y-m-d') == $dateTime->format('Y-m-d')) { |
284 | $this->setStatusQueue('lastGivenNumber', $this->getStatus('queue', 'lastGivenNumber') + 1); |
285 | $this->setStatusQueue('givenNumberCount', $this->getStatus('queue', 'givenNumberCount') + 1); |
286 | } else { |
287 | $this->setStatusQueue('lastGivenNumber', $this->getPreference('queue', 'firstNumber')); |
288 | $this->setStatusQueue('givenNumberCount', 1); |
289 | } |
290 | if ($this->getStatus('queue', 'lastGivenNumber') < $this->getPreference('queue', 'firstNumber')) { |
291 | $this->setStatusQueue('lastGivenNumber', $this->getPreference('queue', 'firstNumber')); |
292 | } elseif ($this->getStatus('queue', 'lastGivenNumber') > $this->getPreference('queue', 'lastNumber')) { |
293 | $this->setStatusQueue('lastGivenNumber', $this->getPreference('queue', 'firstNumber')); |
294 | } |
295 | $this->setStatusQueue('lastGivenNumberTimestamp', $dateTime->getTimestamp()); |
296 | return $this; |
297 | } |
298 | |
299 | public function hasEmailFrom() |
300 | { |
301 | $emailFrom = $this->getPreference('client', 'emailFrom'); |
302 | return ($emailFrom) ? true : false; |
303 | } |
304 | |
305 | public function hasNotificationEnabled() |
306 | { |
307 | $notificationEnabled = $this->getPreference('appointment', 'notificationConfirmationEnabled'); |
308 | return ($notificationEnabled) ? true : false; |
309 | } |
310 | |
311 | public function hasNotificationReminderEnabled() |
312 | { |
313 | $hasReminderEnabled = $this->getPreference('appointment', 'notificationHeadsUpEnabled'); |
314 | return ($hasReminderEnabled) ? true : false; |
315 | } |
316 | |
317 | public function isEmailRequired() |
318 | { |
319 | $emailFrom = $this->getPreference('client', 'emailFrom'); |
320 | $emailRequired = $this->getPreference('client', 'emailRequired'); |
321 | return ($emailFrom && $emailRequired) ? true : false; |
322 | } |
323 | |
324 | public function isTelephoneRequired() |
325 | { |
326 | $telephoneRequired = $this->getPreference('client', 'telephoneRequired'); |
327 | return $telephoneRequired ? true : false; |
328 | } |
329 | |
330 | public function hasAccess(Useraccount $useraccount) |
331 | { |
332 | return $useraccount->hasRights(['superuser']) || $useraccount->hasScope($this->id); |
333 | } |
334 | |
335 | /** |
336 | * Reduce data of dereferenced entities to a required minimum |
337 | * |
338 | */ |
339 | public function withLessData(array $keepArray = []) |
340 | { |
341 | $entity = clone $this; |
342 | if (! in_array('dayoff', $keepArray) && $entity->toProperty()->dayoff->isAvailable()) { |
343 | unset($entity['dayoff']); |
344 | } |
345 | if (! in_array('status', $keepArray)) { |
346 | unset($entity['status']); |
347 | } |
348 | if (! in_array('preferences', $keepArray)) { |
349 | unset($entity['preferences']); |
350 | } |
351 | |
352 | return $entity; |
353 | } |
354 | |
355 | public function setStatusQueue($key, $value) |
356 | { |
357 | $this->status['queue'][$key] = $value; |
358 | return $this; |
359 | } |
360 | |
361 | public function setStatusAvailability($key, $value) |
362 | { |
363 | $this->status['availability'][$key] = $value; |
364 | return $this; |
365 | } |
366 | |
367 | /** |
368 | * Check if scope is newer than given time |
369 | * |
370 | * @return bool |
371 | */ |
372 | public function isNewerThan(\DateTimeInterface $dateTime) |
373 | { |
374 | return ($dateTime->getTimestamp() < $this->lastChange); |
375 | } |
376 | |
377 | public function __toString() |
378 | { |
379 | $string = 'scope#'; |
380 | $string .= $this['id']; |
381 | $string .= ' '; |
382 | $string .= $this->getName(); |
383 | return $string; |
384 | } |
385 | } |