Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.92% covered (warning)
76.92%
30 / 39
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Base
76.92% covered (warning)
76.92%
30 / 39
66.67% covered (warning)
66.67%
2 / 3
16.41
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
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 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        'notificationscope' => 'SMS Auswertung',
28        'notificationdepartment' => 'SMS Auswertung',
29        'notificationorganisation' => 'SMS Auswertung',
30        'clientscope' => 'Kundenstatistik',
31        'clientdepartment' => 'Kundenstatistik',
32        'clientorganisation' => 'Kundenstatistik',
33        'requestscope' => 'Dienstleistungsstatistik',
34        'requestdepartment' => 'Dienstleistungsstatistik',
35        'requestorganisation' => 'Dienstleistungsstatistik',
36        'raw-waitingscope' => 'Rohdaten Wartesituation',
37        'raw-waitingdepartment' => 'Rohdaten Wartesituation',
38        'raw-waitingorganisation' => 'Rohdaten Wartesituation',
39        'raw-clientscope' => 'Rohdaten Wartende',
40        'raw-clientdepartment' => 'Rohdaten Wartende',
41        'raw-clientorganisation' => 'Rohdaten Wartende',
42        'raw-notificationscope' => 'Rohdaten SMS',
43        'raw-notificationdepartment' => 'Rohdaten SMS',
44        'raw-notificationorganisation' => 'Rohdaten SMS',
45        'raw-requestscope' => 'Rohdaten Dienstleistungsstatistik',
46        'raw-requestdepartment' => 'Rohdaten Dienstleistungsstatistik',
47        'raw-requestorganisation' => 'Rohdaten Dienstleistungsstatistik'
48    ];
49
50    public static $headlines = [
51        'subjectid' => 'ID',
52        'scopeids' => 'Standort IDs',
53        'date' => 'Datum',
54        'notificationscount' => 'SMS*',
55        'notificationscost' => 'SMS-Kosten**',
56        'clientscount' => 'Kunden Erschienen',
57        'missed' => 'Kunden Nicht Erschienen',
58        'withappointment' => 'davon Terminkunden Erschienen',
59        'missedwithappointment' => 'davon Terminkunden Nicht Erschienen',
60        'noappointment' => 'davon Spontankunden Erschienen',
61        'missednoappointment' => 'davon Spontankunden Nicht Erschienen',
62        'ticketprinter' => 'Erschienen (E-Kiosk)',
63        'ticketprintermissed' => 'Nicht Erschienen (E-Kiosk)',
64        'requestscount' => 'Dienstleistungen',
65        'organisationname' => 'Organisation',
66        'departmentname' => 'Behörde',
67        'scopename' => 'Standort'
68    ];
69
70    protected function writeInfoHeader(array $args, Spreadsheet $spreadsheet)
71    {
72        $sheet = $spreadsheet->getActiveSheet();
73        $infoData[] = static::$subjectTranslations[$args['category']];
74        if (isset($args['selectedScopes'])) {
75            try {
76                $scopesResult = \App::$http->readGetResult('/scope/')->getData();
77                $scopeMap = [];
78                foreach ($scopesResult as $scope) {
79                    $scopeMap[$scope->id] = $scope;
80                }
81                foreach ($args['selectedScopes'] as $scopeId) {
82                    if (isset($scopeMap[$scopeId])) {
83                        $infoData[] = $scopeMap[$scopeId]->provider->name . " " . $scopeMap[$scopeId]->shortName;
84                    }
85                }
86            } catch (Exception $exception) {
87                return null;
88            }
89        } else {
90            if (isset($args['organisation'])) {
91                $infoData[] = $args['organisation']['name'] ;
92            }
93            if (isset($args['department'])) {
94                $infoData[] = $args['department']['name'];
95            }
96            if (isset($args['scope'])) {
97                $infoData[] = $args['scope']['contact']['name'] . ' ' . $args['scope']['shortName'];
98            }
99        }
100
101        $infoData = array_chunk($infoData, 1);
102        $sheet->fromArray($infoData, null, 'A' . $sheet->getHighestRow());
103
104        if (isset($args['reports'][0]->firstDay)) {
105            $firstDay = $args['reports'][0]->firstDay->toDateTime()->format('d.m.Y');
106            $lastDay = $args['reports'][0]->lastDay->toDateTime()->format('d.m.Y');
107            $range = array('Zeitraum:', $firstDay, 'bis', $lastDay);
108            $sheet->fromArray($range, null, 'A' . ($sheet->getHighestRow() + 1));
109        }
110
111        return $spreadsheet;
112    }
113
114    protected function setDateTime($dateString)
115    {
116        $dateArr = explode('-', $dateString);
117        if (2 == count($dateArr)) {
118            $dateString = $dateString . '-01';
119        }
120        /* ignore because not in use now */
121        //@codeCoverageIgnoreStart
122        if (1 == count($dateArr)) {
123            $dateString = $dateString . '-01-01';
124        }
125        //@codeCoverageIgnoreEnd
126        return new \DateTime($dateString);
127    }
128
129    protected function getFormatedDates($date, $pattern = 'MMMM')
130    {
131        $dateFormatter = new \IntlDateFormatter(
132            'de-DE',
133            \IntlDateFormatter::MEDIUM,
134            \IntlDateFormatter::MEDIUM,
135            \App::TIMEZONE,
136            \IntlDateFormatter::GREGORIAN,
137            $pattern
138        );
139
140        return $dateFormatter->format($date->getTimestamp());
141    }
142}