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    public function readResponse(
41        RequestInterface $request,
42        ResponseInterface $response,
43        array $args
44    ) {
45        $validator = $request->getAttribute('validator');
46        $waitingPeriod = \App::$http
47          ->readGetResult('/warehouse/waitingdepartment/' . $this->department->id . '/')
48          ->getEntity();
49        $exchangeWaiting = null;
50        if (isset($args['period'])) {
51            $exchangeWaiting = \App::$http
52                ->readGetResult('/warehouse/waitingdepartment/' . $this->department->id . '/' . $args['period'] . '/')
53                ->getEntity()
54                ->toGrouped($this->groupfields, $this->hashset);
55
56            $exchangeWaiting = ReportHelper::withTotalCustomers($exchangeWaiting);
57
58            $exchangeWaiting = $exchangeWaiting
59                ->withMaxByHour($this->hashset)
60                ->withMaxAndAverageFromWaitingTime();
61
62            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime');
63            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_termin');
64            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime');
65            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_termin');
66
67            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_total');
68            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_total');
69            $exchangeWaiting = ReportHelper::withGlobalMaxAndAverage($exchangeWaiting, 'waitingtime_total');
70            $exchangeWaiting = ReportHelper::withGlobalMaxAndAverage($exchangeWaiting, 'waytime_total');
71        }
72
73        $type = $validator->getParameter('type')->isString()->getValue();
74        if ($type) {
75            $args['category'] = 'waitingscope';
76            $args['reports'][] = $exchangeWaiting;
77            $args['department'] = $this->department;
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 Behörde',
87              'activeDepartment' => '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' => 'WaitingDepartment'],
96              'workstation' => $this->workstation->getArrayCopy()
97            )
98        );
99    }
100}