MDL-44449 quiz access rules should have a delete hook.

So they can clean up their settings when the quiz is deleted.

See
https://github.com/moodleou/moodle-quizaccess_honestycheck/commit/babf149c2cc6dd734c272cd332b2032cc19db7d8
for an example of using this.
This commit is contained in:
Tim Hunt
2014-05-19 16:59:21 +01:00
parent ba05f573ca
commit 969c26def0
4 changed files with 47 additions and 7 deletions
+22 -4
View File
@@ -31,8 +31,9 @@ defined('MOODLE_INTERNAL') || die();
* This class keeps track of the various access rules that apply to a particular
* quiz, with convinient methods for seeing whether access is allowed.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.2
*/
class quiz_access_manager {
/** @var quiz the quiz settings object. */
@@ -144,11 +145,11 @@ class quiz_access_manager {
/**
* Save any submitted settings when the quiz settings form is submitted.
*
* Note that the standard plugins do not use this mechanism, becuase all their
* Note that the standard plugins do not use this mechanism because their
* settings are stored in the quiz table.
*
* @param object $quiz the data from the quiz form, including $quiz->id
* which is the is of the quiz being saved.
* which is the id of the quiz being saved.
*/
public static function save_settings($quiz) {
@@ -157,6 +158,23 @@ class quiz_access_manager {
}
}
/**
* Delete any rule-specific settings when the quiz is deleted.
*
* Note that the standard plugins do not use this mechanism because their
* settings are stored in the quiz table.
*
* @param object $quiz the data from the database, including $quiz->id
* which is the id of the quiz being deleted.
* @since Moodle 2.7.1, 2.6.4, 2.5.7
*/
public static function delete_settings($quiz) {
foreach (self::get_rule_classes() as $rule) {
$rule::delete_settings($quiz);
}
}
/**
* Build the SQL for loading all the access settings in one go.
* @param int $quizid the quiz id.
+15 -3
View File
@@ -38,8 +38,9 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
* as true) if access should be blocked. Slighly unnatural, but acutally the easist
* way to implement this.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.2
*/
abstract class quiz_access_rule_base {
/** @var stdClass the quiz settings. */
@@ -282,12 +283,23 @@ abstract class quiz_access_rule_base {
* Save any submitted settings when the quiz settings form is submitted. This
* is called from {@link quiz_after_add_or_update()} in lib.php.
* @param object $quiz the data from the quiz form, including $quiz->id
* which is the is of the quiz being saved.
* which is the id of the quiz being saved.
*/
public static function save_settings($quiz) {
// By default do nothing.
}
/**
* Delete any rule-specific settings when the quiz is deleted. This is called
* from {@link quiz_delete_instance()} in lib.php.
* @param object $quiz the data from the database, including $quiz->id
* which is the id of the quiz being deleted.
* @since Moodle 2.7.1, 2.6.4, 2.5.7
*/
public static function delete_settings($quiz) {
// By default do nothing.
}
/**
* Return the bits of SQL needed to load all the settings from all the access
* plugins in one DB query. The easiest way to understand what you need to do
+8
View File
@@ -2,16 +2,24 @@ This files describes API changes for quiz access rule plugins.
Overview of this plugin type at http://docs.moodle.org/dev/Quiz_access_rules
=== 2.8, 2.7.1, 2.6.4 and 2.5.7 ===
* New static method delete_settings for access rules, which is called when a
quiz is deleted.
=== 2.4 and 2.3.4 ===
* Replaced time_left() with new time_left_display() and end_time() functions.
=== 2.3 ===
* This plugin type now supports cron in the standard way. If required, Create a
lib.php file containing
function quizaccess_mypluginname_cron() {};
=== 2.2 ===
* This plugin type was new in Moodle 2.2!
+2
View File
@@ -173,6 +173,8 @@ function quiz_delete_instance($id) {
$DB->delete_records('quiz_question_instances', array('quiz' => $quiz->id));
$DB->delete_records('quiz_feedback', array('quizid' => $quiz->id));
quiz_access_manager::delete_settings($quiz);
$events = $DB->get_records('event', array('modulename' => 'quiz', 'instance' => $quiz->id));
foreach ($events as $event) {
$event = calendar_event::load($event);