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