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