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