From 7a6f4066cee03e8db752a66d667d91b9b28f9ea5 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Tue, 19 Jun 2007 22:17:47 +0000 Subject: [PATCH] MDL-6043 - Implement course reset function for quizzes. --- lang/en_utf8/quiz.php | 4 ++++ mod/quiz/lib.php | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 51f855c350..bfb37665f8 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 d1e3f9e9be..58bcce8fe8 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 '
', get_string('deletingquestionattempts', 'quiz'); + $divider = ': '; + } + foreach ($attemptids as $attemptid) { + delete_attempt($attemptid->uniqueid); + if ($showfeedback) { + echo $divider, $attemptid->uniqueid; + $divider = ', '; + } + } + if ($showfeedback) { + echo "

\n"; + } + } + if (delete_records_select('quiz_grades', $conditiononquizids) && $showfeedback) { + notify(get_string('gradesdeleted','quiz'), 'notifysuccess'); + } + if (delete_records_select('quiz_attempts', $conditiononquizids) && $showfeedback) { + notify(get_string('attemptsdeleted','quiz'), 'notifysuccess'); + } +} ?> \ No newline at end of file -- 2.39.5