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