Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
68 / 68
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ExchangeClientdepartment
100.00% covered (success)
100.00%
68 / 68
100.00% covered (success)
100.00%
3 / 3
9
100.00% covered (success)
100.00%
1 / 1
 readEntity
100.00% covered (success)
100.00%
33 / 33
100.00% covered (success)
100.00%
1 / 1
3
 readSubjectList
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
2
 readPeriodList
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace BO\Zmsdb;
4
5use BO\Zmsentities\Exchange;
6
7class ExchangeClientdepartment extends Base
8{
9    protected $groupBy = array(
10        'month' => '%Y-%m',
11        'day' => '%Y-%m-%d',
12        'hour' => '%H-%i'
13    );
14
15    public function readEntity(
16        $subjectid,
17        \DateTimeInterface $datestart,
18        \DateTimeInterface $dateend,
19        $period = 'day'
20    ) {
21        $config = (new Config())->readEntity();
22        $costs = $config->getNotificationPreferences()['costs'];
23
24        $department = (new Department())->readEntity($subjectid);
25        $organisation = (new Organisation())->readByDepartmentId($subjectid);
26        $entity = new Exchange();
27        $entity['title'] = "Kundenstatistik $organisation->name -> $department->name";
28        $entity->setPeriod($datestart, $dateend, $period);
29        $entity->addDictionaryEntry('subjectid', 'string', 'ID of a department', 'department.id');
30        $entity->addDictionaryEntry('date');
31        $entity->addDictionaryEntry('notificationscount');
32        $entity->addDictionaryEntry('notificationscost');
33        $entity->addDictionaryEntry('clientscount');
34        $entity->addDictionaryEntry('missed');
35        $entity->addDictionaryEntry('withappointment');
36        $entity->addDictionaryEntry('missedwithappointment');
37        $entity->addDictionaryEntry('requestscount');
38        $subjectIdList = explode(',', $subjectid);
39
40        foreach ($subjectIdList as $subjectid) {
41            $raw = $this
42                ->getReader()
43                ->fetchAll(
44                    constant("\BO\Zmsdb\Query\ExchangeClientdepartment::QUERY_READ_REPORT"),
45                    [
46                        'departmentid' => $subjectid,
47                        'datestart' => $datestart->format('Y-m-d'),
48                        'dateend' => $dateend->format('Y-m-d'),
49                        'groupby' => $this->groupBy[$period]
50                    ]
51                );
52            foreach ($raw as $entry) {
53                $entry['notificationscost'] = $entry['notificationscount'] * $costs;
54                $entity->addDataSet(array_values($entry));
55            }
56        }
57        return $entity;
58    }
59
60    public function readSubjectList()
61    {
62        $raw = $this->getReader()->fetchAll(Query\ExchangeClientdepartment::QUERY_SUBJECTS, []);
63        $entity = new Exchange();
64        $entity['title'] = "Kundenstatistik";
65        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable());
66        $entity->addDictionaryEntry('subject', 'string', 'Behörden ID', 'department.id');
67        $entity->addDictionaryEntry('periodstart', 'string', 'Datum von');
68        $entity->addDictionaryEntry('periodend', 'string', 'Datum bis');
69        $entity->addDictionaryEntry('organisationname', 'string', 'Name der Organisation');
70        $entity->addDictionaryEntry('description', 'string', 'Name der Behörde');
71        foreach ($raw as $entry) {
72            $entity->addDataSet(array_values($entry));
73        }
74        return $entity;
75    }
76
77    public function readPeriodList($subjectid, $period = 'day')
78    {
79        $department = (new Department())->readEntity($subjectid);
80        $organisation = (new Organisation())->readByDepartmentId($subjectid);
81        $entity = new Exchange();
82        $entity['title'] = "Kundenstatistik $organisation->name -> $department->name";
83        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period);
84        $entity->addDictionaryEntry('period');
85
86        $montsList = $this->getReader()->fetchAll(
87            constant("\BO\Zmsdb\Query\ExchangeClientdepartment::QUERY_PERIODLIST_MONTH"),
88            [
89                'departmentid' => $subjectid,
90            ]
91        );
92        $raw = [];
93        foreach ($montsList as $month) {
94            $date = new \DateTimeImmutable($month['date']);
95            $raw[$date->format('Y')][] = $month['date'];
96            rsort($raw[$date->format('Y')]);
97        }
98        krsort($raw);
99
100        foreach ($raw as $year => $months) {
101            $entity->addDataSet([$year]);
102            foreach ($months as $month) {
103                $entity->addDataSet([$month]);
104            }
105        }
106        return $entity;
107    }
108}