Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
74.36% covered (warning)
74.36%
29 / 39
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Base
74.36% covered (warning)
74.36%
29 / 39
33.33% covered (danger)
33.33%
1 / 3
17.30
0.00% covered (danger)
0.00%
0 / 1
 writeInfoHeader
65.38% covered (warning)
65.38%
17 / 26
0.00% covered (danger)
0.00%
0 / 1
14.15
 setDateTime
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
3.14
 getFormatedDates
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @package zmsstatistic
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsstatistic\Download;
9
10use Exception;
11use PhpOffice\PhpSpreadsheet\Spreadsheet;
12
13class Base extends \BO\Zmsstatistic\BaseController
14{
15    public static $ignoreColumns = [
16        'subjectid',
17        'scopeids',
18        'max',
19        'sum',
20        'ticketprinter',
21        'ticketprintermissed'
22    ];
23    public static $subjectTranslations = [
24        'waitingscope' => 'Wartesituation',
25        'waitingdepartment' => 'Wartesituation',
26        'waitingorganisation' => 'Wartesituation',
27        'clientscope' => 'Kundenstatistik',
28        'clientdepartment' => 'Kundenstatistik',
29        'clientorganisation' => 'Kundenstatistik',
30        'requestscope' => 'Dienstleistungsstatistik',
31        'requestdepartment' => 'Dienstleistungsstatistik',
32        'requestorganisation' => 'Dienstleistungsstatistik',
33        'raw-waitingscope' => 'Rohdaten Wartesituation',
34        'raw-waitingdepartment' => 'Rohdaten Wartesituation',
35        'raw-waitingorganisation' => 'Rohdaten Wartesituation',
36        'raw-clientscope' => 'Rohdaten Wartende',
37        'raw-clientdepartment' => 'Rohdaten Wartende',
38        'raw-clientorganisation' => 'Rohdaten Wartende',
39        'raw-requestscope' => 'Rohdaten Dienstleistungsstatistik',
40        'raw-requestdepartment' => 'Rohdaten Dienstleistungsstatistik',
41        'raw-requestorganisation' => 'Rohdaten Dienstleistungsstatistik'
42    ];
43
44    public static $headlines = [
45        'subjectid' => 'ID',
46        'scopeids' => 'Standort IDs',
47        'date' => 'Datum',
48        'clientscount' => 'Kunden Erschienen',
49        'missed' => 'Kunden Nicht Erschienen',
50        'withappointment' => 'davon Terminkunden Erschienen',
51        'missedwithappointment' => 'davon Terminkunden Nicht Erschienen',
52        'noappointment' => 'davon Spontankunden Erschienen',
53        'missednoappointment' => 'davon Spontankunden Nicht Erschienen',
54        'ticketprinter' => 'Erschienen (E-Kiosk)',
55        'ticketprintermissed' => 'Nicht Erschienen (E-Kiosk)',
56        'requestscount' => 'Dienstleistungen',
57        'organisationname' => 'Organisation',
58        'departmentname' => 'Behörde',
59        'scopename' => 'Standort'
60    ];
61
62    protected function writeInfoHeader(array $args, Spreadsheet $spreadsheet)
63    {
64        $sheet = $spreadsheet->getActiveSheet();
65        $infoData[] = static::$subjectTranslations[$args['category']];
66        if (isset($args['selectedScopes'])) {
67            try {
68                $scopesResult = \App::$http->readGetResult('/scope/')->getData();
69                $scopeMap = [];
70                foreach ($scopesResult as $scope) {
71                    $scopeMap[$scope->id] = $scope;
72                }
73                foreach ($args['selectedScopes'] as $scopeId) {
74                    if (isset($scopeMap[$scopeId])) {
75                        $infoData[] = $scopeMap[$scopeId]->provider->name . " " . $scopeMap[$scopeId]->shortName;
76                    }
77                }
78            } catch (Exception $exception) {
79                return null;
80            }
81        } else {
82            if (isset($args['organisation'])) {
83                $infoData[] = $args['organisation']['name'] ;
84            }
85            if (isset($args['department'])) {
86                $infoData[] = $args['department']['name'];
87            }
88            if (isset($args['scope'])) {
89                $infoData[] = $args['scope']['contact']['name'] . ' ' . $args['scope']['shortName'];
90            }
91        }
92
93        $infoData = array_chunk($infoData, 1);
94        $sheet->fromArray($infoData, null, 'A' . $sheet->getHighestRow());
95
96        if (isset($args['reports'][0]->firstDay)) {
97            $firstDay = $args['reports'][0]->firstDay->toDateTime()->format('d.m.Y');
98            $lastDay = $args['reports'][0]->lastDay->toDateTime()->format('d.m.Y');
99            $range = array('Zeitraum:', $firstDay, 'bis', $lastDay);
100            $sheet->fromArray($range, null, 'A' . ($sheet->getHighestRow() + 1));
101        }
102
103        return $spreadsheet;
104    }
105
106    protected function setDateTime($dateString)
107    {
108        $dateArr = explode('-', $dateString);
109        if (2 == count($dateArr)) {
110            $dateString = $dateString . '-01';
111        }
112        /* ignore because not in use now */
113        //@codeCoverageIgnoreStart
114        if (1 == count($dateArr)) {
115            $dateString = $dateString . '-01-01';
116        }
117        //@codeCoverageIgnoreEnd
118        return new \DateTime($dateString);
119    }
120
121    protected function getFormatedDates($date, $pattern = 'MMMM')
122    {
123        $dateFormatter = new \IntlDateFormatter(
124            'de-DE',
125            \IntlDateFormatter::MEDIUM,
126            \IntlDateFormatter::MEDIUM,
127            \App::TIMEZONE,
128            \IntlDateFormatter::GREGORIAN,
129            $pattern
130        );
131
132        return $dateFormatter->format($date->getTimestamp());
133    }
134}