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