Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding equation display in calculated question text(MDL-10070) and an…

…swers text length

 greater.
  • Loading branch information...
commit 21cd4715defa5b1346dd7ba252d1789e46862cbf 1 parent 9a9446e
authored
22  question/type/calculated/edit_calculated_form.php
@@ -40,7 +40,7 @@ function definition_inner(&$mform) {
40 40
         $repeated = array();
41 41
         $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated', '{no}'));
42 42
 
43  
-        $repeated[] =& $mform->createElement('text', 'answers', get_string('correctanswerformula', 'quiz'));
  43
+        $repeated[] =& $mform->createElement('text', 'answers', get_string('correctanswerformula', 'quiz').'=', array('size' => 50));
44 44
         $repeatedoptions['answers']['type'] = PARAM_NOTAGS;
45 45
 
46 46
         $creategrades = get_grade_options();
@@ -159,6 +159,26 @@ function qtype() {
159 159
 
160 160
     function validation($data){
161 161
         $errors = array();
  162
+        //verifying for errors in {=...} in question text;
  163
+        $qtext = "";
  164
+        $qtextremaining = $data['questiontext'] ;
  165
+        $possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']);
  166
+            foreach ($possibledatasets as $name => $value) {
  167
+            $qtextremaining = str_replace('{'.$name.'}', '1', $qtextremaining);
  168
+        }
  169
+    //     echo "numericalquestion qtextremaining <pre>";print_r($possibledatasets); 
  170
+        while  (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
  171
+            $qtextsplits = explode($regs1[0], $qtextremaining, 2);
  172
+            $qtext =$qtext.$qtextsplits[0];
  173
+            $qtextremaining = $qtextsplits[1];
  174
+            if (!empty($regs1[1]) && $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])) {
  175
+                if(!isset($errors['questiontext'])){
  176
+                    $errors['questiontext'] = $formulaerrors.':'.$regs1[1] ;
  177
+                }else {
  178
+                    $errors['questiontext'] .= '<br/>'.$formulaerrors.':'.$regs1[1];
  179
+                }                    
  180
+            }
  181
+        }             
162 182
         $answers = $data['answers'];
163 183
         $answercount = 0;
164 184
         $maxgrade = false;
19  question/type/calculated/questiontype.php
@@ -372,6 +372,25 @@ function print_question_formulation_and_controls(&$question, &$state, $cmoptions
372 372
         }
373 373
         $numericalquestion->questiontext = parent::substitute_variables(
374 374
         $numericalquestion->questiontext, $state->options->dataset);
  375
+        //evaluate the equations i.e {=5+4)   
  376
+        $qtext = "";
  377
+        $qtextremaining = $numericalquestion->questiontext ;
  378
+        while  (ereg('\{=([^[:space:]}]*)}', $qtextremaining, $regs1)) {
  379
+            $qtextsplits = explode($regs1[0], $qtextremaining, 2);
  380
+            $qtext =$qtext.$qtextsplits[0];
  381
+            $qtextremaining = $qtextsplits[1];
  382
+            if (empty($regs1[1])) {
  383
+                    $str = '';
  384
+                } else {
  385
+                    if( $formulaerrors = qtype_calculated_find_formula_errors($regs1[1])){
  386
+                        $str=$formulaerrors ;
  387
+                    }else {  
  388
+                        eval('$str = '.$regs1[1].';');            
  389
+                    }
  390
+                }
  391
+                $qtext = $qtext.$str ; 
  392
+        } 
  393
+        $numericalquestion->questiontext = $qtext.$qtextremaining ; // end replace equations
375 394
         $virtualqtype->print_question_formulation_and_controls($numericalquestion, $state, $cmoptions, $options);
376 395
     }
377 396
     function grade_responses(&$question, &$state, $cmoptions) {

0 notes on commit 21cd471

Please sign in to comment.
Something went wrong with that request. Please try again.