From edcf8249534c28337e8f5fe71685ea2cc5cebd20 Mon Sep 17 00:00:00 2001 From: pichetp Date: Sat, 20 Sep 2008 14:07:47 +0000 Subject: [PATCH] MDL-16427 implement the '*' convention as for other questiontypes --- question/type/calculated/questiontype.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 1385d2fd164..ee567e58634 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -758,16 +758,17 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype $delimiter = ': '; $virtualqtype = $this->get_virtual_qtype(); foreach ($answers as $answer) { - $formula = $answer->answer; - foreach ($data as $name => $value) { - $formula = str_replace('{'.$name.'}', $value, $formula); - } + $formula = parent::substitute_variables($answer->answer,$data); $formattedanswer = qtype_calculated_calculate_answer( $answer->answer, $data, $answer->tolerance, $answer->tolerancetype, $answer->correctanswerlength, $answer->correctanswerformat, $unit); - eval('$answer->answer = '.$formula.';') ; - $virtualqtype->get_tolerance_interval($answer); + if ( $formula === '*'){ + $answer->min = '' ; + }else { + eval('$answer->answer = '.$formula.';') ; + $virtualqtype->get_tolerance_interval($answer); + } if ($answer->min === '') { // This should mean that something is wrong $stranswers .= " -$formattedanswer->answer".'

'; @@ -873,6 +874,8 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype /// Calculate the correct answer if (empty($formula)) { $str = ''; + } else if ($formula === '*'){ + $str = '*'; } else { eval('$str = '.$formula.';'); }