]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10689:
authorthepurpleblob <thepurpleblob>
Mon, 20 Aug 2007 10:06:57 +0000 (10:06 +0000)
committerthepurpleblob <thepurpleblob>
Mon, 20 Aug 2007 10:06:57 +0000 (10:06 +0000)
No questions imported if "stop on error" selected and there are invalid grades.

Merged from STABLE_18

question/format.php

index 0222c6c4b119e778a7fcb61d3030919ab1529715..ac0dcc75f2fca4d68036b1597b049b80a16253fb 100644 (file)
@@ -210,6 +210,42 @@ class qformat_default {
         $grades = get_grade_options();
         $gradeoptionsfull = $grades->gradeoptionsfull;
 
+        // check answer grades are valid
+        // (now need to do this here because of 'stop on error': MDL-10689)
+        $gradeerrors = 0;
+        $goodquestions = array();
+        foreach ($questions as $question) {
+            if (!empty($question->fraction) and (is_array($question->fraction))) {
+                $fractions = $question->fraction;
+                $answersvalid = true; // in case they are!
+                foreach ($fractions as $key => $fraction) {
+                    $newfraction = match_grade_options($gradeoptionsfull, $fraction, $this->matchgrades);
+                    if ($newfraction===false) {
+                        $answersvalid = false;
+                    }
+                    else {
+                        $fractions[$key] = $newfraction;
+                    }
+                }
+                if (!$answersvalid) {
+                    notify(get_string('matcherror', 'quiz'));
+                    ++$gradeerrors;
+                    continue;
+                }
+                else {
+                    $question->fraction = $fractions;
+                }
+            }
+            $goodquestions[] = $question;
+        }
+        $questions = $goodquestions;
+
+        // check for errors before we continue
+        if ($this->stoponerror and ($gradeerrors>0)) {
+            return false;
+        }
+
+        // count number of questions processed
         $count = 0;
 
         foreach ($questions as $question) {   // Process and store each question
@@ -234,28 +270,6 @@ class qformat_default {
 
             echo "<hr /><p><b>$count</b>. ".$this->format_question_text($question)."</p>";
 
-            // check for answer grades validity (must match fixed list of grades)
-            if (!empty($question->fraction) and (is_array($question->fraction))) {
-                $fractions = $question->fraction;
-                $answersvalid = true; // in case they are!
-                foreach ($fractions as $key => $fraction) {
-                    $newfraction = match_grade_options($gradeoptionsfull, $fraction, $this->matchgrades);
-                    if ($newfraction===false) {
-                        $answersvalid = false;
-                    }
-                    else {
-                        $fractions[$key] = $newfraction;
-                    }
-                }
-                if (!$answersvalid) {
-                    notify(get_string('matcherror', 'quiz'));
-                    continue;
-                }
-                else {
-                    $question->fraction = $fractions;
-                }
-            }
-
             $question->category = $this->category->id;
             $question->stamp = make_unique_id_code();  // Set the unique code (not to be changed)