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