diff --git a/question/type/numerical/questiontype.php b/question/type/numerical/questiontype.php index 717fbcdacfb..a16f6c399b4 100644 --- a/question/type/numerical/questiontype.php +++ b/question/type/numerical/questiontype.php @@ -455,8 +455,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { */ function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { global $CFG, $OUTPUT; - //echo"
".$question->id."question->options
";print_r($question->options) ;echo""; - //echo"
".$question->id."state
";print_r($state) ;echo""; $context = $this->get_context_by_category_id($question->category); $readonly = empty($options->readonly) ? '' : 'readonly="readonly"'; @@ -550,24 +548,22 @@ class question_numerical_qtype extends question_shortanswer_qtype { }else { - // so we need to apply unit grading i.e. to check if the number-unit combination - // was the rigth one - // on NUMERICALQUESTIONUNITTEXTINPUTDISPLAY we need only to ckeck if applyunit will test OK - // with the $state->responses['unit'] value which cannot be empty - // if $state->responses['unit'] - // if apply-unit is true with a specific unit as long as the unit as been written either in the - // we need the numerical response and test it with the available units - // if the unit used is good then it should be set OK - // however the unit could have been put in the number element in this case - // the unit penalty should be apllied. - // testing apply_unit with no units will get us a false response if there is any text in it - // testing apply_unit with a given unit will get a good value if the number is good with this unit - // apply unit will return the numerical if - // we need to know which conditions let to a good numerical value that were done in the - // - // echo"
unit grading > 0 asterisk
";print_r($answer) ;echo""; + /* so we need to apply unit grading i.e. to check if the number-unit combination + * was the rigth one + * on NUMERICALQUESTIONUNITTEXTINPUTDISPLAY we need only to ckeck if applyunit will test OK + * with the $state->responses['unit'] value which cannot be empty + * if $state->responses['unit'] + * if apply-unit is true with a specific unit as long as the unit as been written either in the + * we need the numerical response and test it with the available units + * if the unit used is good then it should be set OK + * however the unit could have been put in the number element in this case + * the unit penalty should be apllied. + * testing apply_unit with no units will get us a false response if there is any text in it + * testing apply_unit with a given unit will get a good value if the number is good with this unit + * apply unit will return the numerical if + * we need to know which conditions let to a good numerical value that were done in the + */ $valid_numerical_unit = false ; - $validunit = false ; $rawgrade = $answer->fraction ; $valid_numerical_unit_index = -1 ; $invalid_unit_in_numerical_answer = false ; @@ -575,9 +571,7 @@ class question_numerical_qtype extends question_shortanswer_qtype { $classunit = question_get_feedback_class($answer->fraction); $feedbackimgunit = question_get_feedback_image($answer->fraction); $valid_numerical_unit = true ;//everything is true with * - //echo"
answer asterisk
";print_r($answer) ;echo""; } else { - //echo"
else after answer asterisk
";print_r($answer) ;echo""; // if( isset($state->responses['unit']) && $state->responses['unit'] != '' ){// unit should be written in the unit input or checked in multichoice // we need to see if something was written in the answer field that was not in the number // although we cannot actually detect units put before the number which will cause bad numerical. @@ -618,7 +612,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { $classunit = question_get_feedback_class($answer->fraction) ; //question_get_feedback_class(1); $feedbackimgunit = question_get_feedback_image($rawgrade); $valid_numerical_unit = true ; - $validunit = true ; $valid_numerical_unit_index = $key ; break ; } @@ -627,12 +620,10 @@ class question_numerical_qtype extends question_shortanswer_qtype { // } } - //echo "
apres la boucle valid_numerical_unit $valid_numerical_unit valid_numerical_unit_index $valid_numerical_unit_index
"; } } } - // echo "dans valid_numerical_unit_index $valid_numerical_unit_index
"; if ($answer->feedback) { $answer->feedback = quiz_rewrite_question_urls($answer->feedback, 'pluginfile.php', $context->id, 'question', 'answerfeedback', array($state->attempt, $state->question), $answer->id); $feedback = format_text($answer->feedback, true, $formatoptions, $cmoptions->course); @@ -644,7 +635,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { } - // echo "rawgrade $rawgrade classunit $classunit valid_numerical_unit_index $valid_numerical_unit_index ".$feedbackimgunit."
"; $state->options->raw_unitpenalty = 0 ; $raw_unitpenalty = 0 ; if( $question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY || @@ -704,8 +694,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { */ function test_response(&$question, &$state, $answer ) { // Deal with the match anything answer. - // echo"test_response answer
";print_r($answer) ;echo""; - // echo"
test_response state
";print_r($state) ;echo""; if ($answer->answer === '*') { return true; } @@ -721,7 +709,7 @@ class question_numerical_qtype extends question_shortanswer_qtype { // 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; @@ -736,7 +724,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { // } // test OK if only numerical or numerical with known unit names with the unit mltiplier applied $response = $this->apply_unit($answertotest, $question->options->units); - // echo"
dans response apres apply
";print_r($response) ;echo""; if ($response === false) { return false; // The student did not type a number. @@ -744,7 +731,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { // The student did type a number, so check it with tolerances. $this->get_tolerance_interval($answer); - // echo"
test_response apres get tolerance interval answer
";print_r($answer) ;echo""; return ($answer->min <= $response && $response <= $answer->max); }else { // $question->options->unitgradingtype > 0 /* testing with unitgradingtype $question->options->unitgradingtype > 0 @@ -768,8 +754,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { $response = $this->extract_numerical_response($state->responses['answer']); - // echo"
response
";print_r($response) ;echo""; - // echo"
response
";print_r($response) ;echo""; if ($response->number === false ) { return false; // The student did not type a number. @@ -778,7 +762,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { // The student did type a number, so check it with tolerances. $this->get_tolerance_interval($answer); if ($answer->min <= $response->number && $response->number <= $answer->max){ - // echo"
response true
";print_r($response) ;echo""; return true; } // testing for other units @@ -819,25 +802,15 @@ class question_numerical_qtype extends question_shortanswer_qtype { * @param object $cmoptions */ function grade_responses(&$question, &$state, $cmoptions) { - // echo"
grade question->options
";print_r($question->options) ;echo""; - // echo"
grade state response
";print_r($state->responses) ;echo""; - /* if (!isset($state->responses['answer']) && isset($state->responses[''])){ - $state->responses['answer'] = $state->responses['']; - }*/ if ( isset($state->responses['']) && $state->responses[''] != '' && !isset($state->responses['answer'])){ $this->split_old_answer($state->responses[''], $question->options->units, $state->responses['answer'] ,$state->responses['unit'] ); } - //to apply the unit penalty we need to analyse the response in a more complex way - //the apply_unit() function analysis could be used to obtain the infos - // however it is used to detect good or bad numbers but also - // gives false if there is a unit $state->raw_grade = 0; $valid_numerical_unit = false ; $break = 0 ; $unittested = ''; $hasunits = 0 ; - // $response = $this->extract_numerical_response($state->responses['answer']); $answerasterisk = false ; $break = 0 ; @@ -1051,7 +1024,6 @@ class question_numerical_qtype extends question_shortanswer_qtype { * account as a float. */ function apply_unit($rawresponse, $units) { - // echo"
rawresponse $rawresponse
";print_r($units) ;echo""; // Make units more useful $tmpunits = array(); @@ -1103,13 +1075,8 @@ class question_numerical_qtype extends question_shortanswer_qtype { // Units are graded $mform->addElement('header', 'unithandling', get_string('unitshandling', 'qtype_numerical')); $mform->addElement('radio', 'unitrole', get_string('unitnotused', 'qtype_numerical'), get_string('onlynumerical', 'qtype_numerical'),0); - // $mform->addElement('header', 'unithandling1', get_string('unitnotgraded', 'qtype_numerical')); $mform->addElement('radio', 'unitrole', get_string('unitdisplay', 'qtype_numerical'), get_string('oneunitshown', 'qtype_numerical'),1); $mform->addElement('radio', 'unitrole', get_string('unitsused', 'qtype_numerical'), get_string('manynumerical', 'qtype_numerical'),2); - /* $showunits1grp = array(); - $showunits1grp[] = & $mform->createElement('radio', 'showunits1', '', get_string('no', 'moodle'),3); - $showunits1grp[] = & $mform->createElement('radio', 'showunits1', '', get_string('yes', 'moodle'),2);*/ - // $mform->addGroup($showunits1grp, 'showunits1grp', get_string('unitdisplay', 'qtype_numerical'),' ' , false); $mform->addElement('static', 'separator2', '', '