]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6043 - Implement course reset function for quizzes.
authortjhunt <tjhunt>
Tue, 19 Jun 2007 22:17:47 +0000 (22:17 +0000)
committertjhunt <tjhunt>
Tue, 19 Jun 2007 22:17:47 +0000 (22:17 +0000)
lang/en_utf8/quiz.php
mod/quiz/lib.php

index 51f855c3500698d348a1bcd9715b6f8ac7227e02..bfb37665f88246fcdb29f08c1efb0dc3da8e9139 100644 (file)
@@ -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?<br /><br />$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 <strong>$a->cur/$a->max</strong>.';
@@ -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';
index d1e3f9e9be618c2ae46cf1c01dc24de71a828e68..58bcce8fe84787467b2b3720fb43ab6795971db2 100644 (file)
@@ -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 '<p>';
+    print_checkbox('reset_quiz_attempts', 1, true, get_string('removeallquizattempts','quiz'));
+    echo '</p>';
+}
+
+/**
+ * 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 '<div class="notifysuccess">', get_string('deletingquestionattempts', 'quiz');
+            $divider = ': ';
+        }
+        foreach ($attemptids as $attemptid) {
+            delete_attempt($attemptid->uniqueid);
+            if ($showfeedback) {
+                echo $divider, $attemptid->uniqueid;
+                $divider = ', ';
+            }
+        }
+        if ($showfeedback) {
+            echo "</div><br />\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