Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReportWaitingDepartment
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
46 / 46
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3/**
4 * @package Zmsadmin
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsstatistic;
9
10use BO\Slim\Render;
11use Psr\Http\Message\RequestInterface;
12use Psr\Http\Message\ResponseInterface;
13use BO\Zmsstatistic\Helper\ReportHelper;
14
15class ReportWaitingDepartment extends BaseController
16{
17    protected $hashset = [
18        'waitingcount',
19        'waitingtime',
20        'waitingcalculated',
21        'waitingcount_termin',
22        'waitingtime_termin',
23        'waitingcalculated_termin',
24        'waytime',
25        'waytime_termin',
26        'waitingcount_total',
27        'waitingtime_total',
28        'waytime_total',
29    ];
30
31    protected $groupfields = [
32        'date',
33        'hour'
34    ];
35
36    /**
37     * @SuppressWarnings(Param)
38     * @return ResponseInterface
39     */
40    #[\Override]
41    public function readResponse(
42        RequestInterface $request,
43        ResponseInterface $response,
44        array $args
45    ) {
46        $validator = $request->getAttribute('validator');
47        $waitingPeriod = \App::$http
48          ->readGetResult('/warehouse/waitingdepartment/' . $this->department->id . '/')
49          ->getEntity();
50        $exchangeWaiting = null;
51        if (isset($args['period'])) {
52            $exchangeWaiting = \App::$http
53                ->readGetResult('/warehouse/waitingdepartment/' . $this->department->id . '/' . $args['period'] . '/')
54                ->getEntity()
55                ->toGrouped($this->groupfields, $this->hashset);
56
57            $exchangeWaiting = ReportHelper::withTotalCustomers($exchangeWaiting);
58
59            $exchangeWaiting = $exchangeWaiting
60                ->withMaxByHour($this->hashset)
61                ->withMaxAndAverageFromWaitingTime();
62
63            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime');
64            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_termin');
65            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime');
66            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_termin');
67
68            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_total');
69            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_total');
70            $exchangeWaiting = ReportHelper::withGlobalMaxAndAverage($exchangeWaiting, 'waitingtime_total');
71            $exchangeWaiting = ReportHelper::withGlobalMaxAndAverage($exchangeWaiting, 'waytime_total');
72        }
73
74        $type = $validator->getParameter('type')->isString()->getValue();
75        if ($type) {
76            $args['category'] = 'waitingscope';
77            $args['reports'][] = $exchangeWaiting;
78            $args['department'] = $this->department;
79            $args['organisation'] = $this->organisation;
80            return (new Download\WaitingReport(\App::$slim->getContainer()))->readResponse($request, $response, $args);
81        }
82
83        return Render::withHtml(
84            $response,
85            'page/reportWaitingIndex.twig',
86            array(
87              'title' => 'Wartestatistik Behörde',
88              'activeDepartment' => 'active',
89              'menuActive' => 'waiting',
90              'department' => $this->department,
91              'organisation' => $this->organisation,
92              'waitingPeriod' => $waitingPeriod,
93              'showAll' => 1,
94              'period' => (isset($args['period'])) ? $args['period'] : null,
95              'exchangeWaiting' => $exchangeWaiting,
96              'source' => ['entity' => 'WaitingDepartment'],
97              'workstation' => $this->workstation->getArrayCopy()
98            )
99        );
100    }
101}