Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.84% |
85 / 86 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
QueueTable | |
98.84% |
85 / 86 |
|
66.67% |
2 / 3 |
12 | |
0.00% |
0 / 1 |
readResponse | |
98.75% |
79 / 80 |
|
0.00% |
0 / 1 |
10 | |||
getWorkstationsByScope | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getWorkstationsByCluster | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsadmin |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsadmin; |
9 | |
10 | use BO\Zmsadmin\Helper\ClusterHelper; |
11 | use BO\Zmsentities\Collection\QueueList; |
12 | |
13 | class 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 | // parameters |
27 | $validator = $request->getAttribute('validator'); |
28 | $success = $validator->getParameter('success')->isString()->getValue(); |
29 | $withCalledList = $validator->getParameter('withCalled')->isBool()->getValue(); |
30 | $selectedDate = $validator->getParameter('selecteddate')->isString()->getValue(); |
31 | $selectedDateTime = $selectedDate ? new \DateTimeImmutable($selectedDate) : \App::$now; |
32 | $selectedDateTime = ($selectedDateTime < \App::$now) ? \App::$now : $selectedDateTime; |
33 | |
34 | $selectedProcessId = $validator->getParameter('selectedprocess')->isNumber()->getValue(); |
35 | |
36 | // HTTP requests |
37 | $workstation = \App::$http->readGetResult('/workstation/', [ |
38 | 'resolveReferences' => 1, |
39 | 'gql' => Helper\GraphDefaults::getWorkstation() |
40 | ])->getEntity(); |
41 | $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation); |
42 | $department = $workstationRequest->readDepartment(); |
43 | $processList = $workstationRequest->readProcessListByDate( |
44 | $selectedDateTime, |
45 | Helper\GraphDefaults::getProcess() |
46 | ); |
47 | $changedProcess = ($selectedProcessId) |
48 | ? \App::$http->readGetResult('/process/' . $selectedProcessId . '/', [ |
49 | 'gql' => Helper\GraphDefaults::getProcess() |
50 | ])->getEntity() |
51 | : null; |
52 | |
53 | // data refinement |
54 | $queueList = $processList->toQueueList(\App::$now); |
55 | $queueList = $queueList->withSortedArrival(); |
56 | $scope = $workstation->getScope(); |
57 | $clusterHelper = (new ClusterHelper($workstation)); |
58 | |
59 | $workstationGhostCount = $scope->status['queue']['ghostWorkstationCount']; |
60 | $workstationList = ($clusterHelper->isClusterEnabled()) ? |
61 | static::getWorkstationsByCluster($clusterHelper->getEntity()->getId()) : |
62 | static::getWorkstationsByScope($scope->getId()); |
63 | |
64 | $workstationCount = $workstationGhostCount > 0 |
65 | ? $workstationGhostCount |
66 | : ($workstationList === null ? 1 : count($workstationList)); |
67 | $timeAverage = $scope->getPreference('queue', 'processingTimeAverage') ?? 10; |
68 | |
69 | $queueListVisible = $queueList |
70 | ->withStatus(['preconfirmed', 'confirmed', 'queued', 'reserved', 'deleted']) |
71 | ->withEstimatedWaitingTime($timeAverage, $workstationCount, \App::$now, false); |
72 | $queueListMissed = $queueList->withStatus(['missed']); |
73 | $queueListParked = $queueList->withStatus(['parked']); |
74 | $queueListFinished = $queueList->withStatus(['finished']); |
75 | |
76 | $queueListCalled = $withCalledList ? (\App::$http |
77 | ->readGetResult( |
78 | '/useraccount/queue/', |
79 | [ |
80 | 'resolveReferences' => 2, |
81 | 'status' => 'called,processing', |
82 | ] |
83 | ) |
84 | ->getCollection() ?? []) : []; |
85 | |
86 | if ($queueListCalled instanceof \BO\Zmsentities\Collection\QueueList) { |
87 | $queueListCalled->uasort(function ($queueA, $queueB) { |
88 | $statusOrder = ['called' => 0, 'processing' => 1]; |
89 | |
90 | $statusValueA = $statusOrder[$queueA->status] ?? PHP_INT_MAX; |
91 | $statusValueB = $statusOrder[$queueB->status] ?? PHP_INT_MAX; |
92 | |
93 | $cmp = $statusValueA <=> $statusValueB; |
94 | return $cmp !== 0 ? $cmp : $queueB->callTime <=> $queueA->callTime; |
95 | }); |
96 | } else { |
97 | $queueListCalled = []; |
98 | } |
99 | |
100 | return \BO\Slim\Render::withHtml( |
101 | $response, |
102 | 'block/queue/table.twig', |
103 | array( |
104 | 'workstation' => $workstation->getArrayCopy(), |
105 | 'department' => $department, |
106 | 'source' => $workstation->getVariantName(), |
107 | 'selectedDate' => $selectedDateTime->format('Y-m-d'), |
108 | 'cluster' => $workstationRequest->readCluster(), |
109 | 'clusterEnabled' => $workstation->isClusterEnabled(), |
110 | 'processList' => $queueListVisible->toProcessList(), |
111 | 'processListMissed' => $queueListMissed->toProcessList(), |
112 | 'processListParked' => $queueListParked->toProcessList(), |
113 | 'processListFinished' => $queueListFinished->toProcessList(), |
114 | 'showCalledList' => $withCalledList, |
115 | 'queueListCalled' => $queueListCalled, |
116 | 'changedProcess' => $changedProcess, |
117 | 'success' => $success, |
118 | 'debug' => \App::DEBUG, |
119 | 'allowClusterWideCall' => \App::$allowClusterWideCall |
120 | ) |
121 | ); |
122 | } |
123 | |
124 | public static function getWorkstationsByScope($scopeId) |
125 | { |
126 | return \App::$http |
127 | ->readGetResult('/scope/' . $scopeId . '/workstation/', ['resolveReferences' => 1]) |
128 | ->getCollection(); |
129 | } |
130 | |
131 | public static function getWorkstationsByCluster($clusterId) |
132 | { |
133 | return \App::$http |
134 | ->readGetResult('/cluster/' . $clusterId . '/workstation/', ['resolveReferences' => 1]) |
135 | ->getCollection(); |
136 | } |
137 | } |