diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 2e310c3386a..11250055a50 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -763,10 +763,11 @@ 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 = $answer->answer; + $formula = parent::substitute_variables($answer->answer,$data); + /* foreach ($data as $name => $value) { $formula = str_replace('{'.$name.'}', $value, $formula); - } + }*/ $formattedanswer = qtype_calculated_calculate_answer( $answer->answer, $data, $answer->tolerance, $answer->tolerancetype, $answer->correctanswerlength, diff --git a/question/type/datasetdependent/abstractqtype.php b/question/type/datasetdependent/abstractqtype.php index cb2767107ff..0642b41ef6e 100644 --- a/question/type/datasetdependent/abstractqtype.php +++ b/question/type/datasetdependent/abstractqtype.php @@ -82,7 +82,11 @@ class question_dataset_dependent_questiontype extends default_questiontype { function substitute_variables($str, $dataset) { foreach ($dataset as $name => $value) { - $str = str_replace('{'.$name.'}', $value, $str); + if($value < 0 ){ + $str = str_replace('{'.$name.'}', '('.$value.')', $str); + } else { + $str = str_replace('{'.$name.'}', $value, $str); + } } return $str; }