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