From 0b4ce29d8da8c43267be6853c19a664a45fc76fe Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 4 Aug 2006 12:28:39 +0000 Subject: [PATCH] Matching question would fill in the right answer after an incorrect attempt. --- question/type/match/questiontype.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index e8a7f563aa..3d1a48d3a2 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -235,6 +235,7 @@ class question_match_qtype extends default_questiontype { $correctanswers = $this->get_correct_responses($question, $state); $nameprefix = $question->name_prefix; $answers = array(); + $allanswers = array(); $answerids = array(); $responses = &$state->responses; @@ -242,23 +243,26 @@ class question_match_qtype extends default_questiontype { $formatoptions->noclean = true; $formatoptions->para = false; - // Prepare a list of answers, removing duplicates, and fix up the ids - // of any responses that point the the eliminated duplicates. + // Prepare a list of answers, removing duplicates. foreach ($subquestions as $subquestion) { foreach ($subquestion->options->answers as $ans) { + $allanswers[$ans->id] = $ans->answer; if (!in_array($ans->answer, $answers)) { $answers[$ans->id] = $ans->answer; $answerids[$ans->answer] = $ans->id; - } else { - if (array_key_exists($subquestion->id, $responses) && $responses[$subquestion->id]) { - $responses[$subquestion->id] = $answerids[$ans->answer]; - } - if (array_key_exists($subquestion->id, $correctanswers)) { - $correctanswers[$subquestion->id] = $answerids[$ans->answer]; - } } } } + + // Fix up the ids of any responses that point the the eliminated duplicates. + foreach ($responses as $subquestionid => $ignored) { + if ($responses[$subquestionid]) { + $responses[$subquestionid] = $answerids[$allanswers[$responses[$subquestionid]]]; + } + } + foreach ($correctanswers as $subquestionid => $ignored) { + $correctanswers[$subquestionid] = $answerids[$allanswers[$correctanswers[$subquestionid]]]; + } // Shuffle the answers $answers = draw_rand_array($answers, count($answers)); -- 2.39.5