Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.73% |
51 / 55 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
WorkstationInfo | |
92.73% |
51 / 55 |
|
60.00% |
3 / 5 |
16.10 | |
0.00% |
0 / 1 |
getInfoBoxData | |
94.59% |
35 / 37 |
|
0.00% |
0 / 1 |
10.02 | |||
stringTimeToMinute | |
71.43% |
5 / 7 |
|
0.00% |
0 / 1 |
3.21 | |||
getWorkstationsByScope | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getWorkstationsByCluster | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getAdditionalInfoData | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | * @package Zmsadmin |
6 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
7 | * |
8 | */ |
9 | |
10 | namespace BO\Zmsadmin\Helper; |
11 | |
12 | use BO\Mellon\Validator; |
13 | |
14 | class WorkstationInfo |
15 | { |
16 | public static function getInfoBoxData(\BO\Zmsentities\Workstation $workstation, $selectedDate) |
17 | { |
18 | $infoData = array( |
19 | 'waitingTimeEstimate' => 0, |
20 | 'waitingTimeOptimistic' => 0, |
21 | 'waitingClientsFullList' => 0, |
22 | 'waitingClientsBeforeNext' => 0, |
23 | 'waitingClientsEffective' => 0 |
24 | ); |
25 | $scope = \App::$http->readGetResult('/scope/' . $workstation->scope['id'] . '/workstationcount/')->getEntity(); |
26 | |
27 | $clusterHelper = (new ClusterHelper($workstation)); |
28 | |
29 | $infoData['workstationGhostCount'] = $scope->status['queue']['ghostWorkstationCount']; |
30 | $infoData['workstationList'] = ($clusterHelper->isClusterEnabled()) ? |
31 | static::getWorkstationsByCluster($clusterHelper->getEntity()->getId()) : |
32 | static::getWorkstationsByScope($scope->getId()); |
33 | |
34 | $queueListHelper = (new QueueListHelper($clusterHelper, $selectedDate)); |
35 | |
36 | $workstationRequest = new \BO\Zmsclient\WorkstationRequests(\App::$http, $workstation); |
37 | $processList = $workstationRequest->readProcessListByDate( |
38 | new \DateTime($selectedDate) |
39 | ); |
40 | |
41 | $withAppointment = []; |
42 | $withoutAppointment = []; |
43 | |
44 | foreach ($processList as $process) { |
45 | if (!in_array($process->queue->status, ['queued', 'confirmed']) || $process->queue->waitingTime === 0) { |
46 | continue; |
47 | } |
48 | |
49 | if ($process->queue->withAppointment) { |
50 | $withAppointment[] = self::stringTimeToMinute($process->queue->waitingTime); |
51 | continue; |
52 | } |
53 | |
54 | $withoutAppointment[] = self::stringTimeToMinute($process->queue->waitingTime); |
55 | } |
56 | |
57 | $infoData['averageWaitingTimeWithAppointment'] = |
58 | count($withAppointment) ? array_sum($withAppointment) / count($withAppointment) : 0; |
59 | $infoData['averageWaitingTimeWithoutAppointment'] = |
60 | count($withoutAppointment) ? array_sum($withoutAppointment) / count($withoutAppointment) : 0; |
61 | |
62 | $infoData['countCurrentlyProcessing'] = count($queueListHelper->getFullList()->withStatus(['called', 'processing'])); |
63 | |
64 | if ($queueListHelper->getWaitingCount()) { |
65 | $infoData['waitingClientsFullList'] = $queueListHelper->getWaitingCount(); |
66 | if ($selectedDate == \App::$now->format('Y-m-d')) { |
67 | $infoData = static::getAdditionalInfoData($infoData, $queueListHelper); |
68 | } |
69 | } |
70 | return $infoData; |
71 | } |
72 | |
73 | public static function stringTimeToMinute($time) |
74 | { |
75 | $timeArray = explode(':', $time); |
76 | |
77 | if (count($timeArray) === 3) { |
78 | $minutes = (int) $timeArray[0] * 60 * 24 + (int) $timeArray[1] * 60 + (int) $timeArray[2]; |
79 | } elseif (count($timeArray) === 2) { |
80 | $minutes = (int) $timeArray[0] * 60 + (int) $timeArray[1]; |
81 | } else { |
82 | $minutes = (int) $timeArray[0]; |
83 | } |
84 | |
85 | return $minutes; |
86 | } |
87 | |
88 | |
89 | public static function getWorkstationsByScope($scopeId) |
90 | { |
91 | return \App::$http |
92 | ->readGetResult('/scope/' . $scopeId . '/workstation/', ['resolveReferences' => 1]) |
93 | ->getCollection(); |
94 | } |
95 | |
96 | public static function getWorkstationsByCluster($clusterId) |
97 | { |
98 | return \App::$http |
99 | ->readGetResult('/cluster/' . $clusterId . '/workstation/', ['resolveReferences' => 1]) |
100 | ->getCollection(); |
101 | } |
102 | |
103 | protected static function getAdditionalInfoData($infoData, $queueListHelper) |
104 | { |
105 | $infoData['waitingTimeEstimate'] = $queueListHelper->getEstimatedWaitingTime(); |
106 | $infoData['waitingTimeOptimistic'] = $queueListHelper->getOptimisticWaitingTime(); |
107 | $infoData['waitingClientsBeforeNext'] = $queueListHelper->getWaitingClientsBeforeNext(); |
108 | $infoData['waitingClientsEffective'] = $queueListHelper->getWaitingClientsEffective(); |
109 | return $infoData; |
110 | } |
111 | } |