Rolle TOUR GUIDE einführen

This commit is contained in:
torsten 2026-11-08 18:07:28 +01:00
parent 4f65250190
commit ca3c490d4a
11 changed files with 54 additions and 10 deletions

View file

@ -17,7 +17,7 @@ class Booking extends Model
/**
* true, wenn der Benutzer die Bildergalerie einer Tour sehen darf:
* Admins immer, sonst nur Teilnehmer (vorhandene Buchung).
* Admins immer, der eingetragene Tour Guide und Teilnehmer.
*/
public static function canAccessTourGallery(int $tourId, ?User $user): bool
{
@ -29,6 +29,12 @@ class Booking extends Model
return true;
}
$tour = db()->fetchOne('SELECT tour_guide_id FROM `tours` WHERE id = ?', [$tourId]);
if ($tour !== null && (int) $tour['tour_guide_id'] === (int) $user->id) {
return true;
}
return static::forUser($tourId, (int) $user->id) !== null;
}

View file

@ -41,12 +41,12 @@ class User extends Model
return trim(preg_replace('/\s+/u', ' ', $name) ?? '');
}
/** Admins und Mitglieder, die als Tour Guide wählbar sind. */
/** Admins und Tour Guides, die als Tour Guide wählbar sind. */
public static function selectableGuides(): array
{
$rows = db()->fetchAll(
'SELECT * FROM `users` WHERE role IN (?, ?) ORDER BY name',
['ADMIN', 'MEMBER']
['ADMIN', 'TOUR GUIDE']
);
return array_map(fn(array $row) => static::fromRow($row), $rows);
@ -57,8 +57,19 @@ class User extends Model
return $this->role === 'ADMIN';
}
public function isTourGuide(): bool
{
return $this->role === 'TOUR GUIDE';
}
public function isMember(): bool
{
return $this->role === 'MEMBER';
return in_array($this->role, ['MEMBER', 'TOUR GUIDE'], true);
}
/** Darf Touren anlegen (Admin oder Tour Guide). */
public function canCreateTours(): bool
{
return $this->isAdmin() || $this->isTourGuide();
}
}