From 92b360057504ecfb2b3f8174d06a32d7564314bf Mon Sep 17 00:00:00 2001 From: Pierre Pichet Date: Sat, 30 Oct 2010 15:14:57 +0000 Subject: [PATCH] MDL-24503 recoding unit grading options --- question/type/numerical/display.html | 210 +++--- .../type/numerical/edit_numerical_form.php | 9 - .../numerical/lang/en/qtype_numerical.php | 49 +- question/type/numerical/questiontype.php | 605 +++++++++++------- 4 files changed, 558 insertions(+), 315 deletions(-) diff --git a/question/type/numerical/display.html b/question/type/numerical/display.html index c81bd1e7a64a5..953f27f59fdd6 100644 --- a/question/type/numerical/display.html +++ b/question/type/numerical/display.html @@ -17,11 +17,20 @@
- + help_icon('validnumberformats', 'qtype_numerical', ''); + echo get_string('datasetnumber', 'quiz') ; + ?> size="" /> - + options->unitgradingtype != 0 && $unit_in_numerical_answer){ + print_string('nonvalidcharactersinnumber', 'qtype_numerical'); + } + + + ?>
@@ -44,27 +53,37 @@
- + options->unitgradingtype == 0 ){ + echo $OUTPUT->help_icon('unitoptional', 'qtype_numerical', ''); + }else { // unitgradingtype == 1 + echo $OUTPUT->help_icon('unitmandatory', 'qtype_numerical', ''); + } + echo get_string('unit', 'quiz'); ?> size=""/> feedback && $classunitvalue == 0 && ! $answerasterisk ){ - if(isset($question->options->units) && count($question->options->units) > 0){ - $found = 0 ; - foreach($question->options->units as $key => $unit){ - if($state->responses['unit'] == $unit->unit){ - print_string('unitnotvalid', 'qtype_numerical'); - $found = 1 ; - break; + if ($options->feedback && $question->options->unitgradingtype == 1 && ! $valid_numerical_unit && ! $answerasterisk ){ + if ( $empty_unit) { + print_string('unitmandatory', 'qtype_numerical'); + }else { + if(isset($question->options->units) && count($question->options->units) > 0){ + $found = 0 ; + $valid_unit_found = 0 ; + foreach($question->options->units as $key => $unit){ + if($state->responses['unit'] == $unit->unit){ + print_string('unitnotvalid', 'qtype_numerical'); + $valid_unit_found = 1 ; + break; + } + } + if ($valid_unit_found == 0) { + print_string('unitunknown', 'qtype_numerical'); } - } - if ($found == 0) { - print_string('unitunknown', 'qtype_numerical'); } } } - ?>
@@ -106,65 +125,98 @@
- - - +
multiplier is true then // the - + // if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){ + $valid_numerical_unit_index = -1; foreach ($question->options->units as $key => $unit) { - $checked = ''; - $chosen = false; - $classunitvalue = 0 ; + $checked = ''; + $chosen = false; + $classunit = 0 ; + $feedbackimgunit = question_get_feedback_image(0); + $valid_numerical_unit = false ; + $validunit = false ; $type = 'type="radio"'; - // $nameunit = "name=\"".$question->name_prefix;//."unit\""; - if ($response != '' && isset($state->responses['unit']) && $state->responses['unit'] != '' ){ - // we have a unit response - // this unit is the one chosen - // test if the unit give a valid response - $testresponse = $response /$unit->multiplier ; - if($answerasterisk || ($answer->min <= $testresponse && $testresponse <= $answer->max)) { - $classunitvalue = $answer->fraction ; - } - // echo "

dans display classunitvalue $classunitvalue response $response $unit->multiplier $unit->unit state

";print_r($answer);echo "

"; - if ($state->responses['unit'] == $unit->unit) { - $checked = 'checked="checked"'; - $chosen = true; - + // echo "

boucle unit $key $unit->unit answerfraction $answer->fraction classunit $classunit index $valid_numerical_unit_index $key response $response $unit->multiplier $unit->unit state

";print_r($answer);echo "

"; + if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){ + // $nameunit = "name=\"".$question->name_prefix;//."unit\""; + // if (isset($response->number) && $response->number != false && isset($state->responses['unit']) && $state->responses['unit'] != '' ){ + // if ($unit->unit == $state->responses['unit']){ + // test if the numerical value as is or as multiplied by this unit + // could give a good response + // we need to extract the numerical and apply it with this unit + // as if it was used + $testresponse = $state->responses['answer']/$unit->multiplier ; + /* if(isset($state->responses['unit'])){ + $testresponse .= $state->responses['unit'] ; + } */ + $response = $this->apply_unit($testresponse, array($question->options->units[$key])) ; + $invalid_unit_found = 0 ; + if ($response !== false) { + $this->get_tolerance_interval($answer); + if($answer->min <= $response && $response <= $answer->max){ + // then it could give a good response + // has it been used ? + $classunit = 1; // or max response i.e. 1 + $feedbackimgunit = question_get_feedback_image($rawgrade); + $valid_numerical_unit = true ; + $validunit = true ; + + $valid_numerical_unit_index = $key ; + } } - }else if ($key == 0) { + } + // if ($unit->unit == $state->responses['unit']){ + // we have a valid unit response + if($answerasterisk || $valid_numerical_unit_index == $key ){ + $classunit = $rawgrade ; //question_get_feedback_class(1) ; // ; + } + // we have a unit response + // this unit is the one chosen + // test if the unit give a valid response + // $testresponse = $response->number /$unit->multiplier ; + // if($answerasterisk || ($answer->min <= $testresponse && $testresponse <= $answer->max)) { + // $classunitvalue = $answer->fraction ; + // } + // echo "

dans display $answer->fraction classunit $classunit index $valid_numerical_unit_index $key response $response $unit->multiplier $unit->unit state

";print_r($answer);echo "

"; + // if ($state->responses['unit'] == $unit->unit) { + if (isset($state->responses['unit']) && $unit->unit == $state->responses['unit']){ $checked = 'checked="checked"'; $chosen = true; + }else { + $checked = ''; } - - $aid = $question->id ; - $a = new stdClass; - $a->id = $question->name_prefix."unit" ;//. "2" - $a->class = '' ; - $a->feedbackimg = ''; - - $a->control = ""; - - if ($options->correct_responses && $classunitvalue > 0 ) { //$answer->fraction - $a->class = question_get_feedback_class($classunitvalue); - } - if (($options->feedback && $chosen) || $options->correct_responses) { - $a->feedbackimg = question_get_feedback_image($classunitvalue, $chosen && $options->feedback); - } - - // Print the control - // Print the answer text - $a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course); - $row = 0 ; - + + + $aid = $question->id ; + $a = new stdClass; + $a->id = $question->name_prefix."unit" ;//. "2" + $a->class = '' ; + $a->feedbackimg = ''; + + $a->control = ""; + + if ($options->correct_responses && $classunit > 0 ) { //$answer->fraction + $a->class = question_get_feedback_class($classunit); + } + if (($options->feedback && $chosen) || $options->correct_responses) { + $a->feedbackimg = question_get_feedback_image($classunit, $chosen && $options->feedback); + } + + // Print the control + // Print the answer text + $a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course); + $row = 0 ; + ?> -
@@ -174,22 +226,24 @@
- -
- - + feedback && isset($state->responses['answer'])&& $state->responses['answer'] != '' && (!isset($state->responses['unit']) || $state->responses['unit'] == '') && ! $answerasterisk ){ + + print_string('unitnotselected', 'qtype_numerical'); + } + ?> + +
- + help_icon('validnumberformats', 'qtype_numerical', ''); + echo get_string('datasetnumber', 'quiz'); + ?> size=""/> @@ -215,29 +272,18 @@ + options->instructions)){?> +