From: tjhunt Date: Thu, 31 Aug 2006 16:59:05 +0000 (+0000) Subject: MDL-6418 - Grading of multiple choice questions broken X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d3b92b4ba587542a31330269e138f6ad89463c09;p=moodle.git MDL-6418 - Grading of multiple choice questions broken --- diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 63404e7801..82aafbf80c 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -339,34 +339,18 @@ class question_multichoice_qtype extends default_questiontype { include("$CFG->dirroot/question/type/multichoice/display.html"); } + + function grade_responses(&$question, &$state, $cmoptions) { - $answers = $question->options->answers; - $testedstate = clone($state); - $teststate = clone($state); - $state->raw_grade = 0; - foreach($answers as $answer) { - $teststate->responses = array('' => $answer->id); - if($question->options->single) { - if($this->compare_responses($question, $testedstate, - $teststate)) { - $state->raw_grade = $answer->fraction; - break; - } - } else { - foreach($state->responses as $response) { - $testedstate->responses = array('' => $response); - if($this->compare_responses($question, $testedstate, - $teststate)) { - $state->raw_grade += $answer->fraction; - break; - } - } - } - } - if (empty($state->raw_grade)) { + if($question->options->single) { + $state->raw_grade = $question->options->answers[reset($state->responses)]->fraction; + } else { $state->raw_grade = 0; + foreach ($state->responses as $response) { + $state->raw_grade += $question->options->answers[$response]->fraction; + } } - + // Make sure we don't assign negative or too high marks $state->raw_grade = min(max((float) $state->raw_grade, 0.0), 1.0) * $question->maxgrade;