]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15494 - No allowance for the possibility that something might go wrong when proce...
authortjhunt <tjhunt>
Tue, 1 Jul 2008 13:34:09 +0000 (13:34 +0000)
committertjhunt <tjhunt>
Tue, 1 Jul 2008 13:34:09 +0000 (13:34 +0000)
lang/en_utf8/question.php
lib/questionlib.php
mod/quiz/attempt.php
question/preview.php
question/type/description/questiontype.php

index 02880bb7c941307807a060a1171313bfd3b88d87..dc8163ccea234d07715cea18d549402f20970b2e 100644 (file)
@@ -70,6 +70,7 @@ $string['errorfilecannotbemoved'] = 'Error cannot move file $a.';
 $string['errorfileschanged'] = 'Error files linked to from questions have changed since form was displayed.';
 $string['errormanualgradeoutofrange'] = 'The grade $a->grade is not between 0 and $a->maxgrade for question $a->name. The score and comment have not been saved.';
 $string['errormovingquestions'] = 'Error while moving questions with ids $a.';
+$string['errorprocessingresponses'] = 'An error occurred while processing your responses.';
 $string['errorsavingcomment'] = 'Error saving the comment for question $a->name in the database.';
 $string['errorupdatingattempt'] = 'Error updating attempt $a->id in the database.';
 $string['emptyxml'] = 'Unkown error - empty imsmanifest.xml';
index 4bb34256a374a58d9c2171dfee89626476f3e21a..d0c1028bce428e98d2cef31e3e0be7307e5cf071 100644 (file)
@@ -1290,7 +1290,6 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
 /**
 * Processes an array of student responses, grading and saving them as appropriate
 *
-* @return boolean         Indicates success/failure
 * @param object $question Full question object, passed by reference
 * @param object $state    Full state object, passed by reference
 * @param object $action   object with the fields ->responses which
@@ -1301,6 +1300,7 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
 * @param object $cmoptions
 * @param object $attempt  The attempt is passed by reference so that
 *                         during grading its ->sumgrades field can be updated
+* @return boolean         Indicates success/failure
 */
 function question_process_responses(&$question, &$state, $action, $cmoptions, &$attempt) {
     global $QTYPES;
@@ -1361,7 +1361,9 @@ function question_process_responses(&$question, &$state, $action, $cmoptions, &$
 
     if (!question_isgradingevent($action->event)) {
         // Grade the response but don't update the overall grade
-        $QTYPES[$question->qtype]->grade_responses($question, $state, $cmoptions);
+        if (!$QTYPES[$question->qtype]->grade_responses($question, $state, $cmoptions)) {
+            return false;
+        }
 
         // Temporary hack because question types are not given enough control over what is going
         // on. Used by Opaque questions.
@@ -1397,8 +1399,10 @@ function question_process_responses(&$question, &$state, $action, $cmoptions, &$
         // If we did not find a duplicate or if the attempt is closing, perform grading
         if ((!$sameresponses and QUESTION_EVENTDUPLICATE != $state->event) or
                 QUESTION_EVENTCLOSE == $action->event) {
+            if (!$QTYPES[$question->qtype]->grade_responses($question, $state, $cmoptions)) {
+                return false;
+            }
 
-            $QTYPES[$question->qtype]->grade_responses($question, $state, $cmoptions);
             // Calculate overall grade using correct penalty method
             question_apply_penalty_and_timelimit($question, $state, $attempt, $cmoptions);
         }
index e8735525cf31478fb60b24115bbe90e8252183be..b99f4c1897a78d1d421404463d19082d3b0c4ab5 100644 (file)
 
     /// Process each question in turn
         $questionidarray = explode(',', $questionids);
+        $success = true;
         foreach($questionidarray as $i) {
             if (!isset($actions[$i])) {
                 $actions[$i]->responses = array('' => '');
                 $actions[$i]->event = QUESTION_EVENTOPEN;
             }
             $actions[$i]->timestamp = $timenow;
-            question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt);
-            save_question_session($questions[$i], $states[$i]);
+            if (question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt)) {
+                save_question_session($questions[$i], $states[$i]);
+            } else {
+                $success = false;
+            }
+        }
+
+        if (!$success) {
+            $pagebit = '';
+            if ($page) {
+                $pagebit = '&amp;page=' . $page;
+            }
+            print_error('errorprocessingresponses', 'question',
+                    $CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id . $pagebit);
         }
 
         $attempt->timemodified = $timenow;
         $attempt->timefinish = $timenow;
 
     /// Move each question to the closed state.
+        $success = true;
         foreach ($questions as $key => $question) {
             $action->event = QUESTION_EVENTCLOSE;
             $action->responses = $states[$key]->responses;
             $action->timestamp = $states[$key]->timestamp;
-            question_process_responses($question, $states[$key], $action, $quiz, $attempt);
-            save_question_session($question, $states[$key]);
+            if (question_process_responses($question, $closestates[$key], $action, $quiz, $attempt)) {
+                save_question_session($question, $closestates[$key]);
+            } else {
+                $success = false;
+            }
+        }
+
+        if (!$success) {
+            $pagebit = '';
+            if ($page) {
+                $pagebit = '&amp;page=' . $page;
+            }
+            print_error('errorprocessingresponses', 'question',
+                    $CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id . $pagebit);
         }
 
     /// Log the end of this attempt.
index c8bc1516b6b64e01b77525cce9120a292a995d5b..9243c6c1153314dd5f321e3b078e29eaab606a09 100644 (file)
         }
         if ($actions = question_extract_responses($questions, $form, $event)) {
             $actions[$id]->timestamp = 0; // We do not care about timelimits here
-            question_process_responses($questions[$id], $curstate, $actions[$id], $quiz, $attempt);
+            if (!question_process_responses($questions[$id], $curstate, $actions[$id], $quiz, $attempt)) {
+                unset($SESSION->quizpreview);
+                print_error('errorprocessingresponses', 'question', $url->out());
+            }
             if (!$curstate->changed) {
                 // Update the current state rather than creating a new one
                 $historylength--;
index 6dfe2e275043c50d00e46b7d60d077806e2eefbc..be723c95f1e319af4131e3d63c6201371d4dbaad 100644 (file)
@@ -87,6 +87,7 @@ class description_qtype extends default_questiontype {
     function grade_responses(&$question, &$state, $cmoptions) {
         $state->raw_grade = 0;
         $state->penalty = 0;
+        return true;
     }
 
 }