From e7e9d06bf3ebc29085b6e87f265252ef5844bced Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Wed, 7 Sep 2016 14:29:13 +0800 Subject: [PATCH] MDL-41174 mod_workshop: Added workshop_refresh_events This function was missing from this activity. --- mod/workshop/lib.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index c1e9eae1cc1..8af75c2a676 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -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.