Browse Source

Fixes #241 convert deprecated hook to observer.

MOODLE_33_STABLE
Dan Marsden 8 years ago
parent
commit
c51dc77c17
  1. 57
      classes/observer.php
  2. 34
      db/events.php
  3. 20
      lib.php
  4. 2
      version.php

57
classes/observer.php

@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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);
}
}
}

34
db/events.php

@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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',
),
);

20
lib.php

@ -120,26 +120,6 @@ function attendance_delete_instance($id) {
return true; 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 * Called by course/reset.php
* @param $mform form passed by reference * @param $mform form passed by reference

2
version.php

@ -23,7 +23,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017020202; $plugin->version = 2017020203;
$plugin->requires = 2016111800; $plugin->requires = 2016111800;
$plugin->release = '3.2.3'; $plugin->release = '3.2.3';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;

Loading…
Cancel
Save