MDL-41174 mod_workshop: Added workshop_refresh_events

This function was missing from this activity.
This commit is contained in:
Adrian Greeve 2016-09-07 14:29:13 +08:00
parent 7ceab0d993
commit 80753d3107

View File

@ -279,6 +279,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.