/** * Save 'calculation' question type to QTI XML * @param ST_Question_Calculation $question Reference to the question object * @author Adam Clarke, Rob Ingram */ function SaveCalculation(&$question) { if ($question->q_type == 'enhancedcalc') { $this->SaveEnhancedCalc($question); return; } $question->formula = trim($question->formula); if (substr($question->formula, 0, 1) == "=") { $question->formula = substr($question->formula, 1); } $question->origleadin = $question->leadin; $q_text = $question->leadin; // format the text for the question // replace all variables in leadin with randomly generated values foreach ($question->variables as $var => $vairable) { ${$var} = MathsUtils::gen_random_no(checkVariables($vairable->min), checkVariables($vairable->max), $vairable->inc, $vairable->dec); $q_text = str_ireplace("\${$var}", ${$var}, $q_text); } eval("\$answer = " . $question->formula . ";"); //echo $q_text."<BR>"; $question->leadin = $q_text; list($headertext, $title) = $this->MakeQuestionHeader($question); $type = "Calculation"; $ob = new OB(); $ob->ClearAndSave(); include "qti12/tmpl/calculation.php"; $this->output .= $ob->GetContent(); $ob->Restore(); }
function SaveCalculation(&$question) { // TODO : NO template // format the text for the question foreach ($question->variables as $var => $vairable) { ${$var} = MathsUtils::gen_random_no(checkVariables($vairable->min), checkVariables($vairable->max), $vairable->inc, $vairable->dec); } eval("\$answer = " . $question->formula . ";"); $q_text = $question->leadin; $q_text = str_ireplace("\$A", $A, $q_text); $q_text = str_ireplace("\$B", $B, $q_text); $q_text = str_ireplace("\$C", $C, $q_text); $q_text = str_ireplace("\$D", $D, $q_text); $q_text = str_ireplace("\$E", $E, $q_text); $q_text = str_ireplace("\$F", $F, $q_text); $q_text = str_ireplace("\$G", $G, $q_text); $q_text = str_ireplace("\$H", $H, $q_text); //echo $q_text."<BR>"; $question->leadin = $q_text; $headertext = $this->MakeQuestionHeader($question); $title = StripForTitle($question->leadin); $ob = new OB(); $ob->ClearAndSave(); include "qti20/tmpl/calculation.php"; $this->output .= $ob->GetContent(); $ob->Restore(); }
/** * Render the question in the format required when taking the paper * @param array $extra [description] */ public function generate_variables() { if (!isset($this->useranswer['vars']) or !is_array($this->useranswer['vars'])) { // Create an empty array to hold the generated variables $this->useranswer['vars'] = array(); } // Check to see if variables have been previously generated if not put them in an array to be generated foreach ($this->settings['vars'] as $key => $value) { if ((!isset($this->useranswer['vars'][$key]) or $this->useranswer['vars'][$key] === 'ERROR') and !$this->is_linked_ans($value['min'])) { $min = $this->variable_substitution($value['min'], $this->alluseranswers); if ($value['max'] == '') { //value for max not set force it to min to generate a fixed value. $value['max'] = $value['min']; } $max = $this->variable_substitution($value['max'], $this->alluseranswers); // Temporary fix ROGO-1468 until we introduce proper localisation we need to be able to handle ',' decimal places. $inc = $this->variable_substitution(str_replace(',', '.', $value['inc']), $this->alluseranswers); $dec = (int) $value['dec']; $this->useranswer['vars'][$key] = MathsUtils::gen_random_no($min, $max, $inc, $dec); } // Pull in the last userans every time if ($this->is_linked_ans($value['min'])) { $this->useranswer['vars'][$key] = $this->variable_substitution($value['min'], $this->alluseranswers); } } // Update the session $_SESSION['qid'][$this->id]['vars'] = $this->useranswer['vars']; }