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