Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
60 / 60
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ExchangeNotificationowner
100.00% covered (success)
100.00%
60 / 60
100.00% covered (success)
100.00%
3 / 3
9
100.00% covered (success)
100.00%
1 / 1
 readEntity
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
1 / 1
3
 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\Zmsdb;
4
5use BO\Zmsentities\Exchange;
6
7class ExchangeNotificationowner 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        $owner = (new Owner())->readEntity($subjectid);
22        $entity = new Exchange();
23        $entity['title'] = "SMS-Statistik $owner->name";
24        $entity->setPeriod($datestart, $dateend, $period);
25        $entity->addDictionaryEntry('subjectid', 'string', 'ID of the owner', 'owner.id');
26        $entity->addDictionaryEntry('date', 'string', 'Date of entry');
27        $entity->addDictionaryEntry('ownername', 'string', 'name of the owner');
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\ExchangeNotificationowner::QUERY_READ_REPORT"),
39                    [
40                        'ownerid' => $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\ExchangeNotificationowner::QUERY_SUBJECTS, []);
56        $entity = new Exchange();
57        $entity['title'] = "SMS-Statistik";
58        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable());
59        $entity->addDictionaryEntry('subject', 'string', 'Owner ID', 'owner.id');
60        $entity->addDictionaryEntry('periodstart', 'string', 'Datum von');
61        $entity->addDictionaryEntry('periodend', 'string', 'Datum bis');
62        $entity->addDictionaryEntry('description', 'string', 'Name des Eigentümers');
63        foreach ($raw as $entry) {
64            $entity->addDataSet(array_values($entry));
65        }
66        return $entity;
67    }
68
69    public function readPeriodList($subjectid, $period = 'day')
70    {
71        $owner = (new Owner())->readEntity($subjectid);
72        $entity = new Exchange();
73        $entity['title'] = "SMS-Statistik $owner->name";
74        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period);
75        $entity->addDictionaryEntry('period');
76
77        $montsList = $this->getReader()->fetchAll(
78            constant("\BO\Zmsdb\Query\ExchangeNotificationowner::QUERY_PERIODLIST_MONTH"),
79            [
80                'ownerid' => $subjectid,
81            ]
82        );
83        $raw = [];
84        foreach ($montsList as $month) {
85            $date = new \DateTimeImmutable($month['date']);
86            $raw[$date->format('Y')][] = $month['date'];
87            rsort($raw[$date->format('Y')]);
88        }
89        krsort($raw);
90
91        foreach ($raw as $year => $months) {
92            $entity->addDataSet([$year]);
93            foreach ($months as $month) {
94                $entity->addDataSet([$month]);
95            }
96        }
97        return $entity;
98    }
99}