Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-17679: implement course reset for HotPot module (thanks to Albert…
… Gasset)
  • Loading branch information
gbateson committed Jan 27, 2009
1 parent a951a3a commit 96ff525
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en_utf8/hotpot.php
Expand Up @@ -22,6 +22,7 @@
$string['correct'] = 'Correct'; $string['correct'] = 'Correct';
$string['deleteabandoned'] = 'Delete abandoned'; $string['deleteabandoned'] = 'Delete abandoned';
$string['deleteabandonedcheck'] = 'Do you really want to delete all $a abandoned attempts?'; $string['deleteabandonedcheck'] = 'Do you really want to delete all $a abandoned attempts?';
$string['deleteallattempts'] = 'Delete all attempts';
$string['displaycoursenext'] = 'Display Course page next'; $string['displaycoursenext'] = 'Display Course page next';
$string['displayhotpotnext'] = 'Display Hot Potatoes quiz next'; $string['displayhotpotnext'] = 'Display Hot Potatoes quiz next';
$string['displayindexnext'] = 'Display HotPot index next'; $string['displayindexnext'] = 'Display HotPot index next';
Expand Down
61 changes: 61 additions & 0 deletions mod/hotpot/lib.php
Expand Up @@ -2464,4 +2464,65 @@ function getDir(s) {
print '<span class="helplink">'.$html.'</span>'; print '<span class="helplink">'.$html.'</span>';
} }


/**
* 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;
require_once($CFG->libdir.'/filelib.php');

$status = array();

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)");

$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($course) {
print_checkbox('reset_hotpot_deleteallattempts', 1, true, get_string('deleteallattempts', 'hotpot'), '', ''); echo '<br />';
}
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);
}

?> ?>

0 comments on commit 96ff525

Please sign in to comment.