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