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:
}
$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) {
if (empty($formula)) {
$str = '';
} else {
- eval('$str = '.$formula.';');
+ eval('$str = '.$formula.';');
}
return $str;
}
/// 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);
// Formula just might be valid
return false;
}
+
}
function dump($obj) {