Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       100.00%  | 
       64 / 64  | 
               | 
       100.00%  | 
       3 / 3  | 
       CRAP |         | 
       100.00%  | 
       1 / 1  | 
      
| ExchangeClientorganisation |         | 
       100.00%  | 
       64 / 64  | 
               | 
       100.00%  | 
       3 / 3  | 
       9 |         | 
       100.00%  | 
       1 / 1  | 
      
| readEntity |         | 
       100.00%  | 
       32 / 32  | 
               | 
       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\Zmsdb; | 
| 4 | |
| 5 | use BO\Zmsentities\Exchange; | 
| 6 | |
| 7 | class ExchangeClientorganisation 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 | $config = (new Config())->readEntity(); | 
| 22 | $costs = $config->getNotificationPreferences()['costs']; | 
| 23 | |
| 24 | $organisation = (new Organisation())->readEntity($subjectid); | 
| 25 | $entity = new Exchange(); | 
| 26 | $entity['title'] = "Kundenstatistik $organisation->name"; | 
| 27 | $entity->setPeriod($datestart, $dateend, $period); | 
| 28 | $entity->addDictionaryEntry('subjectid', 'string', 'ID of a organisation', 'organisation.id'); | 
| 29 | $entity->addDictionaryEntry('date'); | 
| 30 | $entity->addDictionaryEntry('notificationscount'); | 
| 31 | $entity->addDictionaryEntry('notificationscost'); | 
| 32 | $entity->addDictionaryEntry('clientscount'); | 
| 33 | $entity->addDictionaryEntry('missed'); | 
| 34 | $entity->addDictionaryEntry('withappointment'); | 
| 35 | $entity->addDictionaryEntry('missedwithappointment'); | 
| 36 | $entity->addDictionaryEntry('requestscount'); | 
| 37 | $subjectIdList = explode(',', $subjectid); | 
| 38 | |
| 39 | foreach ($subjectIdList as $subjectid) { | 
| 40 | $raw = $this | 
| 41 | ->getReader() | 
| 42 | ->fetchAll( | 
| 43 | constant("\BO\Zmsdb\Query\ExchangeClientorganisation::QUERY_READ_REPORT"), | 
| 44 | [ | 
| 45 | 'organisationid' => $subjectid, | 
| 46 | 'datestart' => $datestart->format('Y-m-d'), | 
| 47 | 'dateend' => $dateend->format('Y-m-d'), | 
| 48 | 'groupby' => $this->groupBy[$period] | 
| 49 | ] | 
| 50 | ); | 
| 51 | foreach ($raw as $entry) { | 
| 52 | $entry['notificationscost'] = $entry['notificationscount'] * $costs; | 
| 53 | $entity->addDataSet(array_values($entry)); | 
| 54 | } | 
| 55 | } | 
| 56 | return $entity; | 
| 57 | } | 
| 58 | |
| 59 | public function readSubjectList() | 
| 60 | { | 
| 61 | $raw = $this->getReader()->fetchAll(Query\ExchangeClientorganisation::QUERY_SUBJECTS, []); | 
| 62 | $entity = new Exchange(); | 
| 63 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable()); | 
| 64 | $entity->addDictionaryEntry('subject', 'string', 'Organisation ID', 'organisation.id'); | 
| 65 | $entity->addDictionaryEntry('periodstart', 'string', 'Datum von'); | 
| 66 | $entity->addDictionaryEntry('periodend', 'string', 'Datum bis'); | 
| 67 | $entity->addDictionaryEntry('description', 'string', 'Name der Organisation'); | 
| 68 | foreach ($raw as $entry) { | 
| 69 | $entity->addDataSet(array_values($entry)); | 
| 70 | } | 
| 71 | return $entity; | 
| 72 | } | 
| 73 | |
| 74 | public function readPeriodList($subjectid, $period = 'day') | 
| 75 | { | 
| 76 | $organisation = (new Organisation())->readEntity($subjectid); | 
| 77 | $entity = new Exchange(); | 
| 78 | $entity['title'] = "Kundenstatistik $organisation->name"; | 
| 79 | $entity->setPeriod(new \DateTimeImmutable(), new \DateTimeImmutable(), $period); | 
| 80 | $entity->addDictionaryEntry('period'); | 
| 81 | |
| 82 | $montsList = $this->getReader()->fetchAll( | 
| 83 | constant("\BO\Zmsdb\Query\ExchangeClientorganisation::QUERY_PERIODLIST_MONTH"), | 
| 84 | [ | 
| 85 | 'organisationid' => $subjectid, | 
| 86 | ] | 
| 87 | ); | 
| 88 | $raw = []; | 
| 89 | foreach ($montsList as $month) { | 
| 90 | $date = new \DateTimeImmutable($month['date']); | 
| 91 | $raw[$date->format('Y')][] = $month['date']; | 
| 92 | rsort($raw[$date->format('Y')]); | 
| 93 | } | 
| 94 | krsort($raw); | 
| 95 | |
| 96 | foreach ($raw as $year => $months) { | 
| 97 | $entity->addDataSet([$year]); | 
| 98 | foreach ($months as $month) { | 
| 99 | $entity->addDataSet([$month]); | 
| 100 | } | 
| 101 | } | 
| 102 | return $entity; | 
| 103 | } | 
| 104 | } |