Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
79 / 79
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ExchangeWaitingdepartment
100.00% covered (success)
100.00%
79 / 79
100.00% covered (success)
100.00%
3 / 3
10
100.00% covered (success)
100.00%
1 / 1
 readEntity
100.00% covered (success)
100.00%
44 / 44
100.00% covered (success)
100.00%
1 / 1
4
 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\Zmsbackend\Exchange\Service;
4
5use BO\Zmsentities\Exchange;
6
7class ExchangeWaitingdepartment extends \BO\Zmsbackend\Base implements \BO\Zmsbackend\Interfaces\ExchangeSubject
8{
9    /**
10     * @return Exchange
11     */
12    #[\Override]
13    public function readEntity(
14        $subjectid,
15        \DateTimeInterface $datestart,
16        \DateTimeInterface $dateend,
17        $period = 'day'
18    ) {
19        $department = (new \BO\Zmsbackend\Department\Service\Department())->readEntity($subjectid);
20        $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByDepartmentId($subjectid);
21        $entity = new Exchange();
22        $entity['title'] = "Wartestatistik $organisation->name -> $department->name";
23        $entity->setPeriod($datestart, $dateend, $period);
24        $entity->addDictionaryEntry('subjectid', 'string', 'ID of a department', 'department.id');
25        $entity->addDictionaryEntry('date', 'string', 'date of report entry');
26        $entity->addDictionaryEntry('hour', 'string', 'hour of report entry');
27        $entity->addDictionaryEntry('waitingcount', 'number', 'amount of waiting spontaneous clients');
28        $entity->addDictionaryEntry('waitingtime', 'number', 'real waitingtime for spontaneous clients');
29        $entity->addDictionaryEntry('waytime', 'number', 'real waytime for spontaneous clients');
30        $entity->addDictionaryEntry('waitingcalculated', 'number', 'calculated waitingtime for spontaneous clients');
31        $entity->addDictionaryEntry('waitingcount_termin', 'number', 'amount of waiting clients with termin');
32        $entity->addDictionaryEntry('waitingtime_termin', 'number', 'real waitingtime with termin');
33        $entity->addDictionaryEntry('waytime_termin', 'number', 'real waytime with appointment');
34        $entity->addDictionaryEntry('waitingcalculated_termin', 'number', 'calculated waitingtime with termin');
35        $subjectIdList = explode(',', $subjectid);
36        foreach ($subjectIdList as $subjectid) {
37            $raw = $this
38                ->getReader()
39                ->fetchAll(
40                    constant("\BO\Zmsbackend\Exchange\Repository\ExchangeWaitingdepartment::QUERY_READ_" . strtoupper($period)),
41                    [
42                        'departmentid' => $subjectid,
43                        'datestart' => $datestart->format('Y-m-d'),
44                        'dateend' => $dateend->format('Y-m-d'),
45                    ]
46                );
47
48            foreach ($raw as $entry) {
49                foreach (range(0, 23) as $hour) {
50                    $entity->addDataSet([
51                        $subjectid,
52                        $entry['datum'],
53                        $hour,
54                        $entry[sprintf('hour_%02d_waiting_count_spontaneous', $hour)],
55                        $entry[sprintf('hour_%02d_waiting_time_spontaneous', $hour)],
56                        $entry[sprintf('hour_%02d_way_time_spontaneous', $hour)],
57                        $entry[sprintf('hour_%02d_estimated_waiting_time_spontaneous', $hour)],
58                        $entry[sprintf('hour_%02d_waiting_count_appointment', $hour)],
59                        $entry[sprintf('hour_%02d_waiting_time_appointment', $hour)],
60                        $entry[sprintf('hour_%02d_way_time_appointment', $hour)],
61                        $entry[sprintf('hour_%02d_estimated_waiting_time_appointment', $hour)],
62                    ]);
63                }
64            }
65        }
66        return $entity;
67    }
68
69    /**
70     * @return Exchange
71     */
72    #[\Override]
73    public function readSubjectList()
74    {
75        $raw = $this->getReader()->fetchAll(\BO\Zmsbackend\Exchange\Repository\ExchangeWaitingdepartment::QUERY_SUBJECTS, []);
76        $entity = new Exchange();
77        $entity['title'] = "Wartestatistik";
78        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable());
79        $entity->addDictionaryEntry('subject', 'string', 'Behörde ID', 'department.id');
80        $entity->addDictionaryEntry('periodstart', 'string', 'Datum von');
81        $entity->addDictionaryEntry('periodend', 'string', 'Datum bis');
82        $entity->addDictionaryEntry('organisationname', 'string', 'Name der Organisation');
83        $entity->addDictionaryEntry('description', 'string', 'Name der Behörde');
84        foreach ($raw as $entry) {
85            $entity->addDataSet(array_values($entry));
86        }
87        return $entity;
88    }
89
90    /**
91     * @return Exchange
92     */
93    #[\Override]
94    public function readPeriodList($subjectid, $period = 'day')
95    {
96        $department = (new \BO\Zmsbackend\Department\Service\Department())->readEntity($subjectid);
97        $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByDepartmentId($subjectid);
98        $entity = new Exchange();
99        $entity['title'] = "Wartestatistik $organisation->name -> $department->name";
100        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period);
101        $entity->addDictionaryEntry('period');
102
103        $montsList = $this->getReader()->fetchAll(
104            constant("\BO\Zmsbackend\Exchange\Repository\ExchangeWaitingdepartment::QUERY_PERIODLIST_MONTH"),
105            [
106                'departmentid' => $subjectid,
107            ]
108        );
109        $raw = [];
110        foreach ($montsList as $month) {
111            $date = new \DateTimeImmutable($month['date']);
112            $raw[$date->format('Y')][] = $month['date'];
113            rsort($raw[$date->format('Y')]);
114        }
115        krsort($raw);
116
117        foreach ($raw as $year => $months) {
118            $entity->addDataSet([$year]);
119            foreach ($months as $month) {
120                $entity->addDataSet([$month]);
121            }
122        }
123        return $entity;
124    }
125}