]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20296 setting get_correct_responses() for calculated regular and multichoice
authorpichetp <pichetp>
Tue, 13 Oct 2009 01:02:30 +0000 (01:02 +0000)
committerpichetp <pichetp>
Tue, 13 Oct 2009 01:02:30 +0000 (01:02 +0000)
question/type/calculated/questiontype.php

index 2c62d7acf71d20214d997990724fd4bbb12b463f..40d329733e8dc899b5878a63498f55ac71d9730f 100644 (file)
@@ -1425,19 +1425,29 @@ class question_calculated_qtype extends default_questiontype {
 
     function get_correct_responses(&$question, &$state) {
         $virtualqtype = $this->get_virtual_qtype( $question);
-        if($unit = $virtualqtype->get_default_numerical_unit($question)){
-             $unit = $unit->unit;
-        } else {
-            $unit = '';
-        }
-        foreach ($question->options->answers as $answer) {
-            if (((int) $answer->fraction) === 1) {
-                $answernumerical = qtype_calculated_calculate_answer(
-                 $answer->answer, $state->options->dataset, $answer->tolerance,
-                 $answer->tolerancetype, $answer->correctanswerlength,
-                 $answer->correctanswerformat, $unit);
-                return array('' => $answernumerical->answer);
+        if ($question->options->multichoice != 1 ) {
+            if($unit = $virtualqtype->get_default_numerical_unit($question)){
+                 $unit = $unit->unit;
+            } else {
+                $unit = '';
+            }
+            foreach ($question->options->answers as $answer) {
+                if (((int) $answer->fraction) === 1) {
+                    $answernumerical = qtype_calculated_calculate_answer(
+                     $answer->answer, $state->options->dataset, $answer->tolerance,
+                     $answer->tolerancetype, $answer->correctanswerlength,
+                        $answer->correctanswerformat, ''); // remove unit
+                        $correct = array('' => $answernumerical->answer);
+                        $correct['answer']= $correct[''];
+                    if (isset($correct['']) && $correct[''] != '*' && $unit ) {
+                            $correct[''] .= ' '.$unit;
+                            $correct['unit']= $unit;
+                    }
+                    return $correct;
+                }
             }
+        }else{
+            return $virtualqtype->get_correct_responses($question, $state) ;
         }
         return null;
     }