From 2d52056f79945db0ca2ac1d3a486174d28320f6b Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Thu, 23 Mar 2006 11:12:54 +0000 Subject: [PATCH] Not all questions have grades/fractions. Added check. --- question/format.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/question/format.php b/question/format.php index e6b235439d..8af4a93f48 100644 --- a/question/format.php +++ b/question/format.php @@ -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) -- 2.39.5