Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
70 / 70
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
QueueTable
100.00% covered (success)
100.00%
70 / 70
100.00% covered (success)
100.00%
1 / 1
7
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
70 / 70
100.00% covered (success)
100.00%
1 / 1
7
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        // parameters
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        // HTTP requests
36        $workstation = \App::$http->readGetResult('/workstation/', [
37            'resolveReferences' => 1,
38            'gql' => Helper\GraphDefaults::getWorkstation()
39        ])->getEntity();
40        $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation);
41        $department = $workstationRequest->readDepartment();
42        $processList = $workstationRequest->readProcessListByDate(
43            $selectedDateTime,
44            Helper\GraphDefaults::getProcess()
45        );
46        $changedProcess = ($selectedProcessId)
47            ? \App::$http->readGetResult('/process/' . $selectedProcessId . '/', [
48                'gql' => Helper\GraphDefaults::getProcess()
49            ])->getEntity()
50            : null;
51
52        // data refinement
53        $queueList = $processList->toQueueList(\App::$now);
54        $queueList->uasort(function ($queueA, $queueB) {
55            return $queueA->arrivalTime - $queueB->arrivalTime;
56        });
57        $queueListVisible = $queueList->withStatus(['preconfirmed', 'confirmed', 'queued', 'reserved', 'deleted']);
58        $queueListMissed = $queueList->withStatus(['missed']);
59        $queueListParked = $queueList->withStatus(['parked']);
60        $queueListFinished = $queueList->withStatus(['finished']);
61
62        $queueListCalled = $withCalledList ? (\App::$http
63            ->readGetResult(
64                '/useraccount/queue/',
65                [
66                    'resolveReferences' => 2,
67                    'status' => 'called,processing',
68                ]
69            )
70            ->getCollection() ?? []) : [];
71
72        if ($queueListCalled instanceof \BO\Zmsentities\Collection\QueueList) {
73            $queueListCalled->uasort(function ($queueA, $queueB) {
74                $statusOrder = ['called' => 0, 'processing' => 1];
75
76                $statusValueA = $statusOrder[$queueA->status] ?? PHP_INT_MAX;
77                $statusValueB = $statusOrder[$queueB->status] ?? PHP_INT_MAX;
78
79                $cmp = $statusValueA <=> $statusValueB;
80                return $cmp !== 0 ? $cmp : $queueB->callTime <=> $queueA->callTime;
81            });
82        } else {
83            $queueListCalled = [];
84        }
85
86        return \BO\Slim\Render::withHtml(
87            $response,
88            'block/queue/table.twig',
89            array(
90                'workstation' => $workstation->getArrayCopy(),
91                'department' => $department,
92                'source' => $workstation->getVariantName(),
93                'selectedDate' => $selectedDateTime->format('Y-m-d'),
94                'cluster' => $workstationRequest->readCluster(),
95                'clusterEnabled' => $workstation->isClusterEnabled(),
96                'processList' => $queueListVisible->toProcessList(),
97                'processListMissed' => $queueListMissed->toProcessList(),
98                'processListParked' => $queueListParked->toProcessList(),
99                'processListFinished' => $queueListFinished->toProcessList(),
100                'showCalledList' => $withCalledList,
101                'queueListCalled' => $queueListCalled,
102                'changedProcess' => $changedProcess,
103                'success' => $success,
104                'debug' => \App::DEBUG,
105                'allowClusterWideCall' => \App::$allowClusterWideCall
106            )
107        );
108    }
109}