Alte Touren nach Jahren gruppieren

This commit is contained in:
torsten 2026-11-08 17:02:51 +01:00
parent 6b6aaf881e
commit 77df14237c
3 changed files with 213 additions and 16 deletions

View file

@ -32,18 +32,47 @@ class TourController
$tours = Tour::past();
$participantCount = [];
$imagecountPerTour = [];
$toursByYear = [];
foreach ($tours as $tour) {
$participantCount[$tour->id] = Booking::countForTour((int) $tour->id);
// Jahr vor der Formatierung aus dem DB-Datum (YYYY-MM-DD) lesen.
$year = (int) substr((string) $tour->start, 0, 4);
if ($year < 1900) {
$year = 0;
}
$tour->start = german_date($tour->start);
$tour->deadline = german_date($tour->deadline);
$files = glob(storage_path('img_storage/tour-' . $tour->id) . '/*') ?: [];
$imagecountPerTour[$tour->id] = (int) (count($files) / 2);
$toursByYear[$year][] = $tour;
}
krsort($toursByYear, SORT_NUMERIC);
$years = array_keys($toursByYear);
// Ohne Auswahl werden alle Jahre gruppiert angezeigt. ?jahr=2025 filtert.
$requestedYear = input('jahr');
$selectedYear = null;
if (is_string($requestedYear) && ctype_digit($requestedYear)) {
$candidate = (int) $requestedYear;
if (isset($toursByYear[$candidate])) {
$selectedYear = $candidate;
}
}
$visibleYears = $selectedYear === null ? $years : [$selectedYear];
view('tour.index_old', [
'tours' => $tours,
'toursByYear' => $toursByYear,
'years' => $years,
'visibleYears' => $visibleYears,
'selectedYear' => $selectedYear,
'participantCount' => $participantCount,
'imagecountPerTour' => $imagecountPerTour,
]);