]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17679: implement course reset for HotPot module (thanks to Albert Gasset)
authorgbateson <gbateson>
Tue, 27 Jan 2009 08:52:03 +0000 (08:52 +0000)
committergbateson <gbateson>
Tue, 27 Jan 2009 08:52:03 +0000 (08:52 +0000)
lang/en_utf8/hotpot.php
mod/hotpot/lib.php

index 7189a17908a52257bdb4769f88ac8d18f9ffc593..2c74688fd0651ca33443885cdea03b8e8e57985c 100644 (file)
@@ -28,6 +28,7 @@ $string['copytoclipboard'] = 'Copy to Clipboard';
 $string['correct'] = 'Correct';
 $string['deleteabandoned'] = 'Delete abandoned';
 $string['deleteabandonedcheck'] = 'Do you really want to delete all $a abandoned attempts?';
+$string['deleteallattempts'] = 'Delete all attempts';
 $string['displaycoursenext'] = 'Display Course page next';
 $string['displayhotpotnext'] = 'Display Hot Potatoes quiz next';
 $string['displayindexnext'] = 'Display HotPot index next';
index cb6541bb1357db313211460b546dbf7a93bf1328..f899b3d0f446eb934d957e1cb4a424c3f93dcd0f 100644 (file)
@@ -2529,4 +2529,48 @@ function hotpot_get_extra_capabilities() {
     return array('moodle/site:accessallgroups');
 }
 
+/**
+ * This function is used by the reset_course_userdata function in moodlelib.
+ * This function will remove all attempts from hotpot quizzes in the specified course.
+ * @param $data the data submitted from the reset course.
+ * @return array status array
+ */
+function hotpot_reset_userdata($data) {
+    global $CFG, $DB;
+    require_once($CFG->libdir.'/filelib.php');
+
+    $status = array();
+
+    if (!empty($data->reset_hotpot_deleteallattempts)) {
+
+        $hotpotids = 'SELECT h.id FROM {hotpot} h WHERE h.course='.$data->courseid;
+        $attemptids = 'SELECT a.id FROM {hotpot_attempts} a WHERE a.hotpot in ('.$hotpotids.')';
+
+        $DB->delete_records_select('hotpot_responses', "attempt in ($attemptids)");
+        $DB->delete_records_select('hotpot_details', "attempt in ($attemptids)");
+        $DB->delete_records_select('hotpot_attempts', "hotpot IN ($hotpotids)");
+
+        $status[] = array('component' => get_string('modulenameplural', 'hotpot'),
+                          'item' => get_string('deleteallattempts', 'hotpot'),
+                          'error' => false);
+    }
+
+    return $status;
+}
+
+/**
+ * Called by course/reset.php
+ * @param $mform form passed by reference
+ */
+function hotpot_reset_course_form_definition(&$mform) {
+    $mform->addElement('header', 'hotpotheader', get_string('modulenameplural', 'hotpot'));
+    $mform->addElement('checkbox', 'reset_hotpot_deleteallattempts', get_string('deleteallattempts', 'hotpot'));
+}
+
+/**
+ * Course reset form defaults.
+ */
+function hotpot_reset_course_form_defaults($course) {
+    return array('reset_hotpot_deleteallattempts' => 1);
+}
 ?>