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