From aa384adec9edc60d7afffb6785d494e74e3bb32d Mon Sep 17 00:00:00 2001 From: Pierre Pichet Date: Thu, 13 May 2010 02:31:23 +0000 Subject: [PATCH] MDL-20296 improving grading code and display --- question/type/numerical/display.html | 9 +++++++-- question/type/numerical/questiontype.php | 17 ++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/question/type/numerical/display.html b/question/type/numerical/display.html index 5a67f1d4037..9e2dccfd256 100644 --- a/question/type/numerical/display.html +++ b/question/type/numerical/display.html @@ -106,7 +106,6 @@
options->units[0]->unit ; ?> options->units)){?>
+
+ + + options->units as $key => $unit) { @@ -142,7 +146,7 @@ $type = 'type="radio"'; // $nameunit = "name=\"".$question->name_prefix;//."unit\""; - if (isset($state->responses['unit'])){ + if (isset($state->responses['unit']) && $state->responses['unit'] != '' ){ if ($state->responses['unit'] == $unit->unit) { $checked = 'checked="checked"'; $chosen = true; @@ -191,6 +195,7 @@
+
options->showunits == NUMERICALQUESTIONUNITMULTICHOICEDISPLAY && isset($question->options->units) && isset($question->options->units[$state->responses['unit']] )){ $state->responses['unit']=$question->options->units[$state->responses['unit']]->unit; }; @@ -451,9 +452,9 @@ class question_numerical_qtype extends question_shortanswer_qtype { * for NUMERICALQUESTIONUNITTEXTDISPLAY and NUMERICALQUESTIONUNITNODISPLAY * */ - // echo "

test1 response response answer $answer->answer numerical state

";print_r($state);echo "

"; if ( ($question->options->showunits == NUMERICALQUESTIONUNITMULTICHOICEDISPLAY || - $question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ) && + $question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY || + $question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY ) && isset($state->responses['unit']) ){ $state->responses['']= $state->responses['answer'].$state->responses['unit'] ; @@ -463,8 +464,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { } $response = $this->apply_unit($state->responses[''], $question->options->units); - // echo "

test response $response answer $answer->answer numerical state

";print_r($state);echo "

"; - // echo "

test response $response answer $answer->answer numerical state

";print_r($question->options->units);echo "

"; if ($response === false) { return false; // The student did not type a number. @@ -512,14 +511,16 @@ class question_numerical_qtype extends question_shortanswer_qtype { } } // in all cases the unit should be tested - if( $question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY ) { - $this->valid_numerical_unit == true ; + if( $question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY || + $question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY ) { + $this->valid_numerical_unit = true ; }else { $this->valid_numerical_unit = $this->valid_unit($state->responses[''], $question->options->units); } // apply unit penalty $this->raw_unitpenalty = 0 ; - if(!empty($question->options->unitpenalty)&& !$this->valid_numerical_unit ){ + if(!empty($question->options->unitpenalty)&& $this->valid_numerical_unit != true ){ + if($question->options->unitgradingtype == 1){ $this->raw_unitpenalty = $question->options->unitpenalty * $state->raw_grade ; }else { @@ -670,12 +671,10 @@ class question_numerical_qtype extends question_shortanswer_qtype { $replace = array('', '.'); } $rawresponse = str_replace($search, $replace, $rawresponse); - // echo "

apply_unit rawresponse $rawresponse answer answer->answer numerical state

";print_r($units);echo "

"; // Apply any unit that is present. if (preg_match('~^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$~', $rawresponse, $responseparts)) { - // echo "

test response $rawresponse answer answer->answer numerical responseparts

";print_r($responseparts);echo "

"; if (!empty($responseparts[5])) {