diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php
index 51f855c3500..bfb37665f88 100644
--- a/lang/en_utf8/quiz.php
+++ b/lang/en_utf8/quiz.php
@@ -45,6 +45,7 @@ $string['attemptlast'] = 'Last attempt';
$string['attemptquiznow'] = 'Attempt quiz now';
$string['attempts'] = 'Attempts';
$string['attemptsallowed'] = 'Attempts allowed';
+$string['attemptsdeleted'] = 'Quiz attempts deleted';
$string['attemptselection'] = 'Select which attempts to analyze per user:';
$string['attemptsexist'] = 'You can no longer add or remove questions.';
$string['attemptsonly'] = 'Show only students with attempts';
@@ -132,6 +133,7 @@ $string['deleteattemptcheck'] = 'Are you absolutely sure you want to completely
$string['deletequestioncheck'] = 'Are you absolutely sure you want to delete \'$a\'?';
$string['deletequestionscheck'] = 'Are you absolutely sure you want to delete the following questions?
$a';
$string['deleteselected'] = 'Delete selected';
+$string['deletingquestionattempts'] = 'Deleting question attempts';
$string['description'] = 'Description';
$string['discrimination'] = 'Discrim. Index';
$string['displayoptions'] = 'Display options';
@@ -227,6 +229,7 @@ $string['gradeboundary'] = 'Grade boundary';
$string['gradeessays'] = 'Grade Essays';
$string['gradehighest'] = 'Highest grade';
$string['grademethod'] = 'Grading method';
+$string['gradesdeleted'] = 'Quiz grades deleted';
$string['gradesofar'] = '$a->method: $a->mygrade / $a->quizgrade.';
$string['gradingdetails'] = 'Marks for this submission: $a->raw/$a->max.';
$string['gradingdetailsadjustment'] = 'With previous penalties this gives $a->cur/$a->max.';
@@ -411,6 +414,7 @@ $string['regradingquestion'] = 'Regrading \"$a\".';
$string['regradingquiz'] = 'Regrading Quiz \"$a\"';
$string['relative'] = 'Relative';
$string['remove'] = 'Remove';
+$string['removeallquizattempts'] = 'Remove all quiz attempts';
$string['rename'] = 'Rename';
$string['renderingserverconnectfailed'] = 'The server $a failed to process an RQP request. Check that the URL is correct.';
$string['reordertool'] = 'Show the reordering tool';
diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php
index d1e3f9e9be6..58bcce8fe84 100644
--- a/mod/quiz/lib.php
+++ b/mod/quiz/lib.php
@@ -813,4 +813,57 @@ function quiz_question_list_instances($questionid) {
return array();
}
+/**
+ * Implementation of the function for printing the form elements that control
+ * whether the course reset functionality affects the quiz.
+ * @param $course The course id of the course the user is thinking of resetting.
+ */
+function quiz_reset_course_form($course) {
+ echo '
'; + print_checkbox('reset_quiz_attempts', 1, true, get_string('removeallquizattempts','quiz')); + echo '
'; +} + +/** + * Actual implementation of the rest coures functionality, delete all the + * quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is + * set and true. + * @param $data the data submitted from the reset course forum. + * @param $showfeedback whether to output progress information as the reset + * progresses. + */ +function quiz_delete_userdata($data, $showfeedback=true) { + global $CFG; + + if (empty($data->reset_quiz_attempts)) { + return; + } + + $conditiononquizids = 'quiz IN (SELECT id FROM ' . + $CFG->prefix . 'quiz q WHERE q.course = ' . $data->courseid . ')'; + + $attemptids = get_records_select('quiz_attempts', $conditiononquizids, '', 'id, uniqueid'); + if ($attemptids) { + if ($showfeedback) { + echo '