Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
97.44% covered (success)
97.44%
38 / 39
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReportClientIndex
97.44% covered (success)
97.44%
38 / 39
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 readResponse
97.44% covered (success)
97.44%
38 / 39
0.00% covered (danger)
0.00%
0 / 1
6
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;
13
14class ReportClientIndex extends BaseController
15{
16    protected $totals = [
17        'clientscount',
18        'missed',
19        'withappointment',
20        'missedwithappointment',
21        'noappointment',
22        'missednoappointment',
23        'requestscount'
24    ];
25
26    /**
27     * @SuppressWarnings(Param)
28     * @return ResponseInterface
29     */
30    public function readResponse(
31        RequestInterface $request,
32        ResponseInterface $response,
33        array $args
34    ) {
35        $validator = $request->getAttribute('validator');
36        $scopeId = $this->workstation->scope['id'];
37        $clientPeriod = \App::$http
38          ->readGetResult('/warehouse/clientscope/' . $scopeId . '/')
39          ->getEntity();
40
41        $exchangeClient = null;
42        if (isset($args['period'])) {
43            try {
44                $exchangeClient = \App::$http
45                    ->readGetResult('/warehouse/clientscope/' . $scopeId . '/' . $args['period'] . '/')
46                    ->getEntity()
47                    ->withCalculatedTotals($this->totals, 'date')
48                    ->toHashed();
49            } catch (\Exception $exception) {
50                // do nothing
51            }
52        }
53
54        $type = $validator->getParameter('type')->isString()->getValue();
55        if ($type) {
56            $args['category'] = 'clientscope';
57
58            if (count($exchangeClient->data)) {
59                $args['reports'][] = $exchangeClient;
60            }
61            $args['scope'] = $this->workstation->getScope();
62            $args['department'] = $this->department;
63            $args['organisation'] = $this->organisation;
64            return (new Download\ClientReport(\App::$slim->getContainer()))->readResponse($request, $response, $args);
65        }
66
67        return Render::withHtml(
68            $response,
69            'page/reportClientIndex.twig',
70            array(
71                'title' => 'Kundenstatistik Standort',
72                'activeScope' => 'active',
73                'menuActive' => 'client',
74                'department' => $this->department,
75                'organisation' => $this->organisation,
76                'clientperiod' => $clientPeriod,
77                'showAll' => 1,
78                'period' => isset($args['period']) ? $args['period'] : null,
79                'exchangeClient' => $exchangeClient,
80                'source' => ['entity' => 'ClientIndex'],
81                'workstation' => $this->workstation->getArrayCopy()
82            )
83        );
84    }
85}