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