Lines
100.00%
28 / 28
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Month | 100.00% | 28 / 28 | 100.00% | 5 / 5 | 9 | 100.00% | 1 / 1 | |||
| getDefaults | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | |||||
| getFirstDay | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| getDayList | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | |||||
| setDays | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | |||||
| createForDateFromDayList | 100.00% | 13 / 13 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsentities; | |
| 4 | ||
| 5 | class Month extends Schema\Entity | |
| 6 | { | |
| 7 | public const string PRIMARY = 'month'; | |
| 8 | ||
| 9 | public mixed $calendarDayList = null; | |
| 10 | ||
| 11 | public static $schema = "month.json"; | |
| 12 | ||
| 13 | /** | |
| 14 | * @return Collection\DayList[] | |
| 15 | * | |
| 16 | */ | |
| 17 | #[\Override] | |
| 18 | public function getDefaults() | |
| 19 | { | |
| 20 | return [ | |
| 21 | 'days' => new Collection\DayList(), | |
| 22 | ]; | |
| 23 | } | |
| 24 | ||
| 25 | public function getFirstDay(): \BO\Zmsentities\Helper\DateTime | |
| 26 | { | |
| 27 | $dateTime = Helper\DateTime::create($this['year'] . '-' . $this['month'] . '-1'); | |
| 28 | return $dateTime->modify('00:00:00'); | |
| 29 | } | |
| 30 | ||
| 31 | public function getDayList(): Collection\DayList | |
| 32 | { | |
| 33 | $days = $this->days; | |
| 34 | if (!$days instanceof Collection\DayList) { | |
| 35 | $days = new Collection\DayList($days); | |
| 36 | $this->days = $days; | |
| 37 | } | |
| 38 | return $days; | |
| 39 | } | |
| 40 | ||
| 41 | public function setDays(Collection\DayList $dayList): static | |
| 42 | { | |
| 43 | foreach ($this->getDayList() as $key => $day) { | |
| 44 | if (!$day instanceof Day) { | |
| 45 | $day = new Day($day); | |
| 46 | } | |
| 47 | $this->days[$key] = $dayList->getDayByDay($day); | |
| 48 | } | |
| 49 | return $this; | |
| 50 | } | |
| 51 | ||
| 52 | public static function createForDateFromDayList( | |
| 53 | \DateTimeInterface $currentDate, | |
| 54 | \BO\Zmsentities\Collection\DayList $dayList | |
| 55 | ): self { | |
| 56 | $startDow = date('w', mktime(0, 0, 0, (int) $currentDate->format('m'), 1, (int) $currentDate->format('Y'))); | |
| 57 | $monthDayList = $dayList->withAssociatedDays($currentDate); | |
| 58 | $month = (new self( | |
| 59 | array( | |
| 60 | 'year' => $currentDate->format('Y'), | |
| 61 | 'month' => $currentDate->format('m'), | |
| 62 | 'calHeadline' => \BO\Zmsentities\Helper\DateTime::getFormatedDates($currentDate, 'MMMM yyyy'), | |
| 63 | 'startDow' => ($startDow == 0) ? 6 : $startDow - 1, // change for week start with monday on 0, | |
| 64 | 'days' => $monthDayList, | |
| 65 | 'appointmentExists' => $monthDayList->hasDayWithAppointments(), | |
| 66 | ) | |
| 67 | )); | |
| 68 | return $month; | |
| 69 | } | |
| 70 | } |