Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.12% covered (success)
94.12%
64 / 68
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
QueueTable
94.12% covered (success)
94.12%
64 / 68
0.00% covered (danger)
0.00%
0 / 1
7.01
0.00% covered (danger)
0.00%
0 / 1
 readResponse
94.12% covered (success)
94.12%
64 / 68
0.00% covered (danger)
0.00%
0 / 1
7.01
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsadmin;
9
10use BO\Zmsadmin\Helper\ClusterHelper;
11use BO\Zmsentities\Collection\QueueList;
12
13class QueueTable extends BaseController
14{
15    protected $processStatusList = ['preconfirmed', 'confirmed', 'queued', 'reserved', 'deleted'];
16
17    /**
18     * @SuppressWarnings(Param)
19     * @return String
20     */
21    public function readResponse(
22        \Psr\Http\Message\RequestInterface $request,
23        \Psr\Http\Message\ResponseInterface $response,
24        array $args
25    ) {
26        $validator = $request->getAttribute('validator');
27        $success = $validator->getParameter('success')->isString()->getValue();
28        $withCalledList = $validator->getParameter('withCalled')->isBool()->getValue();
29        $selectedDate = $validator->getParameter('selecteddate')->isString()->getValue();
30        $selectedDateTime = $selectedDate ? new \DateTimeImmutable($selectedDate) : \App::$now;
31        $selectedDateTime = ($selectedDateTime < \App::$now) ? \App::$now : $selectedDateTime;
32
33        $selectedProcessId = $validator->getParameter('selectedprocess')->isNumber()->getValue();
34
35        $workstation = \App::$http->readGetResult('/workstation/', [
36            'resolveReferences' => 1,
37            'gql' => Helper\GraphDefaults::getWorkstation()
38        ])->getEntity();
39        $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation);
40        $department = $workstationRequest->readDepartment();
41        $processList = $workstationRequest->readProcessListByDate(
42            $selectedDateTime,
43            Helper\GraphDefaults::getProcess()
44        );
45        $changedProcess = ($selectedProcessId)
46            ? \App::$http->readGetResult('/process/' . $selectedProcessId . '/', [
47                'gql' => Helper\GraphDefaults::getProcess()
48            ])->getEntity()
49            : null;
50
51        $queueList = $processList->toQueueList(\App::$now);
52
53        $queueListVisible = $queueList
54            ->withStatus(['preconfirmed', 'confirmed', 'queued', 'reserved', 'deleted']);
55        $queueListMissed = $queueList->withStatus(['missed']);
56        $queueListParked = $queueList->withStatus(['parked']);
57        $queueListFinished = $queueList->withStatus(['finished']);
58
59        $queueListCalled = $withCalledList ? (\App::$http
60            ->readGetResult(
61                '/useraccount/queue/',
62                [
63                    'resolveReferences' => 2,
64                    'status' => 'called,processing',
65                ]
66            )
67            ->getCollection() ?? []) : [];
68
69        if ($queueListCalled instanceof \BO\Zmsentities\Collection\QueueList) {
70            $queueListCalled->uasort(function ($queueA, $queueB) {
71                $statusOrder = ['called' => 0, 'processing' => 1];
72
73                $statusValueA = $statusOrder[$queueA->status] ?? PHP_INT_MAX;
74                $statusValueB = $statusOrder[$queueB->status] ?? PHP_INT_MAX;
75
76                $cmp = $statusValueA <=> $statusValueB;
77                return $cmp !== 0 ? $cmp : $queueB->callTime <=> $queueA->callTime;
78            });
79        } else {
80            $queueListCalled = [];
81        }
82
83        return \BO\Slim\Render::withHtml(
84            $response,
85            'block/queue/table.twig',
86            array(
87                'workstation' => $workstation->getArrayCopy(),
88                'department' => $department,
89                'source' => $workstation->getVariantName(),
90                'selectedDate' => $selectedDateTime->format('Y-m-d'),
91                'cluster' => $workstationRequest->readCluster(),
92                'clusterEnabled' => $workstation->isClusterEnabled(),
93                'processList' => $queueListVisible->toProcessList(),
94                'processListMissed' => $queueListMissed->toProcessList(),
95                'processListParked' => $queueListParked->toProcessList(),
96                'processListFinished' => $queueListFinished->toProcessList(),
97                'showCalledList' => $withCalledList,
98                'queueListCalled' => $queueListCalled,
99                'changedProcess' => $changedProcess,
100                'success' => $success,
101                'debug' => \App::DEBUG,
102                'allowClusterWideCall' => \App::$allowClusterWideCall
103            )
104        );
105    }
106}