Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
65 / 65
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ExchangeClientscope
100.00% covered (success)
100.00%
65 / 65
100.00% covered (success)
100.00%
3 / 3
9
100.00% covered (success)
100.00%
1 / 1
 readEntity
100.00% covered (success)
100.00%
32 / 32
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 ExchangeClientscope 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        $config = (new Config())->readEntity();
22        $costs = $config->getNotificationPreferences()['costs'];
23
24        $scope = (new Scope())->readEntity($subjectid);
25        $entity = new Exchange();
26        $entity['title'] = "Kundenstatistik " . $scope->contact->name . " " . $scope->shortName;
27        $entity->setPeriod($datestart, $dateend, $period);
28        $entity->addDictionaryEntry('subjectid', 'string', 'ID of a scope', 'scope.id');
29        $entity->addDictionaryEntry('date', 'string', 'Date of entry');
30        $entity->addDictionaryEntry('notificationscount', 'number', 'Amount of notifications sent');
31        $entity->addDictionaryEntry('notificationscost', 'string', 'Costs of notifications');
32        $entity->addDictionaryEntry('clientscount', 'number', 'Amount of clients');
33        $entity->addDictionaryEntry('missed', 'number', 'Amount of missed clients');
34        $entity->addDictionaryEntry('withappointment', 'number', 'Amount of clients with an appointment');
35        $entity->addDictionaryEntry('missedwithappointment', 'number', 'Amount of missed clients with an appointment');
36        $entity->addDictionaryEntry('requestscount', 'number', 'Amount of requests');
37        $subjectIdList = explode(',', $subjectid);
38
39        foreach ($subjectIdList as $subjectid) {
40            $raw = $this
41                ->getReader()
42                ->fetchAll(
43                    constant("\BO\Zmsdb\Query\ExchangeClientscope::QUERY_READ_REPORT"),
44                    [
45                        'scopeid' => $subjectid,
46                        'datestart' => $datestart->format('Y-m-d'),
47                        'dateend' => $dateend->format('Y-m-d'),
48                        'groupby' => $this->groupBy[$period]
49                    ]
50                );
51            foreach ($raw as $entry) {
52                $entry['notificationscost'] = $entry['notificationscount'] * $costs;
53                $entity->addDataSet(array_values($entry));
54            }
55        }
56        return $entity;
57    }
58
59    public function readSubjectList()
60    {
61        $raw = $this->getReader()->fetchAll(Query\ExchangeClientscope::QUERY_SUBJECTS, []);
62        $entity = new Exchange();
63        $entity['title'] = "Kundenstatistik ";
64        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable());
65        $entity->addDictionaryEntry('subject', 'string', 'Standort ID', 'scope.id');
66        $entity->addDictionaryEntry('periodstart', 'string', 'Datum von');
67        $entity->addDictionaryEntry('periodend', 'string', 'Datum bis');
68        $entity->addDictionaryEntry('description', 'string', 'Beschreibung des Standortes');
69        foreach ($raw as $entry) {
70            $entity->addDataSet(array_values($entry));
71        }
72        return $entity;
73    }
74
75    public function readPeriodList($subjectid, $period = 'day')
76    {
77        $scope = (new Scope())->readEntity($subjectid);
78        $entity = new Exchange();
79        $entity['title'] = "Kundenstatistik " . $scope->contact->name . " " . $scope->shortName;
80        $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period);
81        $entity->addDictionaryEntry('period');
82
83        $montsList = $this->getReader()->fetchAll(
84            constant("\BO\Zmsdb\Query\ExchangeClientscope::QUERY_PERIODLIST_MONTH"),
85            [
86                'scopeid' => $subjectid,
87            ]
88        );
89        $raw = [];
90        foreach ($montsList as $month) {
91            $date = new \DateTimeImmutable($month['date']);
92            $raw[$date->format('Y')][] = $month['date'];
93            rsort($raw[$date->format('Y')]);
94        }
95        krsort($raw);
96
97        foreach ($raw as $year => $months) {
98            $entity->addDataSet([$year]);
99            foreach ($months as $month) {
100                $entity->addDataSet([$month]);
101            }
102        }
103        return $entity;
104    }
105}