From aa384adec9edc60d7afffb6785d494e74e3bb32d Mon Sep 17 00:00:00 2001
From: Pierre Pichet
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])) {