Lines
100.00%
59 / 59
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ExchangeClientowner | 100.00% | 59 / 59 | 100.00% | 3 / 3 | 9 | 100.00% | 1 / 1 | |||
| readEntity | 100.00% | 27 / 27 | 100.00% | 1 / 1 | 3 | |||||
| readSubjectList | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 2 | |||||
| readPeriodList | 100.00% | 22 / 22 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Exchange\Service; | |
| 4 | ||
| 5 | use BO\Zmsentities\Exchange; | |
| 6 | ||
| 7 | class ExchangeClientowner 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 | $owner = (new \BO\Zmsbackend\Owner\Service\Owner())->readEntity($subjectid); | |
| 22 | $entity = new Exchange(); | |
| 23 | $entity['title'] = "Kundenstatistik $owner->name"; | |
| 24 | $entity->setPeriod($datestart, $dateend, $period); | |
| 25 | $entity->addDictionaryEntry('subjectid', 'string', 'ID of a owner', 'owner.id'); | |
| 26 | $entity->addDictionaryEntry('date'); | |
| 27 | $entity->addDictionaryEntry('clientscount'); | |
| 28 | $entity->addDictionaryEntry('missed'); | |
| 29 | $entity->addDictionaryEntry('withappointment'); | |
| 30 | $entity->addDictionaryEntry('missedwithappointment'); | |
| 31 | $entity->addDictionaryEntry('requestscount'); | |
| 32 | $subjectIdList = explode(',', $subjectid); | |
| 33 | ||
| 34 | foreach ($subjectIdList as $subjectid) { | |
| 35 | $raw = $this | |
| 36 | ->getReader() | |
| 37 | ->fetchAll( | |
| 38 | constant("\BO\Zmsbackend\Exchange\Repository\ExchangeClientowner::QUERY_READ_REPORT"), | |
| 39 | [ | |
| 40 | 'ownerid' => $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\ExchangeClientowner::QUERY_SUBJECTS, []); | |
| 56 | $entity = new Exchange(); | |
| 57 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable()); | |
| 58 | $entity->addDictionaryEntry('subject', 'string', 'Owner ID', 'owner.id'); | |
| 59 | $entity->addDictionaryEntry('periodstart', 'string', 'Datum von'); | |
| 60 | $entity->addDictionaryEntry('periodend', 'string', 'Datum bis'); | |
| 61 | $entity->addDictionaryEntry('description', 'string', 'Name des Besitzers'); | |
| 62 | foreach ($raw as $entry) { | |
| 63 | $entity->addDataSet(array_values($entry)); | |
| 64 | } | |
| 65 | return $entity; | |
| 66 | } | |
| 67 | ||
| 68 | public function readPeriodList($subjectid, $period = 'day'): Exchange | |
| 69 | { | |
| 70 | $owner = (new \BO\Zmsbackend\Owner\Service\Owner())->readEntity($subjectid); | |
| 71 | $entity = new Exchange(); | |
| 72 | $entity['title'] = "Kundenstatistik $owner->name"; | |
| 73 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period); | |
| 74 | $entity->addDictionaryEntry('period'); | |
| 75 | ||
| 76 | $montsList = $this->getReader()->fetchAll( | |
| 77 | constant("\BO\Zmsbackend\Exchange\Repository\ExchangeClientowner::QUERY_PERIODLIST_MONTH"), | |
| 78 | [ | |
| 79 | 'ownerid' => $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 | } |