2 <?php echo $questiontext; ?>
5 <div class="ablock clearfix">
7 <?php echo get_string("answer", "quiz").': '; ?>
9 <div class="que numerical clearfix">
15 if ( $question->options->unitsleft == 0 ){ ?>
18 <fieldset class="answer" id="generalheader">
19 <legend class="ftoggler">
21 echo $OUTPUT->help_icon('validnumberformats', 'qtype_numerical', '');
22 echo get_string('datasetnumber', 'quiz') ;
25 <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; //
26 ?> size="<?php echo $textlength;?>" />
27 <?php echo $feedbackimg;
28 if(! $answerasterisk && $question->options->unitgradingtype != 0 && $unit_in_numerical_answer){
29 print_string('nonvalidcharactersinnumber', 'qtype_numerical');
38 <?php }// display unit
40 if ($question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY || (isset($question->options->units) && count($question->options->units) == 0 )) {// no unit display or tested
51 } else if ($question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ) {// display unit text input
53 <div class="answer numerical ">
54 <fieldset class="clearfix" id="generalheader">
55 <legend class="ftoggler">
57 if ( $question->options->unitgradingtype == 0 ){
58 echo $OUTPUT->help_icon('unitoptional', 'qtype_numerical', '');
59 }else { // unitgradingtype == 1
60 echo $OUTPUT->help_icon('unitmandatory', 'qtype_numerical', '');
62 echo get_string('unit', 'quiz');
63 if ($state->responses['unit'] == '')$classunit = '';
66 <input type="text" class="<?php echo $classunit; ?>" <?php echo "$readonly $nameunit $valueunit"; //
67 ?> size="<?php echo $textlength;?>"/>
68 <?php if ($state->responses['unit'] != '') echo $feedbackimgunit;
69 if ($options->feedback && $question->options->unitgradingtype == 1 && ! $valid_numerical_unit && ! $answerasterisk ){
71 print_string('unitmandatory', 'qtype_numerical');
73 if(isset($question->options->units) && count($question->options->units) > 0){
75 $valid_unit_found = 0 ;
76 foreach($question->options->units as $key => $unit){
77 if($state->responses['unit'] == $unit->unit){
78 print_string('unitnotvalid', 'qtype_numerical');
79 $valid_unit_found = 1 ;
83 if ($valid_unit_found == 0) {
84 print_string('unitunknown', 'qtype_numerical');
94 } else if ($question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY ) {// display text
98 <fieldset class="clearfix" id="generalheader">
99 <legend class="ftoggler">
100 <?php echo get_string('unit', 'quiz');
105 echo $nameunit; echo $valueunit ;
109 <?php echo $question->options->units[0]->unit ;
118 //display the units as choice
120 } else if ($question->options->showunits == NUMERICALQUESTIONUNITMULTICHOICEDISPLAY){?>
125 //display the units as choice
126 if ( isset($question->options->units)){?>
128 <fieldset class="clearfix" id="generalheader">
129 <legend class="ftoggler">
131 echo get_string('selectunit', 'qtype_numerical');
137 // the order is not shuffled
138 //however the unitvalue is related to the number value
139 // if the response/unit->multiplier is true then
141 // if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){
142 $valid_numerical_unit_index = -1;
143 foreach ($question->options->units as $key => $unit) {
147 $feedbackimgunit = question_get_feedback_image(0);
148 $valid_numerical_unit = false ;
150 $type = 'type="radio"';
151 // echo "<p> boucle unit $key $unit->unit answerfraction $answer->fraction classunit $classunit index $valid_numerical_unit_index $key response $response $unit->multiplier $unit->unit state <pre>";print_r($answer);echo "</pre></p>";
152 if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){
153 // $nameunit = "name=\"".$question->name_prefix;//."unit\"";
154 // if (isset($response->number) && $response->number != false && isset($state->responses['unit']) && $state->responses['unit'] != '' ){
155 // if ($unit->unit == $state->responses['unit']){
156 // test if the numerical value as is or as multiplied by this unit
157 // could give a good response
158 // we need to extract the numerical and apply it with this unit
160 $testresponse = $state->responses['answer']/$unit->multiplier ;
161 /* if(isset($state->responses['unit'])){
162 $testresponse .= $state->responses['unit'] ;
164 $response = $this->apply_unit($testresponse, array($question->options->units[$key])) ;
165 $invalid_unit_found = 0 ;
166 if ($response !== false) {
167 $this->get_tolerance_interval($answer);
168 if($answer->min <= $response && $response <= $answer->max){
169 // then it could give a good response
170 // has it been used ?
171 $classunit = 1; // or max response i.e. 1
172 $feedbackimgunit = question_get_feedback_image($rawgrade);
173 $valid_numerical_unit = true ;
176 $valid_numerical_unit_index = $key ;
180 // if ($unit->unit == $state->responses['unit']){
181 // we have a valid unit response
182 if($answerasterisk || $valid_numerical_unit_index == $key ){
183 $classunit = $rawgrade ; //question_get_feedback_class(1) ; // ;
185 // we have a unit response
186 // this unit is the one chosen
187 // test if the unit give a valid response
188 // $testresponse = $response->number /$unit->multiplier ;
189 // if($answerasterisk || ($answer->min <= $testresponse && $testresponse <= $answer->max)) {
190 // $classunitvalue = $answer->fraction ;
192 // echo "<p> dans display $answer->fraction classunit $classunit index $valid_numerical_unit_index $key response $response $unit->multiplier $unit->unit state <pre>";print_r($answer);echo "</pre></p>";
193 // if ($state->responses['unit'] == $unit->unit) {
194 if (isset($state->responses['unit']) && $unit->unit == $state->responses['unit']){
195 $checked = 'checked="checked"';
202 $aid = $question->id ;
204 $a->id = $question->name_prefix."unit" ;//. "2"
206 $a->feedbackimg = '';
208 $a->control = "<input $readonly $nameunit $checked $type value=\"$key\" />";
210 if ($options->correct_responses && $classunit > 0 ) { //$answer->fraction
211 $a->class = question_get_feedback_class($classunit);
213 if (($options->feedback && $chosen) || $options->correct_responses) {
214 $a->feedbackimg = question_get_feedback_image($classunit, $chosen && $options->feedback);
218 // Print the answer text
219 $a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course);
223 <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
224 <td class="c0 control " style=" ">
225 <?php echo $a->control.' '; ?>
227 <td style=" " class="c1 text <?php echo $a->class ?>">
228 <label for="<?php echo $a->id ?>">
229 <?php echo $a->text.'<br />'; ?>
230 <?php echo $a->feedbackimg;
231 if ($options->feedback && $classunit == 0 && $chosen && !$answerasterisk){
232 print_string('unitnotvalid', 'qtype_numerical');
234 echo ' ';
242 <?php if ($options->feedback && isset($state->responses['answer'])&& $state->responses['answer'] != '' && (!isset($state->responses['unit']) || $state->responses['unit'] == '') && ! $answerasterisk ){
244 print_string('unitnotselected', 'qtype_numerical');
250 <?php } // end unit choices
251 // display intructions
252 // general message first
255 if ($question->options->unitsleft == 1 ){?>
258 <fieldset class="clearfix" id="generalheader">
259 <legend class="ftoggler">
261 echo $OUTPUT->help_icon('validnumberformats', 'qtype_numerical', '');
262 echo get_string('datasetnumber', 'quiz');
265 <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; //
266 ?> size="<?php echo $textlength;?>"/>
267 <?php echo $feedbackimg; ?>
272 //</div> put a div to enclose the answer and unit elements
277 <?php if (!empty($question->options->instructions)){?>
278 <div class="feedback">
279 <fieldset class="clearfix" id="generalheader">
280 <legend class="ftoggler">
281 <?php echo get_string('instructions', 'auth'); ?>
284 <?php echo format_text($question->options->instructions, $question->options->instructionsformat, $formatoptions, $cmoptions->course);?>
290 <?php if ($feedback) { ?>
291 <div class="feedback">
292 <?php echo $feedback ?>
295 <?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?>