Lines
100.00%
85 / 85
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ExchangeClientscope | 100.00% | 85 / 85 | 100.00% | 3 / 3 | 17 | 100.00% | 1 / 1 | |||
| readEntity | 100.00% | 52 / 52 | 100.00% | 1 / 1 | 8 | |||||
| readSubjectList | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 2 | |||||
| readPeriodList | 100.00% | 22 / 22 | 100.00% | 1 / 1 | 7 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Exchange\Service; | |
| 4 | ||
| 5 | use BO\Zmsentities\Exchange; | |
| 6 | ||
| 7 | class ExchangeClientscope 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 | $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($subjectid); | |
| 22 | $entity = new Exchange(); | |
| 23 | $entity['title'] = "Kundenstatistik " . (($scope && $scope->contact) ? $scope->contact->name : 'Unknown') . " " . ($scope ? $scope->shortName : 'Unknown'); | |
| 24 | $entity->setPeriod($datestart, $dateend, $period); | |
| 25 | $entity->addDictionaryEntry('scopeids', 'array', 'Array of scope IDs that contributed data'); | |
| 26 | $entity->addDictionaryEntry('date', 'string', 'Date of entry'); | |
| 27 | $entity->addDictionaryEntry('clientscount', 'number', 'Amount of clients'); | |
| 28 | $entity->addDictionaryEntry('missed', 'number', 'Amount of missed clients'); | |
| 29 | $entity->addDictionaryEntry('withappointment', 'number', 'Amount of clients with an appointment'); | |
| 30 | $entity->addDictionaryEntry('missedwithappointment', 'number', 'Amount of missed clients with an appointment'); | |
| 31 | $entity->addDictionaryEntry('requestscount', 'number', 'Amount of requests'); | |
| 32 | $entity->addDictionaryEntry('ticketprinter', 'number', 'Amount of spontaneous clients via E-Kiosk (appeared)'); | |
| 33 | $entity->addDictionaryEntry('ticketprintermissed', 'number', 'Amount of spontaneous clients via E-Kiosk (missed)'); | |
| 34 | $subjectIdList = explode(',', $subjectid); | |
| 35 | $aggregatedData = []; | |
| 36 | ||
| 37 | $raw = $this->getReader()->fetchAll( | |
| 38 | constant("\BO\Zmsbackend\Exchange\Repository\ExchangeClientscope::QUERY_READ_REPORT"), | |
| 39 | [ | |
| 40 | 'scopeids' => $subjectIdList, | |
| 41 | 'datestart' => $datestart->format('Y-m-d'), | |
| 42 | 'dateend' => $dateend->format('Y-m-d'), | |
| 43 | 'groupby' => $this->groupBy[$period] | |
| 44 | ] | |
| 45 | ); | |
| 46 | ||
| 47 | foreach ($raw as $entry) { | |
| 48 | $date = $entry['date']; | |
| 49 | $scopeId = implode(',', $subjectIdList); | |
| 50 | ||
| 51 | if (!isset($aggregatedData[$date])) { | |
| 52 | $aggregatedData[$date] = [ | |
| 53 | 'scopeids' => [], | |
| 54 | 'date' => $date, | |
| 55 | 'clientscount' => 0, | |
| 56 | 'missed' => 0, | |
| 57 | 'withappointment' => 0, | |
| 58 | 'missedwithappointment' => 0, | |
| 59 | 'requestscount' => 0, | |
| 60 | 'ticketprinter' => 0, | |
| 61 | 'ticketprintermissed' => 0 | |
| 62 | ]; | |
| 63 | } | |
| 64 | ||
| 65 | $aggregatedData[$date]['clientscount'] += $entry['clientscount']; | |
| 66 | $aggregatedData[$date]['missed'] += $entry['missed']; | |
| 67 | $aggregatedData[$date]['withappointment'] += $entry['withappointment']; | |
| 68 | $aggregatedData[$date]['missedwithappointment'] += $entry['missedwithappointment']; | |
| 69 | $aggregatedData[$date]['requestscount'] += $entry['requestcount']; | |
| 70 | $aggregatedData[$date]['ticketprinter'] += $entry['ticketprinter'] ?? 0; | |
| 71 | $aggregatedData[$date]['ticketprintermissed'] += $entry['ticketprintermissed'] ?? 0; | |
| 72 | ||
| 73 | if (!in_array($scopeId, $aggregatedData[$date]['scopeids'])) { | |
| 74 | $aggregatedData[$date]['scopeids'][] = $scopeId; | |
| 75 | } | |
| 76 | } | |
| 77 | ||
| 78 | ksort($aggregatedData); | |
| 79 | foreach ($aggregatedData as $entry) { | |
| 80 | $entity->addDataSet(array_values($entry)); | |
| 81 | } | |
| 82 | return $entity; | |
| 83 | } | |
| 84 | ||
| 85 | public function readSubjectList(): Exchange | |
| 86 | { | |
| 87 | $raw = $this->getReader()->fetchAll(\BO\Zmsbackend\Exchange\Repository\ExchangeClientscope::QUERY_SUBJECTS, []); | |
| 88 | $entity = new Exchange(); | |
| 89 | $entity['title'] = "Kundenstatistik "; | |
| 90 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable()); | |
| 91 | $entity->addDictionaryEntry('subject', 'string', 'Standort ID', 'scope.id'); | |
| 92 | $entity->addDictionaryEntry('periodstart', 'string', 'Datum von'); | |
| 93 | $entity->addDictionaryEntry('periodend', 'string', 'Datum bis'); | |
| 94 | $entity->addDictionaryEntry('description', 'string', 'Beschreibung des Standortes'); | |
| 95 | foreach ($raw as $entry) { | |
| 96 | $entity->addDataSet(array_values($entry)); | |
| 97 | } | |
| 98 | return $entity; | |
| 99 | } | |
| 100 | ||
| 101 | public function readPeriodList($subjectid, $period = 'day'): Exchange | |
| 102 | { | |
| 103 | $scope = (new \BO\Zmsbackend\Scope\Service\Scope())->readEntity($subjectid); | |
| 104 | $entity = new Exchange(); | |
| 105 | $entity['title'] = "Kundenstatistik " . (($scope && $scope->contact) ? $scope->contact->name : 'Unknown') . " " . ($scope ? $scope->shortName : 'Unknown'); | |
| 106 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period); | |
| 107 | $entity->addDictionaryEntry('period'); | |
| 108 | ||
| 109 | $montsList = $this->getReader()->fetchAll( | |
| 110 | constant("\BO\Zmsbackend\Exchange\Repository\ExchangeClientscope::QUERY_PERIODLIST_MONTH"), | |
| 111 | [ | |
| 112 | 'scopeid' => $subjectid, | |
| 113 | ] | |
| 114 | ); | |
| 115 | $raw = []; | |
| 116 | foreach ($montsList as $month) { | |
| 117 | $date = new \DateTimeImmutable($month['date']); | |
| 118 | $raw[$date->format('Y')][] = $month['date']; | |
| 119 | rsort($raw[$date->format('Y')]); | |
| 120 | } | |
| 121 | krsort($raw); | |
| 122 | ||
| 123 | foreach ($raw as $year => $months) { | |
| 124 | $entity->addDataSet([$year]); | |
| 125 | foreach ($months as $month) { | |
| 126 | $entity->addDataSet([$month]); | |
| 127 | } | |
| 128 | } | |
| 129 | return $entity; | |
| 130 | } | |
| 131 | } |