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