Touren: Enddatum ergänzen und Dauer im Jahreskalender anzeigen
This commit is contained in:
parent
b92664f80e
commit
3ea18501b8
15 changed files with 521 additions and 22 deletions
|
|
@ -80,9 +80,15 @@ class TourController
|
|||
$selectedYear = max($firstYear, min($lastYear, $selectedYear));
|
||||
|
||||
$toursByDay = [];
|
||||
$tourCount = 0;
|
||||
|
||||
foreach (Tour::forYear($selectedYear) as $tour) {
|
||||
$toursByDay[substr((string) $tour->start, 0, 10)][] = $tour;
|
||||
$tourCount++;
|
||||
|
||||
// Mehrtägige Touren erscheinen an jedem Tag ihres Zeitraums.
|
||||
foreach ($tour->days() as $date) {
|
||||
$toursByDay[$date][] = $tour;
|
||||
}
|
||||
}
|
||||
|
||||
view('tour.calendar', [
|
||||
|
|
@ -90,10 +96,33 @@ class TourController
|
|||
'years' => range($firstYear, $lastYear),
|
||||
'months' => $this->buildCalendarMonths($selectedYear, $toursByDay),
|
||||
'todayDate' => today(),
|
||||
'tourCount' => array_sum(array_map('count', $toursByDay)),
|
||||
'tourCount' => $tourCount,
|
||||
]);
|
||||
}
|
||||
|
||||
/** Enddatum aus dem Formular; null, wenn nichts angegeben wurde. */
|
||||
private function endDateFromInput(): ?string
|
||||
{
|
||||
$value = trim((string) input('end_date'));
|
||||
|
||||
return $value === '' ? null : db_date($value);
|
||||
}
|
||||
|
||||
/** Das Enddatum darf nicht vor dem Startdatum liegen. */
|
||||
private function assertEndDate(): void
|
||||
{
|
||||
$start = trim((string) input('start'));
|
||||
$end = trim((string) input('end_date'));
|
||||
|
||||
if ($start === '' || $end === '' || db_date($end) >= db_date($start)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$_SESSION['_errors']['end_date'][] = 'Das Enddatum darf nicht vor dem Startdatum liegen.';
|
||||
$_SESSION['_old'] = $_POST;
|
||||
back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut das Monatsraster (Montag als erster Wochentag) für den Jahreskalender.
|
||||
*
|
||||
|
|
@ -227,6 +256,7 @@ class TourController
|
|||
app_log('info', 'Tour create attempt', [
|
||||
'name' => input('name'),
|
||||
'start' => input('start'),
|
||||
'end_date' => input('end_date'),
|
||||
'deadline' => input('deadline'),
|
||||
'max_participants' => input('max_participants'),
|
||||
'is_cancelled' => input('is_cancelled'),
|
||||
|
|
@ -240,19 +270,23 @@ class TourController
|
|||
'name' => 'required|min:3',
|
||||
'beschreibung' => 'required',
|
||||
'start' => 'required|date',
|
||||
'end_date' => 'date',
|
||||
'deadline' => 'required|date',
|
||||
'tour_guide_id' => 'required',
|
||||
]);
|
||||
|
||||
$this->assertEndDate();
|
||||
|
||||
try {
|
||||
$tour = Tour::create([
|
||||
'name' => (string) input('name'),
|
||||
'tour_guide_id' => (int) input('tour_guide_id'),
|
||||
'beschreibung' => (string) input('beschreibung'),
|
||||
'start' => db_date(input('start')),
|
||||
'end_date' => $this->endDateFromInput(),
|
||||
'deadline' => db_date(input('deadline')),
|
||||
'max_participants' => (int) (input('max_participants') ?: 5),
|
||||
'is_cancelled' => (bool) input('is_cancelled', false),
|
||||
'is_cancelled' => (int) (bool) input('is_cancelled', false),
|
||||
'bericht' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
|
|
@ -395,13 +429,18 @@ class TourController
|
|||
}
|
||||
}
|
||||
|
||||
$tourDays = $tour->durationDays();
|
||||
$tourEnd = $tour->endDate();
|
||||
|
||||
// Vergangene Tour
|
||||
if ($tour->start < today()) {
|
||||
if ($tourEnd !== null && $tourEnd < today()) {
|
||||
$tour->start = german_date($tour->start);
|
||||
$tour->end_date = $tour->isMultiDay() ? german_date((string) $tourEnd) : '';
|
||||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.show_old', [
|
||||
'tour' => $tour,
|
||||
'days' => $tourDays,
|
||||
'users' => $users,
|
||||
'guide' => $guide,
|
||||
'tourImages' => $tourImages,
|
||||
|
|
@ -416,10 +455,12 @@ class TourController
|
|||
$rooms = array_map(fn(array $row) => (object) $row, TourRoom::fetchRooms((int) $tour->id));
|
||||
|
||||
$tour->start = german_date($tour->start);
|
||||
$tour->end_date = $tour->isMultiDay() ? german_date((string) $tourEnd) : '';
|
||||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.show', [
|
||||
'tour' => $tour,
|
||||
'days' => $tourDays,
|
||||
'users' => $users,
|
||||
'guide' => $guide,
|
||||
'tourImages' => $tourImages,
|
||||
|
|
@ -443,8 +484,11 @@ class TourController
|
|||
$tourGuide = User::find((int) $tour->tour_guide_id);
|
||||
$tourImages = $this->tourImages((int) $tour->id);
|
||||
|
||||
if ($tour->start < today()) {
|
||||
$tourEnd = $tour->endDate();
|
||||
|
||||
if ($tourEnd !== null && $tourEnd < today()) {
|
||||
$tour->start = german_date($tour->start);
|
||||
$tour->end_date = $tour->isMultiDay() ? german_date($tourEnd) : '';
|
||||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.edit_old', [
|
||||
|
|
@ -460,6 +504,7 @@ class TourController
|
|||
$rooms = array_map(fn(array $row) => (object) $row, TourRoom::fetchRooms((int) $tour->id));
|
||||
|
||||
$tour->start = german_date($tour->start);
|
||||
$tour->end_date = $tour->isMultiDay() ? german_date($tourEnd) : '';
|
||||
$tour->deadline = german_date($tour->deadline);
|
||||
|
||||
view('tour.edit', [
|
||||
|
|
@ -491,9 +536,12 @@ class TourController
|
|||
'tour_id' => 'required',
|
||||
'name' => 'required|min:3',
|
||||
'start' => 'required|date',
|
||||
'end_date' => 'date',
|
||||
'deadline' => 'date',
|
||||
]);
|
||||
|
||||
$this->assertEndDate();
|
||||
|
||||
// Nur Admins dürfen den Tour Guide ändern.
|
||||
if ($current->isAdmin()) {
|
||||
$guide = User::find((int) input('tour_guide_id'));
|
||||
|
|
@ -513,6 +561,9 @@ class TourController
|
|||
if (input('start') !== null) {
|
||||
$tour->start = db_date(input('start'));
|
||||
}
|
||||
if (input('end_date') !== null) {
|
||||
$tour->end_date = $this->endDateFromInput();
|
||||
}
|
||||
if (input('deadline') !== null) {
|
||||
$tour->deadline = db_date(input('deadline'));
|
||||
}
|
||||
|
|
@ -520,9 +571,9 @@ class TourController
|
|||
$tour->max_participants = (int) input('max_participants');
|
||||
}
|
||||
if (input('is_cancelled')) {
|
||||
$tour->is_cancelled = true;
|
||||
$tour->is_cancelled = 1;
|
||||
} else {
|
||||
$tour->is_cancelled = false;
|
||||
$tour->is_cancelled = 0;
|
||||
}
|
||||
if (input('bericht') !== null) {
|
||||
$tour->bericht = (string) input('bericht');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue