From: pichetp Date: Sat, 9 Jun 2007 22:09:54 +0000 (+0000) Subject: adding equation display in calculated question text(MDL-10070) and answers text length X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bfdc0bcedbdd7698141cd06371f1b5349442fc2c;p=moodle.git adding equation display in calculated question text(MDL-10070) and answers text length greater. --- diff --git a/question/type/calculated/edit_calculated_form.php b/question/type/calculated/edit_calculated_form.php index c8821cdff2..6e326e12f1 100644 --- a/question/type/calculated/edit_calculated_form.php +++ b/question/type/calculated/edit_calculated_form.php @@ -40,8 +40,8 @@ class question_edit_calculated_form extends question_edit_form { $repeated = array(); $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated', '{no}')); - $repeated[] =& $mform->createElement('text', 'answers', get_string('correctanswerformula', 'quiz')); - $repeatedoptions['answers']['type'] = PARAM_NOTAGS; + $repeated[] =& $mform->createElement('text', 'answers', get_string('correctanswerformula', 'quiz').'=', array('size' => 50)); + $repeatedoptions['answers']['type'] = PARAM_NOTAGS; $creategrades = get_grade_options(); $gradeoptions = $creategrades->gradeoptions; @@ -158,6 +158,26 @@ class question_edit_calculated_form extends question_edit_form { function validation($data){ $errors = array(); + //verifying for errors in {=...} in question text; + $qtext = ""; + $qtextremaining = $data['questiontext'] ; + $possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']); + foreach ($possibledatasets as $name => $value) { + $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining); + } + // echo "numericalquestion qtextremaining
";print_r($possibledatasets); 
+        while  (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
+            $qtextsplits = explode($regs1[0], $qtextremaining, 2);
+            $qtext =$qtext.$qtextsplits[0];
+            $qtextremaining = $qtextsplits[1];
+            if (!empty($regs1[1]) && $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])) {
+                if(!isset($errors['questiontext'])){
+                    $errors['questiontext'] = $formulaerrors.':'.$regs1[1] ;
+                }else {
+                    $errors['questiontext'] .= '
'.$formulaerrors.':'.$regs1[1]; + } + } + } $answers = $data['answers']; $answercount = 0; $maxgrade = false;