Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReportWaitingOrganisation
100.00% covered (success)
100.00%
39 / 39
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 readResponse
100.00% covered (success)
100.00%
39 / 39
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    ];
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/waitingorganisation/' . $this->organisation->id . '/')
45          ->getEntity();
46        $exchangeWaiting = null;
47        if (isset($args['period'])) {
48            $exchangeWaiting = \App::$http
49            ->readGetResult('/warehouse/waitingorganisation/' . $this->organisation->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['organisation'] = $this->organisation;
66            return (new Download\WaitingReport(\App::$slim->getContainer()))->readResponse($request, $response, $args);
67        }
68
69        return Render::withHtml(
70            $response,
71            'page/reportWaitingIndex.twig',
72            array(
73              'title' => 'Wartestatistik Bezirk',
74              'activeOrganisation' => 'active',
75              'menuActive' => 'waiting',
76              'department' => $this->department,
77              'organisation' => $this->organisation,
78              'waitingPeriod' => $waitingPeriod,
79              'showAll' => 1,
80              'period' => (isset($args['period'])) ? $args['period'] : null,
81              'exchangeWaiting' => $exchangeWaiting,
82              'source' => ['entity' => 'WaitingOrganisation'],
83              'workstation' => $this->workstation->getArrayCopy()
84            )
85        );
86    }
87}