Lines
100.00%
40 / 40
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WorkstationProcessPreCall | 100.00% | 40 / 40 | 100.00% | 1 / 1 | 4 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 40 / 40 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package Zmsadmin | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsadmin; | |
| 9 | ||
| 10 | use BO\Mellon\Validator; | |
| 11 | use BO\Zmsadmin\Helper\ExcludeIds; | |
| 12 | ||
| 13 | class WorkstationProcessPreCall extends BaseController | |
| 14 | { | |
| 15 | /** | |
| 16 | * @return \Psr\Http\Message\ResponseInterface | |
| 17 | */ | |
| 18 | #[\Override] | |
| 19 | public function readResponse( | |
| 20 | \Psr\Http\Message\RequestInterface $request, | |
| 21 | \Psr\Http\Message\ResponseInterface $response, | |
| 22 | array $args | |
| 23 | ): \Psr\Http\Message\ResponseInterface { | |
| 24 | $validator = $request->getAttribute('validator'); | |
| 25 | ||
| 26 | $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity(); | |
| 27 | $processId = Validator::value($args['id'])->isNumber()->getValue(); | |
| 28 | $process = \App::$http->readGetResult('/process/' . $processId . '/')->getEntity(); | |
| 29 | $excludedIds = ExcludeIds::fromQuery( | |
| 30 | $validator->getParameter('exclude')->isString()->setDefault('')->getValue() | |
| 31 | ); | |
| 32 | $excludedIds[] = $process->toQueue(\App::$now)->number; | |
| 33 | ||
| 34 | $error = $validator->getParameter('error')->isString()->getValue(); | |
| 35 | if ($workstation->process->getId()) { | |
| 36 | if ($workstation->process->getId() != $processId) { | |
| 37 | $error = 'has_called_process'; | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | if ('called' == $workstation->process->getStatus()) { | |
| 42 | return \BO\Slim\Render::redirect( | |
| 43 | 'workstationProcessCalled', | |
| 44 | ['id' => $workstation->process->getId()], | |
| 45 | ['error' => $error] | |
| 46 | ); | |
| 47 | } | |
| 48 | ||
| 49 | // Get waiting time for precall twig since no query is performed | |
| 50 | $currentTime = new \DateTime(); | |
| 51 | $arrivalTime = new \DateTime(); | |
| 52 | $timestamp = (int) $process->queue->arrivalTime; | |
| 53 | $arrivalTime->setTimestamp($timestamp); | |
| 54 | $differenceInSeconds = $currentTime->getTimestamp() - $arrivalTime->getTimestamp(); | |
| 55 | $hours = intdiv($differenceInSeconds, 3600); | |
| 56 | $minutes = intdiv($differenceInSeconds % 3600, 60); | |
| 57 | $seconds = $differenceInSeconds % 60; | |
| 58 | $waitingTime = sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); | |
| 59 | ||
| 60 | return \BO\Slim\Render::withHtml( | |
| 61 | $response, | |
| 62 | 'block/process/precall.twig', | |
| 63 | array( | |
| 64 | 'title' => 'Sachbearbeiter', | |
| 65 | 'workstation' => $workstation, | |
| 66 | 'menuActive' => 'workstation', | |
| 67 | 'process' => $process, | |
| 68 | 'timeDifference' => $waitingTime, // Pass this to Twig | |
| 69 | 'exclude' => ExcludeIds::toQuery($excludedIds), | |
| 70 | 'error' => $error | |
| 71 | ) | |
| 72 | ); | |
| 73 | } | |
| 74 | } |