Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
68.64% |
151 / 220 |
|
60.61% |
20 / 33 |
CRAP | |
0.00% |
0 / 1 |
| ProcessList | |
68.64% |
151 / 220 |
|
60.61% |
20 / 33 |
380.33 | |
0.00% |
0 / 1 |
| toProcessListByTime | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| withRequest | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| sortByScopeName | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| sortByAppointmentDate | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| sortByArrivalTime | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| sortByEstimatedWaitingTime | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| sortByClientName | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| sortPickupQueue | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| sortByTimeKey | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| toProcessListByStatusList | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| toConflictListByDay | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
5 | |||
| getScopeList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getRequestList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getAppointmentList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| setTempAppointmentToProcess | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
5 | |||
| toQueueList | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| withAvailability | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| withAvailabilityStrict | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| withDepartmentNotificationEnabled | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| withDepartmentHasMailFrom | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| setConflictAmendment | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| withOutAvailability | |
76.92% |
10 / 13 |
|
0.00% |
0 / 1 |
5.31 | |||
| withUniqueScope | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
4 | |||
| withAccess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| withScopeId | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| withOutScopeId | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| withOutProcessId | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| withoutExpiredAppointmentDate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| withinExactDate | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| withoutDublicatedConflicts | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| testProcessListLength | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| withoutProcessByStatus | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| withTimeRangeByAppointment | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities\Collection; |
| 4 | |
| 5 | use BO\Zmsentities\Helper\Sorter; |
| 6 | use BO\Zmsentities\Helper\Property; |
| 7 | use BO\Zmsentities\Helper\Messaging; |
| 8 | use BO\Zmsentities\Process; |
| 9 | |
| 10 | /** |
| 11 | * @SuppressWarnings(Complexity) |
| 12 | * @SuppressWarnings(Public) |
| 13 | * @SuppressWarnings(Coupling) |
| 14 | * |
| 15 | */ |
| 16 | class ProcessList extends Base |
| 17 | { |
| 18 | public const ENTITY_CLASS = '\BO\Zmsentities\Process'; |
| 19 | |
| 20 | public function toProcessListByTime($format = null) |
| 21 | { |
| 22 | $list = new self(); |
| 23 | foreach ($this as $process) { |
| 24 | $appointment = $process->getFirstAppointment(); |
| 25 | $formattedDate = $appointment['date']; |
| 26 | if ($format) { |
| 27 | $formattedDate = $appointment->toDateTime()->format($format); |
| 28 | } |
| 29 | $list[$formattedDate][] = clone $process; |
| 30 | } |
| 31 | return $list; |
| 32 | } |
| 33 | |
| 34 | public function withRequest($requestId) |
| 35 | { |
| 36 | $list = new self(); |
| 37 | foreach ($this as $process) { |
| 38 | if ($process->requests->hasEntity($requestId)) { |
| 39 | $list->addEntity(clone $process); |
| 40 | } |
| 41 | } |
| 42 | return $list; |
| 43 | } |
| 44 | |
| 45 | public function sortByScopeName() |
| 46 | { |
| 47 | $this->uasort(function ($a, $b) { |
| 48 | return strcmp( |
| 49 | Sorter::toSortableString(ucfirst($a->scope->contact['name'] ?? '')), |
| 50 | Sorter::toSortableString(ucfirst($b->scope->contact['name'] ?? '')) |
| 51 | ); |
| 52 | }); |
| 53 | return $this; |
| 54 | } |
| 55 | |
| 56 | public function sortByAppointmentDate() |
| 57 | { |
| 58 | $this->uasort(function ($a, $b) { |
| 59 | return ($a->getFirstAppointment()->date - $b->getFirstAppointment()->date); |
| 60 | }); |
| 61 | return $this; |
| 62 | } |
| 63 | |
| 64 | public function sortByArrivalTime() |
| 65 | { |
| 66 | $this->uasort(function ($a, $b) { |
| 67 | return ($a->queue['arrivalTime'] - $b->queue['arrivalTime']); |
| 68 | }); |
| 69 | return $this; |
| 70 | } |
| 71 | |
| 72 | public function sortByEstimatedWaitingTime() |
| 73 | { |
| 74 | $this->uasort(function ($a, $b) { |
| 75 | return ($a->queue['waitingTimeEstimate'] - $b->queue['waitingTimeEstimate']); |
| 76 | }); |
| 77 | return $this; |
| 78 | } |
| 79 | |
| 80 | public function sortByClientName() |
| 81 | { |
| 82 | $this->uasort(function ($a, $b) { |
| 83 | return strcmp( |
| 84 | Sorter::toSortableString($a->getFirstClient()['familyName']), |
| 85 | Sorter::toSortableString($b->getFirstClient()['familyName']) |
| 86 | ); |
| 87 | }); |
| 88 | return $this; |
| 89 | } |
| 90 | |
| 91 | public function sortPickupQueue() |
| 92 | { |
| 93 | $this->uasort(function ($a, $b) { |
| 94 | if ($a->queue['arrivalTime'] == $b->queue['arrivalTime']) { |
| 95 | //error_log('equal arrival Time for :'. $a->id); |
| 96 | return strcmp( |
| 97 | Sorter::toSortableString($a->getFirstClient()['familyName']), |
| 98 | Sorter::toSortableString($b->getFirstClient()['familyName']) |
| 99 | ); |
| 100 | } |
| 101 | return ($a->queue['arrivalTime'] - $b->queue['arrivalTime']); |
| 102 | }); |
| 103 | return $this; |
| 104 | } |
| 105 | |
| 106 | public function sortByTimeKey() |
| 107 | { |
| 108 | $this->uksort(function ($a, $b) { |
| 109 | return ($a - $b); |
| 110 | }); |
| 111 | return $this; |
| 112 | } |
| 113 | |
| 114 | public function toProcessListByStatusList(array $statusList) |
| 115 | { |
| 116 | $collection = new self(); |
| 117 | foreach ($this as $process) { |
| 118 | if (in_array($process->getStatus(), $statusList)) { |
| 119 | $collection->addEntity($process); |
| 120 | } |
| 121 | } |
| 122 | return $collection; |
| 123 | } |
| 124 | |
| 125 | public function toConflictListByDay() |
| 126 | { |
| 127 | $list = []; |
| 128 | $oldList = clone $this; |
| 129 | foreach ($oldList as $process) { |
| 130 | $appointmentList = []; |
| 131 | if (!isset($list[$process->getFirstAppointment()->getStartTime()->format('Y-m-d')])) { |
| 132 | $list[$process->getFirstAppointment()->getStartTime()->format('Y-m-d')] = []; |
| 133 | } |
| 134 | foreach ($process->getAppointments() as $appointment) { |
| 135 | $availabilityId = ($appointment->getAvailability()->getId()) ? |
| 136 | $appointment->getAvailability()->getId() : |
| 137 | $appointment->getAvailability()->tempId; |
| 138 | $appointmentList[] = [ |
| 139 | 'startTime' => $appointment->getStartTime()->format('H:i'), |
| 140 | 'endTime' => $appointment->getEndTime()->format('H:i'), |
| 141 | 'availability' => $availabilityId |
| 142 | ]; |
| 143 | } |
| 144 | $list[$process->getFirstAppointment()->getStartTime()->format('Y-m-d')][] = [ |
| 145 | 'message' => $process->amendment, |
| 146 | 'appointments' => $appointmentList |
| 147 | ]; |
| 148 | } |
| 149 | return $list; |
| 150 | } |
| 151 | |
| 152 | public function getScopeList() |
| 153 | { |
| 154 | $list = new ScopeList(); |
| 155 | foreach ($this as $process) { |
| 156 | if (Property::__keyExists('scope', $process)) { |
| 157 | $list[] = new \BO\Zmsentities\Scope($process['scope']); |
| 158 | } |
| 159 | } |
| 160 | return $list->withUniqueScopes(); |
| 161 | } |
| 162 | |
| 163 | public function getRequestList() |
| 164 | { |
| 165 | $list = new RequestList(); |
| 166 | foreach ($this as $process) { |
| 167 | if (Property::__keyExists('requests', $process)) { |
| 168 | $list->addList($process->getRequests()); |
| 169 | } |
| 170 | } |
| 171 | return $list->withUniqueRequests(); |
| 172 | } |
| 173 | |
| 174 | public function getAppointmentList() |
| 175 | { |
| 176 | $appointmentList = new AppointmentList(); |
| 177 | foreach ($this as $process) { |
| 178 | if (Property::__keyExists('appointments', $process)) { |
| 179 | foreach ($process["appointments"] as $appointment) { |
| 180 | $appointmentList->addEntity(new \BO\Zmsentities\Appointment($appointment)); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | return $appointmentList; |
| 185 | } |
| 186 | |
| 187 | public function setTempAppointmentToProcess($dateTime, $scopeId) |
| 188 | { |
| 189 | $addedAppointment = false; |
| 190 | $appointment = (new \BO\Zmsentities\Appointment())->addDate($dateTime->getTimestamp())->addScope($scopeId); |
| 191 | foreach ($this as $process) { |
| 192 | if ($process->hasAppointment($dateTime->getTimestamp(), $scopeId) && !$addedAppointment) { |
| 193 | $entity = clone $process; |
| 194 | $this->addEntity($entity); |
| 195 | $addedAppointment = true; |
| 196 | } |
| 197 | } |
| 198 | if (!$addedAppointment) { |
| 199 | $entity = new \BO\Zmsentities\Process(); |
| 200 | $entity->addAppointment($appointment); |
| 201 | $this->addEntity($entity); |
| 202 | } |
| 203 | return $this; |
| 204 | } |
| 205 | |
| 206 | public function toQueueList($now) |
| 207 | { |
| 208 | $queueList = new QueueList(); |
| 209 | foreach ($this as $process) { |
| 210 | $queue = $process->toQueue($now); |
| 211 | $queueList->addEntity($queue); |
| 212 | } |
| 213 | $queueList->setTransferedProcessList(true); |
| 214 | return $queueList; |
| 215 | } |
| 216 | |
| 217 | public function withAvailability(\BO\Zmsentities\Availability $availability) |
| 218 | { |
| 219 | $processList = new static(); |
| 220 | foreach ($this as $process) { |
| 221 | if ($availability->hasAppointment($process->getFirstAppointment())) { |
| 222 | $processList[] = clone $process; |
| 223 | } |
| 224 | } |
| 225 | return $processList; |
| 226 | } |
| 227 | |
| 228 | public function withAvailabilityStrict(\BO\Zmsentities\Availability $availability) |
| 229 | { |
| 230 | $processList = new static(); |
| 231 | $slotList = $availability->getSlotList(); |
| 232 | foreach ($this as $process) { |
| 233 | if ($slotList->removeAppointment($process->getFirstAppointment())) { |
| 234 | $processList[] = clone $process; |
| 235 | } |
| 236 | } |
| 237 | return $processList; |
| 238 | } |
| 239 | |
| 240 | public function withDepartmentNotificationEnabled() |
| 241 | { |
| 242 | $processList = new static(); |
| 243 | foreach ($this as $process) { |
| 244 | if ($process->scope->hasNotificationReminderEnabled()) { |
| 245 | $entity = clone $process; |
| 246 | $processList->addEntity($entity); |
| 247 | } |
| 248 | } |
| 249 | return $processList; |
| 250 | } |
| 251 | |
| 252 | public function withDepartmentHasMailFrom() |
| 253 | { |
| 254 | $processList = new static(); |
| 255 | foreach ($this as $process) { |
| 256 | if ($process->scope->hasEmailFrom()) { |
| 257 | $entity = clone $process; |
| 258 | $processList->addEntity($entity); |
| 259 | } |
| 260 | } |
| 261 | return $processList; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | |
| 266 | public function setConflictAmendment() |
| 267 | { |
| 268 | foreach ($this as $process) { |
| 269 | $process->amendment = 'Die Slots für diesen Zeitraum wurden überbucht'; |
| 270 | if (! $process->getFirstAppointment()->availability->hasId()) { |
| 271 | $process->amendment = sprintf( |
| 272 | 'Der Vorgang (%s) befindet sich außerhalb der Öffnungszeit!', |
| 273 | $process->getId() |
| 274 | ); |
| 275 | } |
| 276 | } |
| 277 | return $this; |
| 278 | } |
| 279 | |
| 280 | public function withOutAvailability(\BO\Zmsentities\Collection\AvailabilityList $availabilityList) |
| 281 | { |
| 282 | $processList = new static(); |
| 283 | foreach ($this->toProcessListByTime('Y-m-d') as $processListByDate) { |
| 284 | $dateTime = $processListByDate[0]->getFirstAppointment()->toDateTime(); |
| 285 | $slotList = $availabilityList->withType('appointment')->withDateTime($dateTime)->getSlotList(); |
| 286 | foreach ($processListByDate as $process) { |
| 287 | try { |
| 288 | $slotList->withSlotsForAppointment($process->getFirstAppointment()); |
| 289 | if (!$slotList->removeAppointment($process->getFirstAppointment())) { |
| 290 | $process->amendment = ""; |
| 291 | $processList[] = clone $process; |
| 292 | } |
| 293 | } catch (\BO\Zmsentities\Exception\AppointmentNotFitInSlotList $exception) { |
| 294 | $process->amendment = ""; |
| 295 | $processList[] = clone $process; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | return $processList; |
| 300 | } |
| 301 | |
| 302 | public function withUniqueScope($oncePerHour = false) |
| 303 | { |
| 304 | $processList = new static(); |
| 305 | $scopeKeyList = []; |
| 306 | foreach ($this as $process) { |
| 307 | $scopeKey = $process->scope->id . '-'; |
| 308 | if ($oncePerHour) { |
| 309 | $scopeKey .= $process->getFirstAppointment()->toDateTime()->format('H'); |
| 310 | } else { |
| 311 | $scopeKey .= $process->getFirstAppointment()->toDateTime()->format('H:i'); |
| 312 | } |
| 313 | if (!in_array($scopeKey, $scopeKeyList)) { |
| 314 | $processList[] = clone $process; |
| 315 | $scopeKeyList[] = $scopeKey; |
| 316 | } |
| 317 | } |
| 318 | return $processList; |
| 319 | } |
| 320 | |
| 321 | public function withAccess(\BO\Zmsentities\Useraccount $useraccount) |
| 322 | { |
| 323 | $list = new static(); |
| 324 | foreach ($this as $process) { |
| 325 | $process = clone $process; |
| 326 | if ($process->getCurrentScope()->hasAccess($useraccount)) { |
| 327 | $list[] = $process; |
| 328 | } |
| 329 | } |
| 330 | return $list; |
| 331 | } |
| 332 | |
| 333 | public function withScopeId($scopeId) |
| 334 | { |
| 335 | $processList = new static(); |
| 336 | foreach ($this as $process) { |
| 337 | if ($scopeId == $process->scope['id']) { |
| 338 | $processList[] = clone $process; |
| 339 | } |
| 340 | } |
| 341 | return $processList; |
| 342 | } |
| 343 | |
| 344 | public function withOutScopeId($scopeId) |
| 345 | { |
| 346 | $processList = new static(); |
| 347 | foreach ($this as $process) { |
| 348 | if ($scopeId != $process->scope['id']) { |
| 349 | $processList[] = clone $process; |
| 350 | } |
| 351 | } |
| 352 | return $processList; |
| 353 | } |
| 354 | |
| 355 | public function withOutProcessId($processId) |
| 356 | { |
| 357 | $processList = new static(); |
| 358 | foreach ($this as $process) { |
| 359 | if ($processId != $process->getId()) { |
| 360 | $processList[] = clone $process; |
| 361 | } |
| 362 | } |
| 363 | return $processList; |
| 364 | } |
| 365 | |
| 366 | public function withoutExpiredAppointmentDate(\DateTimeInterface $now) |
| 367 | { |
| 368 | $conflictList = new self(); |
| 369 | foreach ($this as $process) { |
| 370 | if ($process->getFirstAppointment()->date > $now->getTimestamp()) { |
| 371 | $conflictList->addEntity(clone $process); |
| 372 | } |
| 373 | } |
| 374 | return $conflictList; |
| 375 | } |
| 376 | |
| 377 | public function withinExactDate(\DateTimeInterface $now) |
| 378 | { |
| 379 | $processList = new self(); |
| 380 | foreach ($this as $process) { |
| 381 | if ($process->getFirstAppointment()->toDateTime()->format('Y-m-d') == $now->format('Y-m-d')) { |
| 382 | $processList->addEntity(clone $process); |
| 383 | } |
| 384 | } |
| 385 | return $processList; |
| 386 | } |
| 387 | |
| 388 | public function withoutDublicatedConflicts() |
| 389 | { |
| 390 | $collection = new self(); |
| 391 | foreach ($this as $conflict) { |
| 392 | if (! $collection->getAppointmentList()->hasAppointment($conflict->getFirstAppointment())) { |
| 393 | $collection->addEntity(clone $conflict); |
| 394 | } |
| 395 | } |
| 396 | return $collection; |
| 397 | } |
| 398 | |
| 399 | public function testProcessListLength($processList, bool $isEmptyAllowed = false): ProcessList |
| 400 | { |
| 401 | $collection = ($processList instanceof Process) ? |
| 402 | (new self())->addEntity($processList) : |
| 403 | $processList; |
| 404 | |
| 405 | if (0 === $collection->count() && ! $isEmptyAllowed) { |
| 406 | throw new \BO\Zmsentities\Exception\ProcessListEmpty(); |
| 407 | } |
| 408 | return $collection; |
| 409 | } |
| 410 | |
| 411 | public function withoutProcessByStatus($process, $status) |
| 412 | { |
| 413 | $collection = clone $this; |
| 414 | $collection = (1 <= $collection->count() && ! Messaging::isEmptyProcessListAllowed($status)) ? |
| 415 | $collection->withOutProcessId($process->getId()) : |
| 416 | $collection; |
| 417 | return $collection; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * reduce process list to items with appointment time in range of given appointment |
| 422 | */ |
| 423 | public function withTimeRangeByAppointment(\BO\Zmsentities\Appointment $appointment) |
| 424 | { |
| 425 | $processList = new self(); |
| 426 | if ($this->count()) { |
| 427 | foreach ($this as $process) { |
| 428 | if ( |
| 429 | $appointment->getEndTime() > $process->getFirstAppointment()->getStartTime() && |
| 430 | $appointment->getStartTime() < $process->getFirstAppointment()->getEndTime() |
| 431 | ) { |
| 432 | $processList->addEntity(clone $process); |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | return $processList; |
| 437 | } |
| 438 | } |