MDL-10110 MDL-20296 improve grading when unit input is empty
authorPierre Pichet <pichet.pierre@uqam.ca>
Sun, 31 Oct 2010 13:27:58 +0000 (13:27 +0000)
committerPierre Pichet <pichet.pierre@uqam.ca>
Sun, 31 Oct 2010 13:27:58 +0000 (13:27 +0000)
question/type/numerical/display.html
question/type/numerical/questiontype.php

index 953f27f..5148b6b 100644 (file)
                 }else { // unitgradingtype ==  1 
                     echo $OUTPUT->help_icon('unitmandatory', 'qtype_numerical', '');
                 }             
-                echo get_string('unit', 'quiz'); ?>
+                echo get_string('unit', 'quiz'); 
+                if ($state->responses['unit'] == '')$classunit = '';
+                ?>
          </legend>
     <input type="text" class="<?php echo $classunit; ?>" <?php echo "$readonly  $nameunit $valueunit"; //
     ?> size="<?php echo $textlength;?>"/>
-    <?php echo $feedbackimgunit; 
+    <?php if ($state->responses['unit'] != '') echo $feedbackimgunit; 
     if ($options->feedback &&  $question->options->unitgradingtype == 1 && ! $valid_numerical_unit && ! $answerasterisk ){
         if ( $empty_unit) {
             print_string('unitmandatory', 'qtype_numerical'); 
index 89cf396..717fbcd 100644 (file)
@@ -719,8 +719,17 @@ class question_numerical_qtype extends question_shortanswer_qtype {
             $answertotest = $state->responses['answer'];
             // values coming from  NUMERICALQUESTIONUNITTEXTINPUTDISPLAY
             // or NUMERICALQUESTIONUNITTEXTDISPLAY as unit hidden HTML element
+            
+            if($question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ){
+                //
+                $testresponse = $this->extract_numerical_response($state->responses['answer']);
+                if($testresponse->unit != '' || $testresponse->number === false){
+                   return false;
+                }
+                $answertotest = $testresponse->number ;
+            }
             if(isset($state->responses['unit'])) {
-                $answertotest .= $state->responses['unit'] ;
+                $answertotest .= $state->responses['unit'] ;    
             }
           //  if ($question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY && isset($question->options->units[0])){ 
            //     $answertotest .= $question->options->units[0]->unit ;