Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
45 / 45
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReportWaitingOrganisation
100.00% covered (success)
100.00%
45 / 45
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
45 / 45
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 ReportWaitingOrganisation 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/waitingorganisation/' . $this->organisation->id . '/')
49          ->getEntity();
50        $exchangeWaiting = null;
51        if (isset($args['period'])) {
52            $exchangeWaiting = \App::$http
53                ->readGetResult('/warehouse/waitingorganisation/' . $this->organisation->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['organisation'] = $this->organisation;
79            return (new Download\WaitingReport(\App::$slim->getContainer()))->readResponse($request, $response, $args);
80        }
81
82        return Render::withHtml(
83            $response,
84            'page/reportWaitingIndex.twig',
85            array(
86              'title' => 'Wartestatistik Bezirk',
87              'activeOrganisation' => 'active',
88              'menuActive' => 'waiting',
89              'department' => $this->department,
90              'organisation' => $this->organisation,
91              'waitingPeriod' => $waitingPeriod,
92              'showAll' => 1,
93              'period' => (isset($args['period'])) ? $args['period'] : null,
94              'exchangeWaiting' => $exchangeWaiting,
95              'source' => ['entity' => 'WaitingOrganisation'],
96              'workstation' => $this->workstation->getArrayCopy()
97            )
98        );
99    }
100}