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