diff --git a/mod/lesson/pagetypes/multichoice.php b/mod/lesson/pagetypes/multichoice.php index 37b6a8d9481..38d314cf8f0 100644 --- a/mod/lesson/pagetypes/multichoice.php +++ b/mod/lesson/pagetypes/multichoice.php @@ -178,71 +178,49 @@ class lesson_page_type_multichoice extends lesson_page { } $correctpageid = null; $wrongpageid = null; - // this is for custom scores. If score on answer is positive, it is correct - if ($this->lesson->custom) { - $ncorrect = 0; - $nhits = 0; - foreach ($answers as $answer) { - if ($answer->score > 0) { - $ncorrect++; - foreach ($studentanswers as $answerid) { - if ($answerid == $answer->id) { - $nhits++; + // Iterate over all the possible answers. + foreach ($answers as $answer) { + if ($this->lesson->custom) { + $iscorrectanswer = $answer->score > 0; + } else { + $iscorrectanswer = $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto); + } + + // Iterate over all the student answers to check if he selected the current possible answer. + foreach ($studentanswers as $answerid) { + if ($answerid == $answer->id) { + if ($iscorrectanswer) { + $nhits++; + } else { + // Always jump to the page related to the student's first wrong answer. + if (!isset($wrongpageid)) { + // Leave in its "raw" state - will be converted into a proper page id later. + $wrongpageid = $answer->jumpto; + } + // Save the answer id for scoring. + if ($wronganswerid == 0) { + $wronganswerid = $answer->id; } - } - // save the first jumpto page id, may be needed!... - if (!isset($correctpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $correctpageid = $answer->jumpto; - } - // save the answer id for scoring - if ($correctanswerid == 0) { - $correctanswerid = $answer->id; - } - } else { - // save the first jumpto page id, may be needed!... - if (!isset($wrongpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $wrongpageid = $answer->jumpto; - } - // save the answer id for scoring - if ($wronganswerid == 0) { - $wronganswerid = $answer->id; } } } - } else { - foreach ($answers as $answer) { - if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) { - $ncorrect++; - foreach ($studentanswers as $answerid) { - if ($answerid == $answer->id) { - $nhits++; - } - } - // save the first jumpto page id, may be needed!... - if (!isset($correctpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $correctpageid = $answer->jumpto; - } - // save the answer id for scoring - if ($correctanswerid == 0) { - $correctanswerid = $answer->id; - } - } else { - // save the first jumpto page id, may be needed!... - if (!isset($wrongpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $wrongpageid = $answer->jumpto; - } - // save the answer id for scoring - if ($wronganswerid == 0) { - $wronganswerid = $answer->id; - } + + if ($iscorrectanswer) { + $ncorrect++; + + // Save the first jumpto page id, may be needed! + if (!isset($correctpageid)) { + // Leave in its "raw" state - will be converted into a proper page id later. + $correctpageid = $answer->jumpto; + } + // Save the answer id for scoring. + if ($correctanswerid == 0) { + $correctanswerid = $answer->id; } } } + if ((count($studentanswers) == $ncorrect) and ($nhits == $ncorrect)) { $result->correctanswer = true; $result->response = implode('
', $responses);