Tour-Ansprechpartner änderbar, Selbst-Austragung gesperrt

This commit is contained in:
torsten 2026-11-08 17:13:11 +01:00
parent 77df14237c
commit 322d232012
5 changed files with 82 additions and 5 deletions

View file

@ -192,11 +192,13 @@ class TourController
redirect('/tour');
}
$guides = User::selectableGuides();
if ($tour->start < today()) {
$tour->start = german_date($tour->start);
$tour->deadline = german_date($tour->deadline);
view('tour.edit_old', ['tour' => $tour]);
view('tour.edit_old', ['tour' => $tour, 'guides' => $guides]);
return;
}
@ -206,7 +208,7 @@ class TourController
$tour->start = german_date($tour->start);
$tour->deadline = german_date($tour->deadline);
view('tour.edit', ['tour' => $tour, 'rooms' => $rooms]);
view('tour.edit', ['tour' => $tour, 'rooms' => $rooms, 'guides' => $guides]);
}
public function update(string $id): void
@ -230,6 +232,13 @@ class TourController
'user_id' => 'required',
]);
$guide = User::find((int) input('user_id'));
if ($guide === null || $guide->role === 'GUEST') {
flash_set('error', 'Der gewählte Ansprechpartner ist ungültig.');
redirect('/tour/' . $tourId . '/edit');
}
$imageError = null;
if (!empty($_FILES['bild']['name'])) {
@ -247,6 +256,7 @@ class TourController
}
}
$tour->user_id = (int) $guide->id;
$tour->name = (string) input('name');
if (input('beschreibung') !== null) {
$tour->beschreibung = (string) input('beschreibung');
@ -292,7 +302,25 @@ class TourController
public function joinRoom(string $tour_id, string $room_id): void
{
Booking::joinRoom((int) $tour_id, (int) Auth::id(), (int) $room_id);
$tour = Tour::find((int) $tour_id);
$user = Auth::user();
if ($tour === null || $user === null) {
redirect('/tour');
}
$roomId = (int) $room_id;
// Normale Nutzer dürfen sich nur selbst in einen echten, freien Raum
// eintragen. room_id 0 (austragen) und Raumwechsel bleiben Admins
// bzw. dem Tour-Ansprechpartner vorbehalten.
if (Booking::forUser((int) $tour->id, (int) $user->id) !== null
|| !TourRoom::isBookable((int) $tour->id, $roomId)
|| !Tour::hasSpace((int) $tour->id)) {
redirect('/tour/' . $tour_id);
}
Booking::joinRoom((int) $tour->id, (int) $user->id, $roomId);
redirect('/tour/' . $tour_id);
}