]> git.mjollnir.org Git - moodle.git/commitdiff
adding equation display in calculated question text(MDL-10070) and answers text length
authorpichetp <pichetp>
Sat, 9 Jun 2007 22:09:54 +0000 (22:09 +0000)
committerpichetp <pichetp>
Sat, 9 Jun 2007 22:09:54 +0000 (22:09 +0000)
 greater.

question/type/calculated/edit_calculated_form.php

index c8821cdff22b8c86dab42d4dad2702e678461668..6e326e12f146f1c8754a13812491613e8cecc5a2 100644 (file)
@@ -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 <pre>";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'] .= '<br/>'.$formulaerrors.':'.$regs1[1];
+                }                    
+            }
+        }             
         $answers = $data['answers'];
         $answercount = 0;
         $maxgrade = false;