diff --git a/motorradig/README.md b/motorradig/README.md index faaf620..8e7ba01 100644 --- a/motorradig/README.md +++ b/motorradig/README.md @@ -9,6 +9,7 @@ Keine externen Composer-Abhängigkeiten. - Startseite und „Aktivitäten" (Inhalt in der Datenbank editierbar) - Mitgliederliste, Benutzerprofile mit Bild - Tourenplan mit Anmeldung, Zimmer-Buchung und Galerie +- Jahreskalender (`/tour/kalender`) mit farblich markierten Touren und Jahres-Navigator - Tour-Chat für Teilnehmer (Polling, ungelesen, Push optional) - Rollen `GUEST` / `MEMBER` / `TOUR GUIDE` / `ADMIN` - Login/Logout, Registrierung, Passwort-Reset per E-Mail diff --git a/motorradig/public/css/custom.css b/motorradig/public/css/custom.css index 65baba3..dd8da55 100644 --- a/motorradig/public/css/custom.css +++ b/motorradig/public/css/custom.css @@ -783,6 +783,205 @@ p { } } +/* Jahreskalender: Touren farblich markiert */ +.tour-calendar-head { + display: flex; + flex-wrap: wrap; + align-items: baseline; + justify-content: space-between; + gap: .75rem; + max-width: 1120px; + margin: 0 auto; +} + +.tour-calendar-title { + margin: 0; + color: #fff; + font-size: 1.9rem; + font-weight: 600; +} + +.tour-calendar-back { + color: #9cc9ff; + text-decoration: none; +} + +.tour-calendar-back:hover, +.tour-calendar-back:focus { + color: #fff; + text-decoration: underline; +} + +.calendar-years { + margin: 1.25rem auto 1rem; +} + +.calendar-year-arrow { + min-width: 3rem; + font-weight: 700; +} + +.calendar-legend { + display: flex; + flex-wrap: wrap; + justify-content: center; + gap: .5rem 1.5rem; + max-width: 1120px; + margin: 0 auto 1.5rem; + padding: 0; + list-style: none; + color: rgba(255, 255, 255, .78); + font-size: .92rem; +} + +.calendar-legend li { + display: inline-flex; + align-items: center; + gap: .45rem; +} + +.calendar-legend-count { + color: rgba(255, 255, 255, .55); + font-variant-numeric: tabular-nums; +} + +.calendar-dot { + display: inline-block; + width: .8rem; + height: .8rem; + border-radius: 50%; +} + +.calendar-dot.is-scheduled { + background: #15803d; +} + +.calendar-dot.is-past { + background: #94a3b8; +} + +.calendar-dot.is-cancelled { + background: #e5484d; +} + +.calendar-months { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); + gap: 1.25rem; + max-width: 1120px; + margin: 0 auto 3rem; +} + +.calendar-month { + padding: .9rem; + border: 1px solid rgba(255, 255, 255, .14); + border-radius: 14px; + background: rgba(13, 17, 23, .6); +} + +.calendar-month-title { + margin: 0 0 .7rem; + color: #fff; + font-size: 1.05rem; + font-weight: 700; + letter-spacing: .02em; + text-align: center; +} + +.calendar-weekdays, +.calendar-grid { + display: grid; + grid-template-columns: repeat(7, minmax(0, 1fr)); + gap: 2px; +} + +.calendar-weekday { + padding-bottom: .3rem; + color: rgba(255, 255, 255, .5); + font-size: .72rem; + text-align: center; + text-transform: uppercase; +} + +.calendar-day { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + min-width: 0; + min-height: 2.15rem; + padding: 2px; + border-radius: 7px; + color: rgba(255, 255, 255, .85); + font-size: .82rem; + line-height: 1.1; + text-align: center; + text-decoration: none; + overflow: hidden; +} + +.calendar-day.is-empty { + background: transparent; +} + +.calendar-day.is-today { + outline: 1px dashed rgba(255, 255, 255, .6); + outline-offset: -1px; +} + +.calendar-day.is-tour { + color: #fff; + font-weight: 700; +} + +.calendar-day.is-tour:hover, +.calendar-day.is-tour:focus { + color: #fff; + text-decoration: none; + box-shadow: 0 0 0 2px rgba(78, 161, 255, .85); +} + +.calendar-day.is-scheduled { + background: #15803d; +} + +.calendar-day.is-past { + background: rgba(148, 163, 184, .5); +} + +.calendar-day.is-cancelled { + background: #e5484d; +} + +.calendar-day-number { + line-height: 1.05; +} + +.calendar-day-label { + display: block; + width: 100%; + font-size: .58rem; + font-weight: 600; + line-height: 1.05; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +@media (max-width: 575.98px) { + .tour-calendar-title { + font-size: 1.5rem; + } + + .calendar-months { + grid-template-columns: 1fr; + } + + .calendar-day { + min-height: 2rem; + } +} + /* Tour-Bilder: mehrere Bilder pro Tour */ .tour-media-grid { --gallery-accent: #4ea1ff; diff --git a/motorradig/src/Controllers/TourController.php b/motorradig/src/Controllers/TourController.php index e3ce755..dba8ad5 100644 --- a/motorradig/src/Controllers/TourController.php +++ b/motorradig/src/Controllers/TourController.php @@ -61,6 +61,88 @@ class TourController ]); } + /** Jahreskalender, in dem alle Touren farblich markiert sind. */ + public function calendar(): void + { + $currentYear = (int) date('Y'); + $tourYears = Tour::years(); + + $firstYear = min(array_merge([$currentYear - 1], $tourYears)); + $lastYear = max(array_merge([$currentYear + 1], $tourYears)); + + $requestedYear = input('jahr'); + $selectedYear = $currentYear; + + if (is_string($requestedYear) && ctype_digit($requestedYear)) { + $selectedYear = (int) $requestedYear; + } + + $selectedYear = max($firstYear, min($lastYear, $selectedYear)); + + $toursByDay = []; + + foreach (Tour::forYear($selectedYear) as $tour) { + $toursByDay[substr((string) $tour->start, 0, 10)][] = $tour; + } + + view('tour.calendar', [ + 'selectedYear' => $selectedYear, + 'years' => range($firstYear, $lastYear), + 'months' => $this->buildCalendarMonths($selectedYear, $toursByDay), + 'todayDate' => today(), + 'tourCount' => array_sum(array_map('count', $toursByDay)), + ]); + } + + /** + * Baut das Monatsraster (Montag als erster Wochentag) für den Jahreskalender. + * + * @param array> $toursByDay + */ + private function buildCalendarMonths(int $year, array $toursByDay): array + { + $labels = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', + 'August', 'September', 'Oktober', 'November', 'Dezember']; + + $months = []; + + foreach ($labels as $index => $label) { + $month = $index + 1; + $first = new \DateTimeImmutable(sprintf('%04d-%02d-01', $year, $month)); + $daysInMonth = (int) $first->format('t'); + $leadingBlanks = (int) $first->format('N') - 1; + + $weeks = []; + $week = array_fill(0, $leadingBlanks, null); + + for ($day = 1; $day <= $daysInMonth; $day++) { + $date = $first->setDate($year, $month, $day)->format('Y-m-d'); + + $week[] = [ + 'day' => $day, + 'date' => $date, + 'tours' => $toursByDay[$date] ?? [], + ]; + + if (count($week) === 7) { + $weeks[] = $week; + $week = []; + } + } + + if ($week !== []) { + $weeks[] = array_pad($week, 7, null); + } + + $months[] = [ + 'label' => $label, + 'weeks' => $weeks, + ]; + } + + return $months; + } + public function indexOld(): void { $tours = Tour::past(); diff --git a/motorradig/src/Models/Tour.php b/motorradig/src/Models/Tour.php index 6c8537a..aeabcd4 100644 --- a/motorradig/src/Models/Tour.php +++ b/motorradig/src/Models/Tour.php @@ -55,6 +55,27 @@ class Tour extends Model ); } + /** Alle Touren eines Jahres, sortiert nach Startdatum. */ + public static function forYear(int $year): array + { + $rows = db()->fetchAll( + 'SELECT * FROM `tours` WHERE start IS NOT NULL AND YEAR(start) = ? ORDER BY start', + [$year] + ); + + return array_map(fn(array $row) => static::fromRow($row), $rows); + } + + /** Alle Jahre, in denen mindestens eine Tour stattfindet. */ + public static function years(): array + { + $rows = db()->fetchAll( + 'SELECT DISTINCT YEAR(start) AS jahr FROM `tours` WHERE start IS NOT NULL ORDER BY jahr' + ); + + return array_map(fn(array $row) => (int) $row['jahr'], $rows); + } + /** Admin oder der dieser Tour zugeordnete Tour Guide. */ public static function canManage(int $tourId, ?User $user): bool { diff --git a/motorradig/src/routes.php b/motorradig/src/routes.php index 56b139b..70e7e2d 100644 --- a/motorradig/src/routes.php +++ b/motorradig/src/routes.php @@ -52,6 +52,7 @@ $router->post('/delete_guests', [AdminController::class, 'deleteGuests'], 'ADMIN // Touren $router->get('/tour/index_old', [TourController::class, 'indexOld'], true); $router->get('/tour', [TourController::class, 'index'], true); +$router->get('/tour/kalender', [TourController::class, 'calendar'], true); $router->get('/tour/create', [TourController::class, 'create'], true); $router->post('/tour/store', [TourController::class, 'store'], true); $router->post('/tour/update', [TourController::class, 'store'], true); diff --git a/motorradig/views/tour/calendar.php b/motorradig/views/tour/calendar.php new file mode 100644 index 0000000..3c3e5d5 --- /dev/null +++ b/motorradig/views/tour/calendar.php @@ -0,0 +1,107 @@ + +
+
+

Jahreskalender

+ ← zur Tourenliste +
+ + + + + +
+ +
+

+ +
+ + + +
+ +
+ + + + + + + + + + is_cancelled) { + $isCancelled = true; + $titles[] = $tour->name . ' (abgesagt)'; + } else { + $titles[] = $tour->name; + } + + if (substr((string) $tour->start, 0, 10) < $todayDate) { + $isPast = true; + } + } + + $stateClass = $isCancelled ? 'is-cancelled' : ($isPast ? 'is-past' : 'is-scheduled'); + // Viele Tournamen beginnen mit "TT.MM.JJJJ - ". Das Datum steht bereits + // in der Zelle, daher im Kalender nur den Titel anzeigen. + $label = trim((string) preg_replace('/^\d{1,2}\.\d{1,2}\.\d{4}\s*[-–]\s*/u', '', (string) $firstTour->name)); + + if ($label === '') { + $label = (string) $firstTour->name; + } + + if (count($tours) > 1) { + $label .= ' +' . (count($tours) - 1); + } + ?> + + + + + + + +
+
+ +
+
diff --git a/motorradig/views/tour/index.php b/motorradig/views/tour/index.php index 46fbdea..71b20e9 100644 --- a/motorradig/views/tour/index.php +++ b/motorradig/views/tour/index.php @@ -67,6 +67,10 @@ +
+

Jahreskalender

+
+ canCreateTours()): ?>

Neue Tour anlegen