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