putting negative data from datasets between () to eliminate maths problem MDL-15358

This commit is contained in:
pichetp 2008-08-20 18:17:27 +00:00
parent 71e02d31cc
commit 6f4accc6fb
2 changed files with 9 additions and 4 deletions

View File

@ -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,

View File

@ -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;
}