Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.48% |
57 / 63 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ExchangeCapacityscope | |
90.48% |
57 / 63 |
|
50.00% |
2 / 4 |
14.17 | |
0.00% |
0 / 1 |
| readEntity | |
90.00% |
36 / 40 |
|
0.00% |
0 / 1 |
8.06 | |||
| resolveMetricsQuery | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
3.58 | |||
| readSubjectList | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 | |||
| readPeriodList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb; |
| 4 | |
| 5 | use BO\Zmsdb\Query\ExchangeCapacityscope as ExchangeCapacityscopeQuery; |
| 6 | use BO\Zmsentities\Exchange; |
| 7 | |
| 8 | class ExchangeCapacityscope extends Base |
| 9 | { |
| 10 | public function readEntity( |
| 11 | $subjectid, |
| 12 | \DateTimeInterface $datestart = null, |
| 13 | \DateTimeInterface $dateend = null, |
| 14 | $period = 'day' |
| 15 | ): Exchange { |
| 16 | if (trim((string) $subjectid) === '') { |
| 17 | throw new \InvalidArgumentException('Subject ID cannot be empty'); |
| 18 | } |
| 19 | |
| 20 | $subjectIdList = explode(',', $subjectid); |
| 21 | $firstScopeId = $subjectIdList[0]; |
| 22 | $scope = (new Scope())->readEntity($firstScopeId); |
| 23 | $entity = new Exchange(); |
| 24 | $entity['title'] = "Terminkapazität " . $scope->contact->name . " " . $scope->shortName; |
| 25 | |
| 26 | $unfiltered = $datestart === null || $dateend === null; |
| 27 | if ($unfiltered) { |
| 28 | $datestart = new \DateTimeImmutable('1970-01-01'); |
| 29 | $dateend = new \DateTimeImmutable('2099-12-31'); |
| 30 | $period = 'day'; |
| 31 | } else { |
| 32 | $entity->setPeriod($datestart, $dateend, $period); |
| 33 | } |
| 34 | |
| 35 | $entity->addDictionaryEntry('subjectid', 'string', 'Standort-ID', 'scope.id'); |
| 36 | $dateDescription = $period === 'hour' ? 'Zeitpunkt' : 'Datum'; |
| 37 | $entity->addDictionaryEntry('date', 'string', $dateDescription); |
| 38 | $entity->addDictionaryEntry('bookedcount', 'number', 'Gebuchte Kapazität insgesamt (Zeitschlitze)'); |
| 39 | $entity->addDictionaryEntry('plannedcount', 'number', 'Geplante Kapazität insgesamt (Zeitschlitze)'); |
| 40 | $entity->addDictionaryEntry('bookedminutes', 'number', 'Gebuchte Kapazität insgesamt (Minuten)'); |
| 41 | $entity->addDictionaryEntry('plannedminutes', 'number', 'Geplante Kapazität insgesamt (Minuten)'); |
| 42 | $entity->addDictionaryEntry('bookedcount_public', 'number', 'Gebuchte Kapazität Internet (Zeitschlitze)'); |
| 43 | $entity->addDictionaryEntry('plannedcount_public', 'number', 'Geplante Kapazität Internet (Zeitschlitze)'); |
| 44 | $entity->addDictionaryEntry('bookedminutes_public', 'number', 'Gebuchte Kapazität Internet (Minuten)'); |
| 45 | $entity->addDictionaryEntry('plannedminutes_public', 'number', 'Geplante Kapazität Internet (Minuten)'); |
| 46 | |
| 47 | $entity['visualization']['xlabel'] = ["date"]; |
| 48 | $entity['visualization']['ylabel'] = ["bookedcount", "plannedcount"]; |
| 49 | $entity['visualization']['ylabelMinutes'] = ["bookedminutes", "plannedminutes"]; |
| 50 | $entity['visualization']['ylabelPublic'] = ["bookedcount_public", "plannedcount_public"]; |
| 51 | $entity['visualization']['ylabelMinutesPublic'] = ["bookedminutes_public", "plannedminutes_public"]; |
| 52 | $entity['visualization']['allowCapacityChannel'] = true; |
| 53 | |
| 54 | $query = $this->resolveMetricsQuery($period, $unfiltered); |
| 55 | |
| 56 | foreach ($subjectIdList as $scopeId) { |
| 57 | $parameters = ['scopeid' => $scopeId]; |
| 58 | if (!$unfiltered) { |
| 59 | $parameters['datestart'] = $datestart->format('Y-m-d'); |
| 60 | $parameters['dateend'] = $dateend->format('Y-m-d'); |
| 61 | } |
| 62 | |
| 63 | $raw = $this->fetchAll($query, $parameters); |
| 64 | foreach ($raw as $entry) { |
| 65 | $entity->addDataSet(array_values($entry)); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return $entity; |
| 70 | } |
| 71 | |
| 72 | private function resolveMetricsQuery(string $period, bool $unfiltered): string |
| 73 | { |
| 74 | if ($unfiltered) { |
| 75 | return ExchangeCapacityscopeQuery::QUERY_CAPACITY_METRICS_BY_DAY_ALL_DATES; |
| 76 | } |
| 77 | |
| 78 | if ($period === 'hour') { |
| 79 | return ExchangeCapacityscopeQuery::QUERY_CAPACITY_METRICS_BY_HOUR_IN_DATE_RANGE; |
| 80 | } |
| 81 | |
| 82 | return ExchangeCapacityscopeQuery::QUERY_CAPACITY_METRICS_BY_DAY_IN_DATE_RANGE; |
| 83 | } |
| 84 | |
| 85 | public function readSubjectList(): Exchange |
| 86 | { |
| 87 | $raw = $this->getReader()->fetchAll( |
| 88 | ExchangeCapacityscopeQuery::QUERY_CAPACITY_REPORT_SCOPE_SUBJECT_LIST, |
| 89 | [] |
| 90 | ); |
| 91 | $entity = new Exchange(); |
| 92 | $entity['title'] = "Terminkapazität "; |
| 93 | $entity->addDictionaryEntry('subject', 'string', 'Standort ID', 'scope.id'); |
| 94 | $entity->addDictionaryEntry('periodstart', 'string', 'Datum von'); |
| 95 | $entity->addDictionaryEntry('periodend', 'string', 'Datum bis'); |
| 96 | $entity->addDictionaryEntry('description', 'string', 'Beschreibung des Standortes'); |
| 97 | foreach ($raw as $entry) { |
| 98 | $entity->addDataSet(array_values($entry)); |
| 99 | } |
| 100 | |
| 101 | return $entity; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Aggregate period placeholder required by ExchangeSubject interface. |
| 106 | * |
| 107 | * @SuppressWarnings(Unused) |
| 108 | */ |
| 109 | public function readPeriodList($subjectid, $period = 'day'): Exchange |
| 110 | { |
| 111 | $entity = new Exchange(); |
| 112 | $entity['title'] = "Terminkapazität "; |
| 113 | $entity->addDictionaryEntry('id', 'string', 'Gesamter Zeitraum', 'useraccount.rights.superuser'); |
| 114 | $entity->addDataSet(["_"]); |
| 115 | |
| 116 | return $entity; |
| 117 | } |
| 118 | } |