Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReportWaitingDepartment
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
40 / 40
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    ];
27
28    protected $groupfields = [
29        'date',
30        'hour'
31    ];
32
33    /**
34     * @SuppressWarnings(Param)
35     * @return ResponseInterface
36     */
37    public function readResponse(
38        RequestInterface $request,
39        ResponseInterface $response,
40        array $args
41    ) {
42        $validator = $request->getAttribute('validator');
43        $waitingPeriod = \App::$http
44          ->readGetResult('/warehouse/waitingdepartment/' . $this->department->id . '/')
45          ->getEntity();
46        $exchangeWaiting = null;
47        if (isset($args['period'])) {
48            $exchangeWaiting = \App::$http
49            ->readGetResult('/warehouse/waitingdepartment/' . $this->department->id . '/' . $args['period'] . '/')
50            ->getEntity()
51            ->toGrouped($this->groupfields, $this->hashset)
52            ->withMaxByHour($this->hashset)
53            ->withMaxAndAverageFromWaitingTime();
54
55            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime');
56            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waitingtime_termin');
57            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime');
58            $exchangeWaiting = ReportHelper::withMaxAndAverage($exchangeWaiting, 'waytime_termin');
59        }
60
61        $type = $validator->getParameter('type')->isString()->getValue();
62        if ($type) {
63            $args['category'] = 'waitingscope';
64            $args['reports'][] = $exchangeWaiting;
65            $args['department'] = $this->department;
66            $args['organisation'] = $this->organisation;
67            return (new Download\WaitingReport(\App::$slim->getContainer()))->readResponse($request, $response, $args);
68        }
69
70        return Render::withHtml(
71            $response,
72            'page/reportWaitingIndex.twig',
73            array(
74              'title' => 'Wartestatistik Behörde',
75              'activeDepartment' => 'active',
76              'menuActive' => 'waiting',
77              'department' => $this->department,
78              'organisation' => $this->organisation,
79              'waitingPeriod' => $waitingPeriod,
80              'showAll' => 1,
81              'period' => (isset($args['period'])) ? $args['period'] : null,
82              'exchangeWaiting' => $exchangeWaiting,
83              'source' => ['entity' => 'WaitingDepartment'],
84              'workstation' => $this->workstation->getArrayCopy()
85            )
86        );
87    }
88}