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