Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WorkstationProcessPreCall
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
6
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
42 / 42
100.00% covered (success)
100.00%
1 / 1
6
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            if ('pickup' == $workstation->process->getStatus()) {
39                $error = 'has_called_pickup';
40            }
41        }
42
43        if ('called' == $workstation->process->getStatus()) {
44            return \BO\Slim\Render::redirect(
45                'workstationProcessCalled',
46                ['id' => $workstation->process->getId()],
47                ['error' => $error]
48            );
49        }
50
51        // Get waiting time for precall twig since no query is performed
52        $currentTime = new \DateTime();
53        $arrivalTime = new \DateTime();
54        $timestamp = (int) $process->queue->arrivalTime;
55        $arrivalTime->setTimestamp($timestamp);
56        $differenceInSeconds = $currentTime->getTimestamp() - $arrivalTime->getTimestamp();
57        $hours = intdiv($differenceInSeconds, 3600);
58        $minutes = intdiv($differenceInSeconds % 3600, 60);
59        $seconds = $differenceInSeconds % 60;
60        $waitingTime = sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
61
62        return \BO\Slim\Render::withHtml(
63            $response,
64            'block/process/precall.twig',
65            array(
66                'title' => 'Sachbearbeiter',
67                'workstation' => $workstation,
68                'menuActive' => 'workstation',
69                'process' => $process,
70                'timeDifference' => $waitingTime, // Pass this to Twig
71                'exclude' => join(',', $exclude),
72                'error' => $error
73            )
74        );
75    }
76}