Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.38% |
54 / 64 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WorkstationProcessNext | |
84.38% |
54 / 64 |
|
0.00% |
0 / 2 |
20.38 | |
0.00% |
0 / 1 |
| timeToUnix | |
28.57% |
2 / 7 |
|
0.00% |
0 / 1 |
9.83 | |||
| readResponse | |
91.23% |
52 / 57 |
|
0.00% |
0 / 1 |
15.15 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package Zmsadmin |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsadmin; |
| 9 | |
| 10 | use BO\Zmsentities\Collection\ProcessList; |
| 11 | |
| 12 | class WorkstationProcessNext extends BaseController |
| 13 | { |
| 14 | /** |
| 15 | * @SuppressWarnings(Param) |
| 16 | * @return String |
| 17 | */ |
| 18 | |
| 19 | public function timeToUnix($timeValue): ?int |
| 20 | { |
| 21 | if ($timeValue === null) { |
| 22 | return null; |
| 23 | } |
| 24 | $timeString = trim((string) $timeValue); |
| 25 | if ($timeString === '') { |
| 26 | return null; |
| 27 | } |
| 28 | $unixTimestamp = strtotime($timeString); |
| 29 | |
| 30 | return $unixTimestamp !== false ? $unixTimestamp : null; |
| 31 | } |
| 32 | |
| 33 | public function readResponse( |
| 34 | \Psr\Http\Message\RequestInterface $request, |
| 35 | \Psr\Http\Message\ResponseInterface $response, |
| 36 | array $args |
| 37 | ) { |
| 38 | $workstation = \App::$http->readGetResult('/workstation/', [ |
| 39 | 'resolveReferences' => 1, |
| 40 | 'gql' => Helper\GraphDefaults::getWorkstation() |
| 41 | ])->getEntity(); |
| 42 | $validator = $request->getAttribute('validator'); |
| 43 | $excludedIds = $validator->getParameter('exclude')->isString()->getValue(); |
| 44 | $excludedIds = ($excludedIds) ? $excludedIds : ''; |
| 45 | |
| 46 | $selectedDateTime = \App::$now; |
| 47 | $selectedDateTime = ($selectedDateTime < \App::$now) ? \App::$now : $selectedDateTime; |
| 48 | |
| 49 | $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation); |
| 50 | |
| 51 | $processList = $workstationRequest->readProcessListByDate( |
| 52 | $selectedDateTime, |
| 53 | Helper\GraphDefaults::getProcess() |
| 54 | ); |
| 55 | |
| 56 | $filteredProcessList = new ProcessList(); |
| 57 | |
| 58 | foreach ($processList as $process) { |
| 59 | if ($process->status === "queued" || $process->status === "confirmed") { |
| 60 | $timeoutTimeUnix = $this->timeToUnix($process->timeoutTime ?? null); |
| 61 | $currentTimeUnix = time(); |
| 62 | |
| 63 | if (!isset($process->timeoutTime)) { |
| 64 | $filteredProcessList->addEntity(clone $process); |
| 65 | } elseif ($timeoutTimeUnix !== null && !($process->queue->callCount > 0 && ($currentTimeUnix - $timeoutTimeUnix) < 300)) { |
| 66 | $filteredProcessList->addEntity(clone $process); |
| 67 | } else { |
| 68 | if (!empty($excludedIds)) { |
| 69 | $excludedIds .= ","; |
| 70 | } |
| 71 | $excludedIds .= $process->queue->number; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | $process = (new Helper\ClusterHelper($workstation))->getNextProcess($excludedIds); |
| 77 | |
| 78 | if (!$process || ! $process->hasId() || $process->getFirstAppointment()->date > \App::$now->getTimestamp()) { |
| 79 | return \BO\Slim\Render::withHtml( |
| 80 | $response, |
| 81 | 'block/process/next.twig', |
| 82 | array( |
| 83 | 'workstation' => $workstation, |
| 84 | 'processNotFoundInQueue' => 1, |
| 85 | 'exclude' => '' |
| 86 | ) |
| 87 | ); |
| 88 | } |
| 89 | if ($process->toProperty()->amendment->get()) { |
| 90 | return \BO\Slim\Render::redirect( |
| 91 | 'workstationProcessPreCall', |
| 92 | array( |
| 93 | 'id' => $process->id, |
| 94 | 'authkey' => $process->authKey |
| 95 | ), |
| 96 | array( |
| 97 | 'exclude' => $excludedIds |
| 98 | ) |
| 99 | ); |
| 100 | } |
| 101 | return \BO\Slim\Render::redirect( |
| 102 | 'workstationProcessCalled', |
| 103 | array( |
| 104 | 'id' => $process->id |
| 105 | ), |
| 106 | array( |
| 107 | 'exclude' => $excludedIds |
| 108 | ) |
| 109 | ); |
| 110 | } |
| 111 | } |