Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WorkstationProcessPreCall
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Mellon\Validator;
11
12class WorkstationProcessPreCall extends BaseController
13{
14    /**
15     * @return \Psr\Http\Message\ResponseInterface
16     */
17    #[\Override]
18    public function readResponse(
19        \Psr\Http\Message\RequestInterface $request,
20        \Psr\Http\Message\ResponseInterface $response,
21        array $args
22    ): \Psr\Http\Message\ResponseInterface {
23        $validator = $request->getAttribute('validator');
24
25        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
26        $processId = Validator::value($args['id'])->isNumber()->getValue();
27        $process = \App::$http->readGetResult('/process/' . $processId . '/')->getEntity();
28        $excludedIds = $validator->getParameter('exclude')->isString()->setDefault('')->getValue();
29        if ($excludedIds) {
30            $exclude = explode(',', $excludedIds);
31        }
32        $exclude[] = $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' => join(',', $exclude),
70                'error' => $error
71            )
72        );
73    }
74}