Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Base
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
3 / 3
9
100.00% covered (success)
100.00%
1 / 1
 writeInfoHeader
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
5
 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 PhpOffice\PhpSpreadsheet\Spreadsheet;
11
12class Base extends \BO\Zmsstatistic\BaseController
13{
14    public static $ignoreColumns = [
15        'subjectid',
16        'scopeids',
17        'max',
18        'sum'
19    ];
20    public static $subjectTranslations = [
21        'waitingscope' => 'Wartesituation',
22        'waitingdepartment' => 'Wartesituation',
23        'waitingorganisation' => 'Wartesituation',
24        'notificationscope' => 'SMS Auswertung',
25        'notificationdepartment' => 'SMS Auswertung',
26        'notificationorganisation' => 'SMS Auswertung',
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-notificationscope' => 'Rohdaten SMS',
40        'raw-notificationdepartment' => 'Rohdaten SMS',
41        'raw-notificationorganisation' => 'Rohdaten SMS',
42        'raw-requestscope' => 'Rohdaten Dienstleistungsstatistik',
43        'raw-requestdepartment' => 'Rohdaten Dienstleistungsstatistik',
44        'raw-requestorganisation' => 'Rohdaten Dienstleistungsstatistik'
45    ];
46
47    public static $headlines = [
48        'subjectid' => 'ID',
49        'scopeids' => 'Standort IDs',
50        'date' => 'Datum',
51        'notificationscount' => 'SMS*',
52        'notificationscost' => 'SMS-Kosten**',
53        'clientscount' => 'Kunden Erschienen',
54        'missed' => 'Kunden Nicht Erschienen',
55        'withappointment' => 'davon Terminkunden Erschienen',
56        'missedwithappointment' => 'davon Terminkunden Nicht Erschienen',
57        'noappointment' => 'davon Spontankunden Erschienen',
58        'missednoappointment' => 'davon Spontankunden Nicht Erschienen',
59        'requestscount' => 'Dienstleistungen',
60        'organisationname' => 'Organisation',
61        'departmentname' => 'Behörde',
62        'scopename' => 'Standort'
63    ];
64
65    protected function writeInfoHeader(array $args, Spreadsheet $spreadsheet)
66    {
67        $sheet = $spreadsheet->getActiveSheet();
68        $infoData[] = static::$subjectTranslations[$args['category']];
69        if (isset($args['organisation'])) {
70            $infoData[] = $args['organisation']['name'] ;
71        }
72        if (isset($args['department'])) {
73            $infoData[] = $args['department']['name'];
74        }
75        if (isset($args['scope'])) {
76            $infoData[] = $args['scope']['contact']['name'] . ' ' . $args['scope']['shortName'];
77        }
78        $infoData = array_chunk($infoData, 1);
79        $sheet->fromArray($infoData, null, 'A' . $sheet->getHighestRow());
80
81        if (isset($args['reports'][0]->firstDay)) {
82            $firstDay = $args['reports'][0]->firstDay->toDateTime()->format('d.m.Y');
83            $lastDay = $args['reports'][0]->lastDay->toDateTime()->format('d.m.Y');
84            $range = array('Zeitraum:', $firstDay, 'bis', $lastDay);
85            $sheet->fromArray($range, null, 'A' . ($sheet->getHighestRow() + 1));
86        }
87
88        return $spreadsheet;
89    }
90
91    protected function setDateTime($dateString)
92    {
93        $dateArr = explode('-', $dateString);
94        if (2 == count($dateArr)) {
95            $dateString = $dateString . '-01';
96        }
97        /* ignore because not in use now */
98        //@codeCoverageIgnoreStart
99        if (1 == count($dateArr)) {
100            $dateString = $dateString . '-01-01';
101        }
102        //@codeCoverageIgnoreEnd
103        return new \DateTime($dateString);
104    }
105
106    protected function getFormatedDates($date, $pattern = 'MMMM')
107    {
108        $dateFormatter = new \IntlDateFormatter(
109            'de-DE',
110            \IntlDateFormatter::MEDIUM,
111            \IntlDateFormatter::MEDIUM,
112            \App::TIMEZONE,
113            \IntlDateFormatter::GREGORIAN,
114            $pattern
115        );
116
117        return $dateFormatter->format($date->getTimestamp());
118    }
119}