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