From e260bf1c122737b07b7ca38a29483ec3505617da Mon Sep 17 00:00:00 2001 From: gbateson Date: Tue, 27 Jan 2009 08:37:54 +0000 Subject: [PATCH] MDL-17679: implement course reset for HotPot module (thanks to Albert Gasset) --- lang/en_utf8/hotpot.php | 2 ++ mod/hotpot/lib.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lang/en_utf8/hotpot.php b/lang/en_utf8/hotpot.php index ddc5fb650adbb..39d890f45f27d 100644 --- a/lang/en_utf8/hotpot.php +++ b/lang/en_utf8/hotpot.php @@ -203,4 +203,6 @@ // error messages (attempt.php) $string['error_invalidquiztype'] = 'Quiz type is missing or invalid'; + +$string['deleteallattempts'] = 'Delete all attempts'; ?> diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index 4d5e7b06f7c3e..b24271d9e9f63 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -2433,5 +2433,35 @@ function getDir(s) { } print ''.$html.''; } +/** + * Called by course/reset.php + * @param $mform form passed by reference + */ +function hotpot_reset_course_form($course) { + print_checkbox('reset_hotpot_deleteallattempts', 1, true, get_string('deleteallattempts', 'hotpot'), '', ''); echo '
'; +} +function hotpot_delete_userdata($data, $showfeedback=true) { + global $CFG; + + if (!empty($data->reset_hotpot_deleteallattempts)) { + $hotpotids = "SELECT h.id FROM {$CFG->prefix}hotpot h WHERE h.course={$data->courseid}"; + $attemptids = "SELECT a.id FROM {$CFG->prefix}hotpot_attempts a WHERE a.hotpot in ($hotpotids)"; + + delete_records_select('hotpot_responses', "attempt in ($attemptids)"); + delete_records_select('hotpot_details', "attempt in ($attemptids)"); + delete_records_select('hotpot_attempts', "hotpot IN ($hotpotids)"); + + if ($showfeedback) { + notify(get_string('reset').': '.get_string('modulenameplural', 'hotpot'), 'notifysuccess'); + } + } +} + +/** + * Course reset form defaults. + */ +function hotpot_reset_course_form_defaults($course) { + return array('reset_hotpot_deleteallattempts' => 1); +} ?>