Skip to content
Snippets Groups Projects
Commit 89c22235 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

ensure booking is valid before updating event, fixes #1300

Closes #1300

Merge request studip/studip!798
parent 3e3c02f3
No related branches found
No related tags found
No related merge requests found
......@@ -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}";
}));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment