From: pichetp Date: Sat, 9 Jun 2007 22:07:51 +0000 (+0000) Subject: adding equation display in calculated question text(MDL-10070) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=fd6b864f7c41dda71983faf129328cc424a330f3;p=moodle.git adding equation display in calculated question text(MDL-10070) --- diff --git a/question/type/calculated/questiontype.php b/question/type/calculated/questiontype.php index 1c65c92faf..1d9e44d975 100644 --- a/question/type/calculated/questiontype.php +++ b/question/type/calculated/questiontype.php @@ -8,6 +8,7 @@ require_once("$CFG->dirroot/question/type/datasetdependent/abstractqtype.php"); + class question_calculated_qtype extends question_dataset_dependent_questiontype { // Used by the function custom_generator_tools: @@ -372,6 +373,25 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype } $numericalquestion->questiontext = parent::substitute_variables( $numericalquestion->questiontext, $state->options->dataset); + //evaluate the equations i.e {=5+4) + $qtext = ""; + $qtextremaining = $numericalquestion->questiontext ; + while (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) { + $qtextsplits = explode($regs1[0], $qtextremaining, 2); + $qtext =$qtext.$qtextsplits[0]; + $qtextremaining = $qtextsplits[1]; + if (empty($regs1[1])) { + $str = ''; + } else { + if( $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])){ + $str=$formulaerrors ; + }else { + eval('$str = '.$regs1[1].';'); + } + } + $qtext = $qtext.$str ; + } + $numericalquestion->questiontext = $qtext.$qtextremaining ; // end replace equations $virtualqtype->print_question_formulation_and_controls($numericalquestion, $state, $cmoptions, $options); } function grade_responses(&$question, &$state, $cmoptions) { @@ -892,7 +912,7 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype if (empty($formula)) { $str = ''; } else { - eval('$str = '.$formula.';'); + eval('$str = '.$formula.';'); } return $str; } @@ -1197,7 +1217,6 @@ function qtype_calculated_find_formula_errors($formula) { /// Validates the formula submitted from the question edit page. /// Returns false if everything is alright. /// Otherwise it constructs an error message - // Strip away dataset names while (ereg('\\{[[:alpha:]][^>} <{"\']*\\}', $formula, $regs)) { $formula = str_replace($regs[0], '1', $formula); @@ -1283,6 +1302,7 @@ function qtype_calculated_find_formula_errors($formula) { // Formula just might be valid return false; } + } function dump($obj) {