Lines
100.00%
62 / 62
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ExchangeRequestdepartment | 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\Zmsbackend\Exchange\Service; | |
| 4 | ||
| 5 | use BO\Zmsentities\Exchange; | |
| 6 | ||
| 7 | class ExchangeRequestdepartment extends \BO\Zmsbackend\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 | ): Exchange { | |
| 21 | $department = (new \BO\Zmsbackend\Department\Service\Department())->readEntity($subjectid); | |
| 22 | $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByDepartmentId($subjectid); | |
| 23 | $entity = new Exchange(); | |
| 24 | $entity['title'] = "Dienstleistungsstatistik $organisation->name -> $department->name"; | |
| 25 | $entity->setPeriod($datestart, $dateend, $period); | |
| 26 | $entity->addDictionaryEntry('departmentid', 'string', 'ID of a department', 'department.id'); | |
| 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 | foreach ($subjectIdList as $subjectid) { | |
| 35 | $raw = $this | |
| 36 | ->getReader() | |
| 37 | ->fetchAll( | |
| 38 | constant("\BO\Zmsbackend\Exchange\Repository\ExchangeRequestdepartment::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(): Exchange | |
| 54 | { | |
| 55 | $raw = $this->getReader()->fetchAll(\BO\Zmsbackend\Exchange\Repository\ExchangeRequestdepartment::QUERY_SUBJECTS, []); | |
| 56 | $entity = new Exchange(); | |
| 57 | $entity['title'] = "Dienstleistungsstatistik"; | |
| 58 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable()); | |
| 59 | $entity->addDictionaryEntry('subject', 'string', 'Behoerden 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', 'Beschreibung 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'): Exchange | |
| 71 | { | |
| 72 | $department = (new \BO\Zmsbackend\Department\Service\Department())->readEntity($subjectid); | |
| 73 | $organisation = (new \BO\Zmsbackend\Organisation\Service\Organisation())->readByDepartmentId($subjectid); | |
| 74 | $entity = new Exchange(); | |
| 75 | $entity['title'] = "Dienstleistungsstatistik $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\Zmsbackend\Exchange\Repository\ExchangeRequestdepartment::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 | } |