Aktuelle Touren im Jahres-Pillen-Layout
This commit is contained in:
parent
b52155c5f0
commit
183422b0c8
2 changed files with 75 additions and 16 deletions
|
|
@ -17,14 +17,46 @@ class TourController
|
|||
{
|
||||
$tours = Tour::upcoming();
|
||||
$participantCount = [];
|
||||
$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);
|
||||
|
||||
$toursByYear[$year][] = $tour;
|
||||
}
|
||||
|
||||
view('tour.index', ['tours' => $tours, 'participantCount' => $participantCount]);
|
||||
krsort($toursByYear, SORT_NUMERIC);
|
||||
$years = array_keys($toursByYear);
|
||||
|
||||
// Ohne Auswahl werden alle Jahre gruppiert angezeigt. ?jahr=2026 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', [
|
||||
'toursByYear' => $toursByYear,
|
||||
'years' => $years,
|
||||
'visibleYears' => $visibleYears,
|
||||
'selectedYear' => $selectedYear,
|
||||
'participantCount' => $participantCount,
|
||||
]);
|
||||
}
|
||||
|
||||
public function indexOld(): void
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
use App\Models\Tour;
|
||||
|
||||
$current = auth_check() ? user() : null;
|
||||
$selectedYear = $selectedYear ?? null;
|
||||
$years = $years ?? [];
|
||||
$toursByYear = $toursByYear ?? [];
|
||||
$visibleYears = $visibleYears ?? ($selectedYear === null ? $years : [$selectedYear]);
|
||||
?>
|
||||
|
||||
<div class="container text-center text-light mt-5">
|
||||
|
|
@ -12,23 +16,46 @@
|
|||
<span class="offset-1"><a href="/img_storage/pdf/Tourenplan.pdf" class="btn btn-success"><h3>Download</h3></a></span>
|
||||
</div>
|
||||
|
||||
<div class="container text-primary" style="display:flex">
|
||||
.<ul class="list-group offset-2 col-8">
|
||||
<?php foreach ($tours as $tour): ?>
|
||||
<a href="/tour/<?= e($tour->id) ?>">
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<?= e($tour->start) ?> - <?= e($tour->name) ?> [<?= e($participantCount[$tour->id] ?? 0) ?>/<?= e($tour->max_participants) ?>]
|
||||
<?php if ($years === []): ?>
|
||||
<p class="tour-years-empty">Es sind aktuell keine Touren geplant.</p>
|
||||
<?php else: ?>
|
||||
<nav class="tour-years" aria-label="Aktuelle Touren nach Jahr">
|
||||
<a class="tour-year-pill<?= $selectedYear === null ? ' is-active' : '' ?>"
|
||||
href="/tour"<?= $selectedYear === null ? ' aria-current="page"' : '' ?>>Alle</a>
|
||||
|
||||
<?php if ($current && Tour::hasParticipant((int) $tour->id, (int) $current->id)): ?>
|
||||
<i class="fas fa-biking"></i>
|
||||
<?php endif; ?>
|
||||
|
||||
<span class="badge <?= $tour->is_cancelled ? 'badge-danger' : 'badge-success' ?> badge-pill"><?= $tour->is_cancelled ? 'STORNIERT' : 'FINDET STATT' ?></span>
|
||||
</li>
|
||||
</a>
|
||||
<?php foreach ($years as $year): ?>
|
||||
<?php $yearLabel = ((int) $year === 0) ? 'Ohne Datum' : (string) $year; ?>
|
||||
<a class="tour-year-pill<?= $selectedYear === $year ? ' is-active' : '' ?>"
|
||||
href="/tour?jahr=<?= e($year) ?>"<?= $selectedYear === $year ? ' aria-current="page"' : '' ?>><?= e($yearLabel) ?></a>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<?php foreach ($visibleYears as $year): ?>
|
||||
<?php $yearLabel = ((int) $year === 0) ? 'Ohne Datum' : (string) $year; ?>
|
||||
<section class="tour-year-group" aria-labelledby="tour-year-<?= e($year) ?>">
|
||||
<h2 class="tour-year-heading" id="tour-year-<?= e($year) ?>"><?= e($yearLabel) ?></h2>
|
||||
|
||||
<ul class="list-group tour-list">
|
||||
<?php foreach ($toursByYear[$year] ?? [] as $tour): ?>
|
||||
<li class="list-group-item tour-list-item">
|
||||
<a class="tour-list-link" href="/tour/<?= e($tour->id) ?>">
|
||||
<span class="tour-list-title"><?= e($tour->start) ?> - <?= e($tour->name) ?></span>
|
||||
<span class="tour-list-meta">[<?= e($participantCount[$tour->id] ?? 0) ?>/<?= e($tour->max_participants) ?>]</span>
|
||||
</a>
|
||||
|
||||
<span class="tour-list-actions">
|
||||
<?php if ($current && Tour::hasParticipant((int) $tour->id, (int) $current->id)): ?>
|
||||
<i class="fas fa-biking" title="Du hast teilgenommen" aria-label="Du hast teilgenommen"></i>
|
||||
<?php endif; ?>
|
||||
|
||||
<span class="badge <?= $tour->is_cancelled ? 'badge-danger' : 'badge-success' ?> badge-pill"><?= $tour->is_cancelled ? 'STORNIERT' : 'FINDET STATT' ?></span>
|
||||
</span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($current && ($current->role === 'ADMIN' || $current->role === 'MEMBER')): ?>
|
||||
<div class="container text-primary">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue