From c51dc77c17797709f654016002b2959c95e437a1 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 2 Feb 2017 20:49:03 +1300 Subject: [PATCH] Fixes #241 convert deprecated hook to observer. --- classes/observer.php | 57 ++++++++++++++++++++++++++++++++++++++++++++ db/events.php | 34 ++++++++++++++++++++++++++ lib.php | 20 ---------------- version.php | 2 +- 4 files changed, 92 insertions(+), 21 deletions(-) create mode 100644 classes/observer.php create mode 100644 db/events.php diff --git a/classes/observer.php b/classes/observer.php new file mode 100644 index 0000000..16804a8 --- /dev/null +++ b/classes/observer.php @@ -0,0 +1,57 @@ +. + +/** + * Event observers supported by this module + * + * @package mod_attendance + * @copyright 2017 Dan Marsden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Event observers supported by this module + * + * @package mod_attendance + * @copyright 2017 Dan Marsden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_attendance_observer { + + /** + * Observer for the event course_content_deleted - delete all attendance stuff. + * + * @param \core\event\course_content_deleted $event + */ + public static function course_content_deleted(\core\event\course_content_deleted $event) { + global $DB; + + $attids = array_keys($DB->get_records('attendance', array('course' => $event->objectid), '', 'id')); + $sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id')); + if (attendance_existing_calendar_events_ids($sessids)) { + attendance_delete_calendar_events($sessids); + } + if ($sessids) { + $DB->delete_records_list('attendance_log', 'sessionid', $sessids); + } + if ($attids) { + $DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); + $DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); + } + } +} diff --git a/db/events.php b/db/events.php new file mode 100644 index 0000000..afe87a6 --- /dev/null +++ b/db/events.php @@ -0,0 +1,34 @@ +. + +/** + * Attendance event handler definition. + * + * @package mod_attendance + * @category event + * @copyright 2017 Dan Marsden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// List of observers. +$observers = array( + + array( + 'eventname' => '\core\event\course_content_deleted', + 'callback' => 'mod_attendance_observer::course_content_deleted', + ), + +); diff --git a/lib.php b/lib.php index e5ab12c..e3d6163 100644 --- a/lib.php +++ b/lib.php @@ -120,26 +120,6 @@ function attendance_delete_instance($id) { return true; } -function attendance_delete_course($course, $feedback=true) { - global $DB; - - $attids = array_keys($DB->get_records('attendance', array('course' => $course->id), '', 'id')); - $sessids = array_keys($DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id')); - if (attendance_existing_calendar_events_ids($sessids)) { - attendance_delete_calendar_events($sessids); - } - if ($sessids) { - $DB->delete_records_list('attendance_log', 'sessionid', $sessids); - } - if ($attids) { - $DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); - $DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); - } - $DB->delete_records('attendance', array('course' => $course->id)); - - return true; -} - /** * Called by course/reset.php * @param $mform form passed by reference diff --git a/version.php b/version.php index b9ce0a8..79d9f6f 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2017020202; +$plugin->version = 2017020203; $plugin->requires = 2016111800; $plugin->release = '3.2.3'; $plugin->maturity = MATURITY_STABLE;