Jahreskalender mit farblich markierten Touren und Jahres-Navigator
This commit is contained in:
parent
7695c70ad2
commit
b92664f80e
7 changed files with 415 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<string, array<int, Tour>> $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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
107
motorradig/views/tour/calendar.php
Normal file
107
motorradig/views/tour/calendar.php
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
/** @var array $months */
|
||||
/** @var array $years */
|
||||
/** @var int $selectedYear */
|
||||
/** @var string $todayDate */
|
||||
/** @var int $tourCount */
|
||||
$weekdayLabels = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'];
|
||||
?>
|
||||
<div class="container mt-4">
|
||||
<header class="tour-calendar-head">
|
||||
<h1 class="tour-calendar-title">Jahreskalender <?= (int) $selectedYear ?></h1>
|
||||
<a class="tour-calendar-back" href="/tour">← zur Tourenliste</a>
|
||||
</header>
|
||||
|
||||
<nav class="tour-years calendar-years" aria-label="Jahr wählen">
|
||||
<?php if ($selectedYear > min($years)): ?>
|
||||
<a class="tour-year-pill calendar-year-arrow" href="/tour/kalender?jahr=<?= (int) $selectedYear - 1 ?>"
|
||||
aria-label="Vorheriges Jahr">«</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($years as $year): ?>
|
||||
<a class="tour-year-pill <?= $year === $selectedYear ? 'is-active' : '' ?>"
|
||||
href="/tour/kalender?jahr=<?= (int) $year ?>"
|
||||
<?= $year === $selectedYear ? 'aria-current="page"' : '' ?>><?= (int) $year ?></a>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($selectedYear < max($years)): ?>
|
||||
<a class="tour-year-pill calendar-year-arrow" href="/tour/kalender?jahr=<?= (int) $selectedYear + 1 ?>"
|
||||
aria-label="Nächstes Jahr">»</a>
|
||||
<?php endif; ?>
|
||||
</nav>
|
||||
|
||||
<ul class="calendar-legend">
|
||||
<li><span class="calendar-dot is-scheduled"></span> Tour geplant</li>
|
||||
<li><span class="calendar-dot is-past"></span> Tour vorbei</li>
|
||||
<li><span class="calendar-dot is-cancelled"></span> Tour abgesagt</li>
|
||||
<li class="calendar-legend-count"><?= (int) $tourCount ?> Touren in <?= (int) $selectedYear ?></li>
|
||||
</ul>
|
||||
|
||||
<div class="calendar-months">
|
||||
<?php foreach ($months as $month): ?>
|
||||
<section class="calendar-month">
|
||||
<h2 class="calendar-month-title"><?= e($month['label']) ?></h2>
|
||||
|
||||
<div class="calendar-weekdays">
|
||||
<?php foreach ($weekdayLabels as $weekdayLabel): ?>
|
||||
<span class="calendar-weekday"><?= e($weekdayLabel) ?></span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div class="calendar-grid">
|
||||
<?php foreach ($month['weeks'] as $week): ?>
|
||||
<?php foreach ($week as $day): ?>
|
||||
<?php if ($day === null): ?>
|
||||
<span class="calendar-day is-empty"></span>
|
||||
<?php elseif ($day['tours'] === []): ?>
|
||||
<span class="calendar-day <?= $day['date'] === $todayDate ? 'is-today' : '' ?>">
|
||||
<span class="calendar-day-number"><?= (int) $day['day'] ?></span>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<?php
|
||||
$tours = $day['tours'];
|
||||
$firstTour = $tours[0];
|
||||
$isCancelled = false;
|
||||
$isPast = false;
|
||||
$titles = [];
|
||||
|
||||
foreach ($tours as $tour) {
|
||||
if ((bool) $tour->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);
|
||||
}
|
||||
?>
|
||||
<a class="calendar-day is-tour <?= $stateClass ?> <?= $day['date'] === $todayDate ? 'is-today' : '' ?>"
|
||||
href="/tour/<?= (int) $firstTour->id ?>"
|
||||
title="<?= e(implode(', ', $titles)) ?>">
|
||||
<span class="calendar-day-number"><?= (int) $day['day'] ?></span>
|
||||
<span class="calendar-day-label"><?= e($label) ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -67,6 +67,10 @@
|
|||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="container text-primary">
|
||||
<a href="/tour/kalender" class="btn btn-success col-3 mt-2"><h3>Jahreskalender</h3></a>
|
||||
</div>
|
||||
|
||||
<?php if ($current && $current->canCreateTours()): ?>
|
||||
<div class="container text-primary">
|
||||
<a href="/tour/create" class="btn btn-danger col-3 mt-2 "><h3>Neue Tour anlegen</h3></a>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue