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 String
16     */
17    public function readResponse(
18        \Psr\Http\Message\RequestInterface $request,
19        \Psr\Http\Message\ResponseInterface $response,
20        array $args
21    ) {
22        $validator = $request->getAttribute('validator');
23
24        $workstation = \App::$http->readGetResult('/workstation/', ['resolveReferences' => 2])->getEntity();
25        $processId = Validator::value($args['id'])->isNumber()->getValue();
26        $process = \App::$http->readGetResult('/process/' . $processId . '/')->getEntity();
27        $excludedIds = $validator->getParameter('exclude')->isString()->setDefault('')->getValue();
28        if ($excludedIds) {
29            $exclude = explode(',', $excludedIds);
30        }
31        $exclude[] = $process->toQueue(\App::$now)->number;
32
33        $error = $validator->getParameter('error')->isString()->getValue();
34        if ($workstation->process->getId()) {
35            if ($workstation->process->getId() != $processId) {
36                $error = 'has_called_process';
37            }
38        }
39
40        if ('called' == $workstation->process->getStatus()) {
41            return \BO\Slim\Render::redirect(
42                'workstationProcessCalled',
43                ['id' => $workstation->process->getId()],
44                ['error' => $error]
45            );
46        }
47
48        // Get waiting time for precall twig since no query is performed
49        $currentTime = new \DateTime();
50        $arrivalTime = new \DateTime();
51        $timestamp = (int) $process->queue->arrivalTime;
52        $arrivalTime->setTimestamp($timestamp);
53        $differenceInSeconds = $currentTime->getTimestamp() - $arrivalTime->getTimestamp();
54        $hours = intdiv($differenceInSeconds, 3600);
55        $minutes = intdiv($differenceInSeconds % 3600, 60);
56        $seconds = $differenceInSeconds % 60;
57        $waitingTime = sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
58
59        return \BO\Slim\Render::withHtml(
60            $response,
61            'block/process/precall.twig',
62            array(
63                'title' => 'Sachbearbeiter',
64                'workstation' => $workstation,
65                'menuActive' => 'workstation',
66                'process' => $process,
67                'timeDifference' => $waitingTime, // Pass this to Twig
68                'exclude' => join(',', $exclude),
69                'error' => $error
70            )
71        );
72    }
73}