Lines
100.00%
35 / 35
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Day | 100.00% | 35 / 35 | 100.00% | 5 / 5 | 14 | 100.00% | 1 / 1 | |||
| writeTemporaryScopeList | 100.00% | 15 / 15 | 100.00% | 1 / 1 | 5 | |||||
| rewriteTemporaryScopeList | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | |||||
| readByCalendar | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| readListFromPreparedTemporaryScopeList | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 4 | |||||
| __destruct | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Day\Service; | |
| 4 | ||
| 5 | use BO\Zmsentities\Day as Entity; | |
| 6 | ||
| 7 | class Day extends \BO\Zmsbackend\Base | |
| 8 | { | |
| 9 | protected $tempScopeListExists = false; | |
| 10 | ||
| 11 | public function writeTemporaryScopeList(\BO\Zmsentities\Calendar $calendar, int|float|null $slotsRequiredForce = null): void | |
| 12 | { | |
| 13 | $this->getReader()->exec(\BO\Zmsbackend\Day\Repository\Day::QUERY_CREATE_TEMPORARY_SCOPELIST); | |
| 14 | $monthList = $calendar->getMonthList(); | |
| 15 | $slotsRequired = $slotsRequiredForce; | |
| 16 | foreach ($monthList as $month) { | |
| 17 | $dateTime = $month->getFirstDay(); | |
| 18 | foreach ($calendar->scopes as $scope) { | |
| 19 | if (!$slotsRequiredForce) { | |
| 20 | $slotsRequired = $calendar->scopes->getRequiredSlotsByScope($scope); | |
| 21 | } | |
| 22 | $this->getReader()->perform(\BO\Zmsbackend\Day\Repository\Day::QUERY_INSERT_TEMPORARY_SCOPELIST, [ | |
| 23 | 'scopeID' => $scope->id, | |
| 24 | 'year' => $dateTime->format('Y'), | |
| 25 | 'month' => $dateTime->format('m'), | |
| 26 | 'slotsRequired' => $slotsRequired > 1 ? round($slotsRequired, 0) : 1, | |
| 27 | ]); | |
| 28 | } | |
| 29 | } | |
| 30 | $this->tempScopeListExists = true; | |
| 31 | } | |
| 32 | ||
| 33 | /** | |
| 34 | * Drop and rebuild calendarscope for the calendar's current firstDay/lastDay months. | |
| 35 | * Used to shrink the daylist window (painted month) or scan one neighbor month at a time. | |
| 36 | */ | |
| 37 | public function rewriteTemporaryScopeList(\BO\Zmsentities\Calendar $calendar, int|float|null $slotsRequiredForce = null): void | |
| 38 | { | |
| 39 | if ($this->tempScopeListExists) { | |
| 40 | $this->getReader()->exec(\BO\Zmsbackend\Day\Repository\Day::QUERY_DROP_TEMPORARY_SCOPELIST); | |
| 41 | $this->tempScopeListExists = false; | |
| 42 | } | |
| 43 | $this->writeTemporaryScopeList($calendar, $slotsRequiredForce); | |
| 44 | } | |
| 45 | ||
| 46 | public function readByCalendar(\BO\Zmsentities\Calendar $calendar, int|float|null $slotsRequiredForce = null) | |
| 47 | { | |
| 48 | // We use a temporary table, so we can use create and insert on a readonly connection | |
| 49 | $this->writeTemporaryScopeList($calendar, $slotsRequiredForce); | |
| 50 | ||
| 51 | return $this->readListFromPreparedTemporaryScopeList($slotsRequiredForce); | |
| 52 | } | |
| 53 | ||
| 54 | public function readListFromPreparedTemporaryScopeList(int|float|null $slotsRequiredForce = null, ?string $daylistQuery = null): \BO\Zmsentities\Collection\DayList | |
| 55 | { | |
| 56 | $dayList = new \BO\Zmsentities\Collection\DayList(); | |
| 57 | $dayData = $this->getReader()->fetchAll( | |
| 58 | $daylistQuery ?? \BO\Zmsbackend\Day\Repository\Day::QUERY_DAYLIST_JOIN, | |
| 59 | [ | |
| 60 | 'forceRequiredSlots' => | |
| 61 | ($slotsRequiredForce === null || $slotsRequiredForce < 1) ? 1 : round($slotsRequiredForce), | |
| 62 | ] | |
| 63 | ); | |
| 64 | foreach ($dayData as $day) { | |
| 65 | $day = new \BO\Zmsentities\Day($day); | |
| 66 | $dayList[$day->getDayHash()] = $day; | |
| 67 | } | |
| 68 | ||
| 69 | return $dayList; | |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Remove temporary scope list at destruct to allow other functions to use it | |
| 74 | */ | |
| 75 | public function __destruct() | |
| 76 | { | |
| 77 | if ($this->tempScopeListExists) { | |
| 78 | $this->getReader()->exec(\BO\Zmsbackend\Day\Repository\Day::QUERY_DROP_TEMPORARY_SCOPELIST); | |
| 79 | } | |
| 80 | } | |
| 81 | } |