Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
47 / 47
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReportWaitingOrganisation
100.00% covered (success)
100.00%
47 / 47
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
47 / 47
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 array $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 array $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    ): mixed {
46        /** @var \Psr\Http\Message\ServerRequestInterface $request */
47        $validator = $request->getAttribute('validator');
48        $waitingPeriod = \App::http()
49          ->readGetResult('/warehouse/waitingorganisation/' . $this->organisation->id . '/')
50          ->getEntity();
51        $exchangeWaiting = null;
52        if (isset($args['period'])) {
53            /** @var mixed $entity */
54            $entity = \App::http()
55                ->readGetResult('/warehouse/waitingorganisation/' . $this->organisation->id . '/' . $args['period'] . '/')
56                ->getEntity();
57            $exchangeWaiting = $entity
58                ->toGrouped($this->groupfields, $this->hashset);
59
60            $exchangeWaiting = ReportHelper::withTotalCustomers($exchangeWaiting);
61
62            $exchangeWaiting = $exchangeWaiting
63                ->withMaxByHour($this->hashset)
64                ->withMaxAndAverageFromWaitingTime();
65
66            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime');
67            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_termin');
68            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime');
69            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_termin');
70
71            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_total');
72            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_total');
73            $exchangeWaiting = ReportHelper::withGlobalMaxAndAverage($exchangeWaiting, 'waitingtime_total');
74            $exchangeWaiting = ReportHelper::withGlobalMaxAndAverage($exchangeWaiting, 'waytime_total');
75        }
76
77        $type = $validator->getParameter('type')->isString()->getValue();
78        if ($type) {
79            $args['category'] = 'waitingscope';
80            $args['reports'][] = $exchangeWaiting;
81            $args['organisation'] = $this->organisation;
82            /** @var mixed $container */
83            $container = \App::$slim->getContainer();
84            return (new Download\WaitingReport($container))->readResponse($request, $response, $args);
85        }
86
87        return Render::withHtml(
88            $response,
89            'page/reportWaitingIndex.twig',
90            array(
91              'title' => 'Wartestatistik Bezirk',
92              'activeOrganisation' => 'active',
93              'menuActive' => 'waiting',
94              'department' => $this->department,
95              'organisation' => $this->organisation,
96              'waitingPeriod' => $waitingPeriod,
97              'showAll' => 1,
98              'period' => (isset($args['period'])) ? $args['period'] : null,
99              'exchangeWaiting' => $exchangeWaiting,
100              'source' => ['entity' => 'WaitingOrganisation'],
101              'workstation' => $this->workstation->getArrayCopy()
102            )
103        );
104    }
105}