Skip to content

Commit

Permalink
Bugfix: Error when creating booking option templates with teachers, d…
Browse files Browse the repository at this point in the history
…ates and addtocalendar active (fixes #766)
  • Loading branch information
ibernhardf committed Dec 16, 2024
1 parent ff7082d commit a2fd227
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions classes/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,20 @@ public function __construct($cmid, $optionid, $userid, $type, $optiondateid = 0,
$DB->update_record('booking_userevents', $userevent);
}
}
} else {
echo "ERROR: Calendar entry for option date could not be created.";
}
/* TODO: Currently, dates might not be saved for teachers if the optiondates are not already saved.
We need to make sure, that dates are also saved for teachers, even if we newly create an option.
We might need a new MOD_BOOKING_EXECUTION_POSTSAVE_AFTER for this, so this happens AFTER the dates
have been created. */
} else if ($settings->addtocalendar == 1) {
if ($optiondate = $DB->get_record("booking_optiondates", ["id" => $optiondateid])) {
$newcalendarid = self::booking_optiondate_add_to_cal($cmid, $optionid,
$optiondate, $settings->calendarid, 0, 1);
} else {
echo "ERROR: Calendar entry for option date could not be created.";
}
/* TODO: Currently, dates might not be saved for teachers if the optiondates are not already saved.
We need to make sure, that dates are also saved for teachers, even if we newly create an option.
We might need a new MOD_BOOKING_EXECUTION_POSTSAVE_AFTER for this, so this happens AFTER the dates
have been created. */
}
break;

Expand Down
7 changes: 7 additions & 0 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,14 @@ public static function teacher_added(\mod_booking\event\teacher_added $event) {
}
$teacherid = $event->relateduserid;
$cmid = $event->contextinstanceid;

// For templates, we do not create calendar events for teachers (fixes #766).
if (empty($cmid)) {
return;
}

$settings = singleton_service::get_instance_of_booking_option_settings($optionid);

// Create calendar events for the newly added teacher.
foreach ($settings->sessions as $session) {
new calendar($cmid, $optionid, $teacherid,
Expand Down

0 comments on commit a2fd227

Please sign in to comment.