format('w') !== 0) { $start = (clone $start)->modify('next sunday'); } $sundays = []; $d = clone $start; while ($d <= $end) { $sundays[] = $d->format('Y-m-d'); $d->modify('+7 days'); } return $sundays; } public function eventDays(string $schoolYear): array { $events = CalendarEvent::getEventsBySchoolYear($schoolYear) ?? []; $eventDays = []; foreach ($events as $event) { $ymd = substr((string) ($event['date'] ?? ''), 0, 10); $no = (int) ($event['no_school'] ?? 0); if ($ymd && $no === 1) { $eventDays[$ymd] = true; } } return $eventDays; } public function dateToIndex(array $sundays, array $eventDays): array { $dateToIndex = []; $idx = 0; foreach ($sundays as $ymd) { if (! isset($eventDays[$ymd])) { $idx++; $dateToIndex[$ymd] = $idx; } else { $dateToIndex[$ymd] = null; } } return $dateToIndex; } }