Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
WarehouseReport | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
writeRawReport | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | /** |
4 | * @package zmsstatistic |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsstatistic\Download; |
9 | |
10 | use BO\Zmsentities\Exchange as ReportEntity; |
11 | use BO\Zmsstatistic\Helper\Download; |
12 | use PhpOffice\PhpSpreadsheet\Spreadsheet; |
13 | use Psr\Http\Message\RequestInterface; |
14 | use Psr\Http\Message\ResponseInterface; |
15 | |
16 | class WarehouseReport extends Base |
17 | { |
18 | /** |
19 | * @SuppressWarnings(Param) |
20 | * @return ResponseInterface |
21 | */ |
22 | public function readResponse( |
23 | RequestInterface $request, |
24 | ResponseInterface $response, |
25 | array $args |
26 | ) { |
27 | $title = 'raw_statistic_' . $args['subject'] . '_' . $args['subjectid'] . '_' . $args['period']; |
28 | $download = (new Download($request))->setSpreadSheet($title); |
29 | |
30 | $this->writeRawReport($args['report'], $download->getSpreadSheet()); |
31 | |
32 | return $download->writeDownload($response); |
33 | } |
34 | |
35 | protected function writeRawReport(ReportEntity $report, Spreadsheet $spreadsheet) |
36 | { |
37 | $sheet = $spreadsheet->getActiveSheet(); |
38 | $reportData = []; |
39 | foreach ($report->dictionary as $item) { |
40 | $reportData['header'][] = $item['variable']; |
41 | } |
42 | foreach ($report->data as $row => $entry) { |
43 | foreach ($entry as $item) { |
44 | $reportData[$row][] = (is_numeric($item)) ? (string)($item) : $item; |
45 | } |
46 | } |
47 | $sheet->fromArray($reportData, null, 'A' . ($sheet->getHighestRow())); |
48 | return $spreadsheet; |
49 | } |
50 | } |