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