Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.00% |
49 / 50 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ReportClientIndex | |
98.00% |
49 / 50 |
|
66.67% |
2 / 3 |
7 | |
0.00% |
0 / 1 |
readResponse | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
3 | |||
handleDownloadRequest | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
renderHtmlResponse | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @package Zmsadmin |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsstatistic; |
9 | |
10 | use BO\Slim\Render; |
11 | use BO\Zmsstatistic\Service\ReportClientService; |
12 | use Psr\Http\Message\RequestInterface; |
13 | use Psr\Http\Message\ResponseInterface; |
14 | |
15 | class ReportClientIndex extends BaseController |
16 | { |
17 | protected $resolveLevel = 3; |
18 | |
19 | /** |
20 | * @SuppressWarnings(Param) |
21 | * @return ResponseInterface |
22 | */ |
23 | public function readResponse( |
24 | RequestInterface $request, |
25 | ResponseInterface $response, |
26 | array $args |
27 | ) { |
28 | $validator = $request->getAttribute('validator'); |
29 | $reportClientService = new ReportClientService(); |
30 | |
31 | $selectedScopes = $reportClientService->extractSelectedScopes( |
32 | $validator->getParameter('scopes')->isArray()->getValue() ?? [] |
33 | ); |
34 | |
35 | $scopeId = !empty($selectedScopes) ? implode(',', $selectedScopes) : $this->workstation->scope['id']; |
36 | |
37 | $clientPeriod = $reportClientService->getClientPeriod($this->workstation->scope['id']); |
38 | |
39 | $dateRange = $reportClientService->extractDateRange( |
40 | $validator->getParameter('from')->isString()->getValue(), |
41 | $validator->getParameter('to')->isString()->getValue() |
42 | ); |
43 | |
44 | $exchangeClient = $reportClientService->getExchangeClientData($scopeId, $dateRange, $args); |
45 | |
46 | $type = $validator->getParameter('type')->isString()->getValue(); |
47 | if ($type) { |
48 | return $this->handleDownloadRequest( |
49 | $request, |
50 | $response, |
51 | $args, |
52 | $exchangeClient, |
53 | $dateRange, |
54 | $selectedScopes, |
55 | $reportClientService |
56 | ); |
57 | } |
58 | |
59 | return $this->renderHtmlResponse($response, $args, $clientPeriod, $dateRange, $exchangeClient, $selectedScopes); |
60 | } |
61 | |
62 | /** |
63 | * Handle download request and return Excel file |
64 | */ |
65 | private function handleDownloadRequest( |
66 | $request, |
67 | $response, |
68 | $args, |
69 | $exchangeClient, |
70 | $dateRange, |
71 | $selectedScopes = [], |
72 | $reportClientService = null |
73 | ): ResponseInterface { |
74 | if ($reportClientService === null) { |
75 | $reportClientService = new ReportClientService(); |
76 | } |
77 | |
78 | $args = $reportClientService->prepareDownloadArgs($args, $exchangeClient, $dateRange, $selectedScopes); |
79 | |
80 | $args['scope'] = $this->workstation->getScope(); |
81 | $args['department'] = $this->department; |
82 | $args['organisation'] = $this->organisation; |
83 | |
84 | return (new Download\ClientReport(\App::$slim->getContainer()))->readResponse($request, $response, $args); |
85 | } |
86 | |
87 | /** |
88 | * Render HTML response for the report page |
89 | */ |
90 | private function renderHtmlResponse( |
91 | $response, |
92 | $args, |
93 | $clientPeriod, |
94 | $dateRange, |
95 | $exchangeClient, |
96 | $selectedScopes = [] |
97 | ): ResponseInterface { |
98 | return Render::withHtml( |
99 | $response, |
100 | 'page/reportClientIndex.twig', |
101 | array( |
102 | 'title' => 'Kundenstatistik Standort', |
103 | 'activeScope' => 'active', |
104 | 'menuActive' => 'client', |
105 | 'department' => $this->department, |
106 | 'organisation' => $this->organisation, |
107 | 'clientperiod' => $clientPeriod, |
108 | 'showAll' => 1, |
109 | 'period' => isset($args['period']) ? $args['period'] : null, |
110 | 'dateRange' => $dateRange, |
111 | 'exchangeClient' => $exchangeClient, |
112 | 'source' => ['entity' => 'ClientIndex'], |
113 | 'selectedScopeIds' => $selectedScopes, |
114 | 'workstation' => $this->workstation->getArrayCopy() |
115 | ) |
116 | ); |
117 | } |
118 | } |