226 lines
10 KiB
PHP
226 lines
10 KiB
PHP
<?php
|
|
/** @var \App\Models\Tour $tour */
|
|
$canJoin = $current !== null
|
|
&& !$tour->is_cancelled
|
|
&& !\App\Models\Tour::hasParticipant((int) $tour->id, (int) $current->id)
|
|
&& \App\Models\Tour::hasSpace((int) $tour->id);
|
|
|
|
$showJoinButton = $canJoin;
|
|
$showGallery = true;
|
|
$isPast = false;
|
|
?>
|
|
<div class="container tour-detail">
|
|
<div class="row">
|
|
<div class="col-12 col-lg-8">
|
|
<?php require __DIR__ . '/partials/detail_card.php'; ?>
|
|
</div>
|
|
|
|
<aside class="col-12 col-lg-4">
|
|
<section class="tour-side-card">
|
|
<h2 class="tour-side-title">Tour-Chat</h2>
|
|
<a href="/tour/<?= e($tour->id) ?>/chat" class="btn btn-primary btn-block">
|
|
<i class="fas fa-comments" aria-hidden="true"></i>
|
|
Chat öffnen
|
|
<?php if (($chatUnread ?? 0) > 0): ?>
|
|
<span class="badge badge-light ml-1"><?= e(($chatUnread ?? 0) > 99 ? '99+' : (string) $chatUnread) ?></span>
|
|
<?php endif; ?>
|
|
</a>
|
|
</section>
|
|
|
|
<section class="tour-side-card">
|
|
<h2 class="tour-side-title">
|
|
Teilnehmer
|
|
<span class="tour-side-count"><?= count($users) ?>/<?= (int) $tour->max_participants ?></span>
|
|
</h2>
|
|
|
|
<?php
|
|
// Zimmer aus der Zimmerliste aufbauen (auch freie), Buchungen zuordnen.
|
|
$roomsById = [];
|
|
|
|
foreach (($roomOptions ?? []) as $room) {
|
|
$roomsById[(string) $room['id']] = [
|
|
'name' => (string) $room['name'],
|
|
'capacity' => (int) $room['capacity'],
|
|
'people' => [],
|
|
];
|
|
}
|
|
|
|
$unassigned = [];
|
|
|
|
foreach (($rooms ?? []) as $row) {
|
|
if (empty($row->user_name)) {
|
|
continue;
|
|
}
|
|
|
|
$key = (string) ($row->room_id ?? '');
|
|
|
|
if (isset($roomsById[$key])) {
|
|
$roomsById[$key]['people'][] = $row;
|
|
} else {
|
|
$unassigned[] = $row;
|
|
}
|
|
}
|
|
|
|
// Einzelzimmer zuerst, danach Doppelzimmer; freie Zimmer je Sektion unten.
|
|
uasort($roomsById, static function (array $a, array $b): int {
|
|
if ($a['capacity'] !== $b['capacity']) {
|
|
return $a['capacity'] <=> $b['capacity'];
|
|
}
|
|
|
|
$aFree = count($a['people']) >= $a['capacity'];
|
|
$bFree = count($b['people']) >= $b['capacity'];
|
|
|
|
if ($aFree !== $bFree) {
|
|
return $aFree <=> $bFree;
|
|
}
|
|
|
|
return 0;
|
|
});
|
|
?>
|
|
|
|
<?php if ($roomsById === [] && $unassigned === []): ?>
|
|
<p class="tour-side-empty">Noch keine Anmeldungen.</p>
|
|
<?php endif; ?>
|
|
|
|
<?php foreach ($roomsById as $roomGroup): ?>
|
|
<div class="tour-room-group">
|
|
<div class="tour-room-head">
|
|
<div class="tour-room-heading">
|
|
<span class="tour-room-name"><?= e($roomGroup['name']) ?></span>
|
|
<span class="tour-room-meta"><?= count($roomGroup['people']) ?>/<?= $roomGroup['capacity'] ?></span>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($roomGroup['people'] === []): ?>
|
|
<p class="tour-side-empty">frei</p>
|
|
<?php else: ?>
|
|
<ul class="tour-person-list">
|
|
<?php foreach ($roomGroup['people'] as $participant): ?>
|
|
<li class="tour-person">
|
|
<span class="tour-person-name">
|
|
<i class="fas fa-biking" aria-hidden="true"></i>
|
|
<?= e($participant->user_name) ?>
|
|
</span>
|
|
<?php if ($canManage && !empty($participant->user_id)): ?>
|
|
<form action="/tour/<?= e($tour->id) ?>/cancelBookingAdmin/<?= e($participant->user_id) ?>" method="POST">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" class="tour-person-remove" title="Anmeldung entfernen"
|
|
aria-label="Anmeldung von <?= e($participant->user_name) ?> entfernen">
|
|
<i class="fas fa-times" aria-hidden="true"></i>
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
|
|
<?php if ($unassigned !== []): ?>
|
|
<div class="tour-room-group is-unassigned">
|
|
<div class="tour-room-head">
|
|
<div class="tour-room-heading">
|
|
<span class="tour-room-name">Ohne Zimmer</span>
|
|
<span class="tour-room-meta"><?= count($unassigned) ?></span>
|
|
</div>
|
|
</div>
|
|
|
|
<ul class="tour-person-list">
|
|
<?php foreach ($unassigned as $participant): ?>
|
|
<li class="tour-person">
|
|
<span class="tour-person-name">
|
|
<i class="fas fa-biking" aria-hidden="true"></i>
|
|
<?= e($participant->user_name) ?>
|
|
</span>
|
|
<?php if ($canManage && !empty($participant->user_id)): ?>
|
|
<form action="/tour/<?= e($tour->id) ?>/cancelBookingAdmin/<?= e($participant->user_id) ?>" method="POST">
|
|
<?= csrf_field() ?>
|
|
<button type="submit" class="tour-person-remove" title="Anmeldung entfernen"
|
|
aria-label="Anmeldung von <?= e($participant->user_name) ?> entfernen">
|
|
<i class="fas fa-times" aria-hidden="true"></i>
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<?php if ($canManage): ?>
|
|
<section class="tour-side-card">
|
|
<h2 class="tour-side-title">Organisation</h2>
|
|
<div class="tour-side-actions">
|
|
<a class="btn btn-outline-light btn-block" href="/tour/<?= e($tour->id) ?>/edit">
|
|
<i class="fas fa-pen" aria-hidden="true"></i> Tour bearbeiten
|
|
</a>
|
|
<a class="btn btn-outline-light btn-block" href="/tour">
|
|
<i class="fas fa-list" aria-hidden="true"></i> Zur Tourenliste
|
|
</a>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
</aside>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($canJoin): ?>
|
|
<div id="myModal" class="modal tour-modal">
|
|
<div class="modal-content tour-modal-content">
|
|
<span class="close" aria-label="Schließen">×</span>
|
|
<h2 class="tour-modal-title">Zimmer wählen</h2>
|
|
<p class="tour-modal-hint">Wähle das Zimmer, das du buchen möchtest.</p>
|
|
|
|
<div class="tour-modal-rooms">
|
|
<?php foreach (($roomOptions ?? []) as $room): ?>
|
|
<?php $free = (int) $room['capacity'] - (int) $room['booked']; ?>
|
|
<form class="booking_form tour-modal-room" action="/tour/<?= e($tour->id) ?>/join/<?= e($room['id']) ?>" method="POST">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="user_id" value="<?= e($current->id ?? '') ?>">
|
|
<span class="tour-modal-room-name"><?= e($room['name']) ?></span>
|
|
<span class="tour-modal-room-meta">
|
|
<?= (int) $room['capacity'] ?> Bett<?= (int) $room['capacity'] === 1 ? '' : 'en' ?>
|
|
· <?= max(0, $free) ?> frei
|
|
</span>
|
|
<button type="submit" class="btn btn-success btn-sm" <?= $free <= 0 ? 'disabled' : '' ?>>
|
|
<?= $free <= 0 ? 'voll' : 'Buchen' ?>
|
|
</button>
|
|
</form>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<script>
|
|
(function () {
|
|
var modal = document.getElementById('myModal');
|
|
var btn = document.getElementById('myBtn');
|
|
|
|
if (!modal || !btn) {
|
|
return;
|
|
}
|
|
|
|
var closeBtn = modal.querySelector('.close');
|
|
|
|
btn.addEventListener('click', function (event) {
|
|
event.preventDefault();
|
|
modal.style.display = 'block';
|
|
});
|
|
|
|
if (closeBtn) {
|
|
closeBtn.addEventListener('click', function (event) {
|
|
event.preventDefault();
|
|
modal.style.display = 'none';
|
|
});
|
|
}
|
|
|
|
modal.addEventListener('click', function (event) {
|
|
if (event.target === modal) {
|
|
modal.style.display = 'none';
|
|
}
|
|
});
|
|
})();
|
|
</script>
|