From: thepurpleblob Date: Mon, 20 Aug 2007 10:06:57 +0000 (+0000) Subject: MDL-10689: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c1828e0b19d09272fa5c25f24c12babe7512b34f;p=moodle.git MDL-10689: No questions imported if "stop on error" selected and there are invalid grades. Merged from STABLE_18 --- diff --git a/question/format.php b/question/format.php index 0222c6c4b1..ac0dcc75f2 100644 --- a/question/format.php +++ b/question/format.php @@ -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 "

$count. ".$this->format_question_text($question)."

"; - // 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)