diff --git a/course/rest.php b/course/rest.php index 675f3671e96..d25b9fc9839 100644 --- a/course/rest.php +++ b/course/rest.php @@ -188,6 +188,12 @@ switch($requestmethod) { $grademodule->modname = $cm->modname; grade_update_mod_grades($grademodule); + // Update calendar events with the new name. + $refresheventsfunction = $cm->modname . '_refresh_events'; + if (function_exists($refresheventsfunction)) { + call_user_func($refresheventsfunction, $cm->course); + } + // We need to return strings after they've been through filters for multilang $stringoptions = new stdClass; $stringoptions->context = $coursecontext; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 6fb41e3e2e7..13d343485d1 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -263,6 +263,40 @@ function workshop_delete_instance($id) { return true; } +/** + * This standard function will check all instances of this module + * and make sure there are up-to-date events created for each of them. + * If courseid = 0, then every workshop event in the site is checked, else + * only workshop events belonging to the course specified are checked. + * + * @param integer $courseid The Course ID. + * @return bool Returns true if the calendar events were successfully updated. + */ +function workshop_refresh_events($courseid = 0) { + global $DB; + + if ($courseid) { + // Make sure that the course id is numeric. + if (!is_numeric($courseid)) { + return false; + } + if (!$workshops = $DB->get_records('workshop', array('course' => $courseid))) { + return false; + } + } else { + if (!$workshops = $DB->get_records('workshop')) { + return false; + } + } + foreach ($workshops as $workshop) { + if (!$cm = get_coursemodule_from_instance('workshop', $workshop->id, $courseid, false)) { + continue; + } + workshop_calendar_update($workshop, $cm->id); + } + return true; +} + /** * List the actions that correspond to a view of this module. * This is used by the participation report.