]> git.mjollnir.org Git - moodle.git/commitdiff
Not all questions have grades/fractions. Added check.
authorthepurpleblob <thepurpleblob>
Thu, 23 Mar 2006 11:12:54 +0000 (11:12 +0000)
committerthepurpleblob <thepurpleblob>
Thu, 23 Mar 2006 11:12:54 +0000 (11:12 +0000)
question/format.php

index e6b235439ddcb91c6b6b62f8a4ca6157e90e0d09..8af4a93f48fc2ead6162bc67f32e1c08cb1ceb5d 100644 (file)
@@ -69,23 +69,25 @@ class qformat_default {
 
             // check for answer grades validity (must match fixed list of grades)
             $fractions = $question->fraction;
-            $answersvalid = true; // in case they are!
-            foreach ($fractions as $key => $fraction) {
-                $newfraction = match_grade_options($gradeoptionsfull, $fraction, $matchgrades);
-                if ($newfraction===false) {
-                    $answersvalid = false;
+            if (!empty($fractions)) {
+                $answersvalid = true; // in case they are!
+                foreach ($fractions as $key => $fraction) {
+                    $newfraction = match_grade_options($gradeoptionsfull, $fraction, $matchgrades);
+                    if ($newfraction===false) {
+                        $answersvalid = false;
+                    }
+                    else {
+                        $fractions[$key] = $newfraction;
+                    }
+                }
+                if (!$answersvalid) {
+                    notify( get_string('matcherror','quiz') );
+                    continue;
                 }
                 else {
-                    $fractions[$key] = $newfraction;
+                    $question->fraction = $fractions;
                 }
             }
-            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)