Lines
92.72%
51 / 55
Methods
60.00%
3 / 5
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| getInfoBoxData | 94.59% | 35 / 37 | 0.00% | 0 / 1 | 10.02 | ||
| stringTimeToMinute | 71.42% | 5 / 7 | 0.00% | 0 / 1 | 4.37 | ||
| 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 | ||
| 17 | class WorkstationInfo | |
| 18 | { | |
| 19 | public static function getInfoBoxData(Workstation $workstation, string $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): int | |
| 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 | /** | |
| 107 | * @param (float|int|mixed)[] $infoData | |
| 108 | * | |
| 109 | */ | |
| 110 | protected static function getAdditionalInfoData(array $infoData, QueueListHelper $queueListHelper) | |
| 111 | { | |
| 112 | $infoData['waitingTimeEstimate'] = $queueListHelper->getEstimatedWaitingTime(); | |
| 113 | $infoData['waitingTimeOptimistic'] = $queueListHelper->getOptimisticWaitingTime(); | |
| 114 | $infoData['waitingClientsBeforeNext'] = $queueListHelper->getWaitingClientsBeforeNext(); | |
| 115 | $infoData['waitingClientsEffective'] = $queueListHelper->getWaitingClientsEffective(); | |
| 116 | return $infoData; | |
| 117 | } | |
| 118 | } |