From 8f609a37cf13173c56d64046429d9ac31913ad63 Mon Sep 17 00:00:00 2001 From: Pierre Pichet Date: Sun, 31 Oct 2010 13:27:58 +0000 Subject: [PATCH] MDL-10110 MDL-20296 improve grading when unit input is empty --- question/type/numerical/display.html | 6 ++++-- question/type/numerical/questiontype.php | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/question/type/numerical/display.html b/question/type/numerical/display.html index 953f27f59fd..5148b6b5886 100644 --- a/question/type/numerical/display.html +++ b/question/type/numerical/display.html @@ -59,11 +59,13 @@ }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 = ''; + ?> size=""/> - responses['unit'] != '') echo $feedbackimgunit; if ($options->feedback && $question->options->unitgradingtype == 1 && ! $valid_numerical_unit && ! $answerasterisk ){ if ( $empty_unit) { print_string('unitmandatory', 'qtype_numerical'); diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php index 89cf396513c..717fbcdacfb 100644 --- a/question/type/numerical/questiontype.php +++ b/question/type/numerical/questiontype.php @@ -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 ; -- 2.43.0