From 8fef8bc3c46650f9bdcb9beffeafdd01ef8fe76f Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms Date: Tue, 25 Jun 2024 12:35:18 +0000 Subject: fixes #4320, fixes #1871 Closes #4320 and #1871 Merge request studip/studip!3125 --- app/controllers/consultation/admin.php | 26 +++++++++++++------ app/views/consultation/overview/index.php | 2 +- app/views/consultation/overview/ungrouped.php | 2 +- lib/models/ConsultationSlot.php | 22 ++++++++++------ resources/vue/components/ConsultationCreator.vue | 32 ++++++++++++------------ 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/app/controllers/consultation/admin.php b/app/controllers/consultation/admin.php index 8ee7575..13451d2 100644 --- a/app/controllers/consultation/admin.php +++ b/app/controllers/consultation/admin.php @@ -165,13 +165,19 @@ class Consultation_AdminController extends ConsultationController CSRFProtection::verifyUnsafeRequest(); try { + $interval = Request::int('interval'); $start = $this->getDateAndTime('start'); - $end = $this->getDateAndTime('end'); + $end = $this->getDateAndTime($interval === 0 ? 'start' : 'end', 'end'); if (date('Hi', $end) <= date('Hi', $start)) { throw new InvalidArgumentException(_('Die Endzeit liegt vor der Startzeit!')); } + $dow = Request::int('day-of-week'); + if ($interval === 0) { + $dow = date('w', $start); + } + // Determine duration of a slot and pause times $duration = Request::int('duration'); $pause_time = Request::bool('pause') ? Request::int('pause_time') : null; @@ -187,8 +193,8 @@ class Consultation_AdminController extends ConsultationController $slot_count = ConsultationBlock::countSlots( $start, $end, - Request::int('day-of-week'), - Request::int('interval'), + $dow, + $interval, $duration, $pause_time, $pause_duration @@ -202,8 +208,8 @@ class Consultation_AdminController extends ConsultationController $this->range, $start, $end, - Request::int('day-of-week'), - Request::int('interval') + $dow, + $interval ); $stored = 0; @@ -872,15 +878,19 @@ class Consultation_AdminController extends ConsultationController } } - private function getDateAndTime($index) + private function getDateAndTime(string $index, string $index_time = null) { - if (!Request::submitted("{$index}-date") || !Request::submitted("{$index}-time")) { + if ($index_time === null) { + $index_time = $index; + } + + if (!Request::submitted("{$index}-date") || !Request::submitted("{$index_time}-time")) { throw new Exception("Date with index '{$index}' was not submitted properly"); } return strtotime(implode(' ', [ Request::get("{$index}-date"), - Request::get("{$index}-time") + Request::get("{$index_time}-time") ])); } diff --git a/app/views/consultation/overview/index.php b/app/views/consultation/overview/index.php index dcad608..ef7f208 100644 --- a/app/views/consultation/overview/index.php +++ b/app/views/consultation/overview/index.php @@ -61,7 +61,7 @@ asImg(tooltip2(_('Termin reservieren'))) ?> - asImg(tooltip2(_('Dieser Termin ist für Buchungen gesperrt.'))) ?> + asImg(tooltip2(_('Dieser Termin ist für Buchungen gesperrt.'))) ?> diff --git a/app/views/consultation/overview/ungrouped.php b/app/views/consultation/overview/ungrouped.php index 147f588..c9eb519 100644 --- a/app/views/consultation/overview/ungrouped.php +++ b/app/views/consultation/overview/ungrouped.php @@ -91,7 +91,7 @@ asImg(tooltip2(_('Termin reservieren'))) ?> - asImg(tooltip2(_('Dieser Termin ist für Buchungen gesperrt.'))) ?> + asImg(tooltip2(_('Dieser Termin ist für Buchungen gesperrt.'))) ?> diff --git a/lib/models/ConsultationSlot.php b/lib/models/ConsultationSlot.php index c46e47c..1e935c5 100644 --- a/lib/models/ConsultationSlot.php +++ b/lib/models/ConsultationSlot.php @@ -19,6 +19,7 @@ * @property SimpleORMapCollection|ConsultationEvent[] $events has_many ConsultationEvent * @property ConsultationBlock $block belongs_to ConsultationBlock * @property ConsultationSlot|null $previous_slot has_one ConsultationSlot + * @property ConsultationSlot|null $next_slot has_one ConsultationSlot * @property-read mixed $has_bookings additional field * @property-read mixed $is_expired additional field */ @@ -48,8 +49,12 @@ class ConsultationSlot extends SimpleORMap 'on_delete' => 'delete', ]; $config['has_one']['previous_slot'] = [ - 'class_name' => ConsultationSlot::class, - 'foreign_key' => 'previous_slot_id', + 'class_name' => ConsultationSlot::class, + 'foreign_key' => 'previous_slot_id', + ]; + $config['has_one']['next_slot'] = [ + 'class_name' => ConsultationSlot::class, + 'assoc_func' => 'findOneByPrevious_slot_id', ]; $config['registered_callbacks']['before_create'][] = function (ConsultationSlot $slot) { @@ -183,14 +188,15 @@ class ConsultationSlot extends SimpleORMap /** * Returns whether the slot is bookable for the given user_id */ - public function isBookable(?string $user_id = null): bool + public function isBookable(): bool { - return !$this->isOccupied($user_id) + return !$this->isOccupied() && !$this->isLocked() - && !( - $this->block->consecutive - && $this->previous_slot - && !$this->previous_slot->isOccupied() + && ( + !$this->block->consecutive + || !$this->block->has_bookings + || ($this->previous_slot && $this->previous_slot->isOccupied()) + || ($this->next_slot && $this->next_slot->isOccupied()) ); } diff --git a/resources/vue/components/ConsultationCreator.vue b/resources/vue/components/ConsultationCreator.vue index 375e98a..73c3cb1 100644 --- a/resources/vue/components/ConsultationCreator.vue +++ b/resources/vue/components/ConsultationCreator.vue @@ -30,7 +30,7 @@