Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
63.91% covered (warning)
63.91%
85 / 133
50.94% covered (warning)
50.94%
27 / 53
CRAP
0.00% covered (danger)
0.00%
0 / 1
Scope
63.91% covered (warning)
63.91%
85 / 133
50.94% covered (warning)
50.94%
27 / 53
519.24
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
 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
 getSlotsPerAppointment
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
106    public function getProvider()
107    {
108        if (!isset($this->provider)) {
109            throw new Exception\ScopeMissingProvider("Provider is missing", 500);
110        }
111        if (!$this->provider instanceof Provider) {
112            $this->provider = new Provider($this->toProperty()->provider->get());
113        }
114        if (!isset($this->provider['id']) || !$this->provider->id) {
115            $exception = new Exception\ScopeMissingProvider("No reference to a provider found for scope $this->id");
116            $exception->data['scope'] = $this->getArrayCopy();
117            throw $exception;
118        }
119        return $this->provider;
120    }
121
122    public function getProviderId()
123    {
124        return $this->getProvider()->id;
125    }
126
127    public function getDayoffList()
128    {
129        if (!isset($this->dayoff) || !$this->dayoff instanceof Collection\DayoffList) {
130            $this->dayoff = (!isset($this->dayoff) || !is_array($this->dayoff)) ? [] : $this->dayoff;
131            $this->dayoff = new Collection\DayoffList($this->dayoff);
132            foreach ($this->dayoff as $key => $dayoff) {
133                if (!$dayoff instanceof Dayoff) {
134                    $this->dayoff[$key] = new Dayoff($dayoff);
135                }
136            }
137        }
138        return $this->dayoff;
139    }
140
141    public function getClosureList()
142    {
143        if (!isset($this->closure) || !$this->closure instanceof Collection\ClosureList) {
144            $this->closure = (!isset($this->closure) || !is_array($this->closure)) ? [] : $this->closure;
145            $this->closure = new Collection\ClosureList($this->closure);
146            foreach ($this->closure as $key => $closure) {
147                if (!$closure instanceof Closure) {
148                    $this->closure[$key] = new Closure($closure);
149                }
150            }
151        }
152        return $this->closure;
153    }
154
155    public function getRequestList()
156    {
157        return $this->getProvider()->getRequestList();
158    }
159
160    public function getNotificationPreferences()
161    {
162        return $this->toProperty()->preferences->notifications->get();
163    }
164
165    public function getConfirmationContent()
166    {
167        return $this->toProperty()->preferences->notifications->confirmationContent->get();
168    }
169
170    public function getHeadsUpContent()
171    {
172        return $this->toProperty()->preferences->notifications->headsUpContent->get();
173    }
174
175    public function getPreference($preferenceKey, $index, $isBool = false, $default = null)
176    {
177        $preference = $this->toProperty()->preferences->$preferenceKey->$index->get($default);
178        return ($isBool) ? ($preference ? 1 : 0) : $preference;
179    }
180
181    public function getStatus($statusKey, $index)
182    {
183        return $this->toProperty()->status->$statusKey->$index->get();
184    }
185
186    public function getContactEmail()
187    {
188        return $this->toProperty()->contact->email->get();
189    }
190
191    public function getName()
192    {
193        return $this->toProperty()->contact->name->get();
194    }
195
196    public function getScopeInfo()
197    {
198        return $this->toProperty()->preferences->ticketprinter->buttonName->get();
199    }
200
201    public function getScopeHint()
202    {
203        return $this->toProperty()->hint->get();
204    }
205
206    public function getDisplayNumberPrefix()
207    {
208        return $this->toProperty()->preferences->queue->displayNumberPrefix->get();
209    }
210
211    public function getAlternateRedirectUrl()
212    {
213        $alternateUrl = $this->toProperty()->preferences->client->alternateAppointmentUrl->get();
214
215        return ($alternateUrl) ? $alternateUrl : null;
216    }
217
218    public function getAppointmentsPerMail()
219    {
220        $appointmentsPerMail = $this->toProperty()->preferences->client->appointmentsPerMail->get();
221
222        return ($appointmentsPerMail) ? $appointmentsPerMail : null;
223    }
224
225    public function getSlotsPerAppointment()
226    {
227        $slotsPerAppointment = $this->toProperty()->preferences->client->slotsPerAppointment->get();
228
229        return ($slotsPerAppointment) ? $slotsPerAppointment : null;
230    }
231
232    public function getWhitelistedMails()
233    {
234        $emails = $this->toProperty()->preferences->client->whitelistedMails->get();
235
236        return ($emails) ? $emails : '';
237    }
238
239    public function getReservationDuration()
240    {
241        return $this->toProperty()->preferences->appointment->reservationDuration->get();
242    }
243
244    public function getWaitingTimeFromQueueList(Collection\QueueList $queueList, \DateTimeInterface $dateTime)
245    {
246        return $queueList->getEstimatedWaitingTime(
247            $this->getPreference('queue', 'processingTimeAverage'),
248            $this->getCalculatedWorkstationCount(),
249            $dateTime
250        );
251    }
252
253    public function getCalculatedWorkstationCount()
254    {
255        $workstationCount = null;
256        if ($this->getStatus('queue', 'workstationCount') > 0) {
257            $workstationCount = $this->getStatus('queue', 'workstationCount');
258        } elseif (! $workstationCount && $this->getStatus('queue', 'ghostWorkstationCount') > 0) {
259            $workstationCount = $this->getStatus('queue', 'ghostWorkstationCount');
260        }
261        return $workstationCount;
262    }
263
264    /**
265    * Get last bookable start date of a scope
266    *
267    * @return \DateTimeImmutable $scopeEndDate
268    */
269    public function getBookableStartDate(\DateTimeInterface $now)
270    {
271        $now = Helper\DateTime::create($now);
272        $scopeStartDate = $this->toProperty()->preferences->appointment->startInDaysDefault->get();
273        return ($scopeStartDate) ? $now->modify('+' . $scopeStartDate . 'days') : $now;
274    }
275
276    /**
277    * Get last bookable end date of a scope
278    *
279    * @return \DateTimeImmutable $scopeEndDate
280    */
281    public function getBookableEndDate(\DateTimeInterface $now)
282    {
283        $now = Helper\DateTime::create($now);
284        $scopeEndDate = $this->toProperty()->preferences->appointment->endInDaysDefault->get();
285        return ($scopeEndDate) ? $now->modify('+' . $scopeEndDate . 'days') : $now;
286    }
287
288    public function updateStatusQueue(\DateTimeInterface $dateTime)
289    {
290        $lastQueueUpdateDate = Helper\DateTime::create()
291            ->setTimestamp($this->getStatus('queue', 'lastGivenNumberTimestamp'));
292        if ($lastQueueUpdateDate->format('Y-m-d') == $dateTime->format('Y-m-d')) {
293            $this->setStatusQueue('lastGivenNumber', $this->getStatus('queue', 'lastGivenNumber') + 1);
294            $this->setStatusQueue('givenNumberCount', $this->getStatus('queue', 'givenNumberCount') + 1);
295        } else {
296            $this->setStatusQueue('lastGivenNumber', $this->getPreference('queue', 'firstNumber'));
297            $this->setStatusQueue('givenNumberCount', 1);
298        }
299        if ($this->getStatus('queue', 'lastGivenNumber') < $this->getPreference('queue', 'firstNumber')) {
300            $this->setStatusQueue('lastGivenNumber', $this->getPreference('queue', 'firstNumber'));
301        } elseif ($this->getStatus('queue', 'lastGivenNumber') > $this->getPreference('queue', 'lastNumber')) {
302            $this->setStatusQueue('lastGivenNumber', $this->getPreference('queue', 'firstNumber'));
303        }
304        $this->setStatusQueue('lastGivenNumberTimestamp', $dateTime->getTimestamp());
305        return $this;
306    }
307
308    public function incrementDisplayNumber()
309    {
310        if ($this->getStatus('queue', 'lastDisplayNumber') >= $this->getStatus('queue', 'maxDisplayNumber')) {
311            $this->setStatusQueue('lastDisplayNumber', 1);
312            return $this;
313        }
314
315        $this->setStatusQueue('lastDisplayNumber', $this->getStatus('queue', 'lastDisplayNumber') + 1);
316        return $this;
317    }
318
319    public function hasEmailFrom()
320    {
321        $emailFrom = $this->getPreference('client', 'emailFrom');
322        return ($emailFrom) ? true : false;
323    }
324
325    public function hasNotificationEnabled()
326    {
327        $notificationEnabled = $this->getPreference('appointment', 'notificationConfirmationEnabled');
328        return ($notificationEnabled) ? true : false;
329    }
330
331    public function hasNotificationReminderEnabled()
332    {
333        $hasReminderEnabled = $this->getPreference('appointment', 'notificationHeadsUpEnabled');
334        return ($hasReminderEnabled) ? true : false;
335    }
336
337    public function isEmailRequired()
338    {
339        $emailFrom = $this->getPreference('client', 'emailFrom');
340        $emailRequired = $this->getPreference('client', 'emailRequired');
341        return ($emailFrom && $emailRequired) ? true : false;
342    }
343
344    public function isTelephoneRequired()
345    {
346        $telephoneRequired = $this->getPreference('client', 'telephoneRequired');
347        return $telephoneRequired ? true : false;
348    }
349
350    public function hasAccess(Useraccount $useraccount)
351    {
352        return $useraccount->hasRights(['superuser']) ||  $useraccount->hasScope($this->id);
353    }
354
355    /**
356     * Reduce data of dereferenced entities to a required minimum
357     *
358     */
359    public function withLessData(array $keepArray = [])
360    {
361        $entity = clone $this;
362        if (! in_array('dayoff', $keepArray) && $entity->toProperty()->dayoff->isAvailable()) {
363            unset($entity['dayoff']);
364        }
365        if (! in_array('status', $keepArray)) {
366            unset($entity['status']);
367        }
368        if (! in_array('preferences', $keepArray)) {
369            unset($entity['preferences']);
370        }
371
372        return $entity;
373    }
374
375    public function setStatusQueue($key, $value)
376    {
377        $this->status['queue'][$key] = $value;
378        return $this;
379    }
380
381    public function setStatusAvailability($key, $value)
382    {
383        $this->status['availability'][$key] = $value;
384        return $this;
385    }
386
387    /**
388     * Check if scope is newer than given time
389     *
390     * @return bool
391     */
392    public function isNewerThan(\DateTimeInterface $dateTime)
393    {
394        return ($dateTime->getTimestamp() < $this->lastChange);
395    }
396
397    public function __toString()
398    {
399        $string = 'scope#';
400        $string .= $this['id'];
401        $string .= ' ';
402        $string .= $this->getName();
403        return $string;
404    }
405}