diff --git a/lib/models/ConsultationSlot.php b/lib/models/ConsultationSlot.php index 63c730aa9cd3596df0505abc672b567f1b762ae5..546f72f4f57958d44f9f2a438bd79448aee50ce7 100644 --- a/lib/models/ConsultationSlot.php +++ b/lib/models/ConsultationSlot.php @@ -204,11 +204,19 @@ class ConsultationSlot extends SimpleORMap // If no range is associated, remove the event if (!$this->block->range) { - return $this->removeEvent(); + $this->removeEvent(); + return; } - if (count($this->bookings) === 0 && !$this->block->calendar_events) { - return $this->removeEvent(); + $bookings = $this->bookings->filter(function (ConsultationBooking $booking) { + return !$booking->isDeleted() + && $booking->user; + }); + + + if (count($bookings) === 0 && !$this->block->calendar_events) { + $this->removeEvent(); + return; } $event = $this->event; @@ -221,11 +229,11 @@ class ConsultationSlot extends SimpleORMap setTempLanguage($this->block->range_id); - if (count($this->bookings) > 0) { + if (count($bookings) > 0) { $event->category_intern = 1; - if (count($this->bookings) === 1) { - $booking = $this->bookings->first(); + if (count($bookings) === 1) { + $booking = $bookings->first(); $event->summary = sprintf( _('Termin mit %s'), @@ -235,9 +243,9 @@ class ConsultationSlot extends SimpleORMap } else { $event->summary = sprintf( _('Termin mit %u Personen'), - count($this->bookings) + count($bookings) ); - $event->description = implode("\n\n----\n\n", $this->bookings->map(function ($booking) { + $event->description = implode("\n\n----\n\n", $bookings->map(function ($booking) { return "- {$booking->user->getFullName()}:\n{$booking->reason}"; })); }