Commit | Line | Data |
---|---|---|
94909089 PP |
1 | <div class="qtext"> |
2 | <?php echo $questiontext; ?> | |
3 | </div> | |
aeb15530 | 4 | |
94909089 PP |
5 | <div class="ablock clearfix"> |
6 | <div class="prompt"> | |
7 | <?php echo get_string("answer", "quiz").': '; ?> | |
8 | </div> | |
ca3ede76 | 9 | <div class="que numerical clearfix"> |
94909089 | 10 | <?php |
b003b818 | 11 | $textlength = 20 ; |
12 | ?> | |
13 | ||
14 | <?php | |
15 | if ( $question->options->unitsleft == 0 ){ ?> | |
16 | ||
17 | <div class="answer"> | |
18 | <fieldset class="answer" id="generalheader"> | |
4454447d | 19 | <legend class="ftoggler"> |
92b36005 PP |
20 | <?php |
21 | echo $OUTPUT->help_icon('validnumberformats', 'qtype_numerical', ''); | |
22 | echo get_string('datasetnumber', 'quiz') ; | |
23 | ?> | |
4454447d | 24 | </legend> |
b003b818 | 25 | <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; // |
26 | ?> size="<?php echo $textlength;?>" /> | |
92b36005 PP |
27 | <?php echo $feedbackimg; |
28 | if(! $answerasterisk && $question->options->unitgradingtype != 0 && $unit_in_numerical_answer){ | |
29 | print_string('nonvalidcharactersinnumber', 'qtype_numerical'); | |
30 | } | |
31 | ||
32 | ||
33 | ?> | |
b003b818 | 34 | </fieldset> |
35 | </div> | |
aeb15530 PS |
36 | |
37 | ||
b003b818 | 38 | <?php }// display unit |
94909089 | 39 | |
04e91671 | 40 | if ($question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY || (isset($question->options->units) && count($question->options->units) == 0 )) {// no unit display or tested |
aeb15530 | 41 | |
b003b818 | 42 | ?> |
43 | <div class="answer"> | |
aeb15530 PS |
44 | <input type="hidden" |
45 | <?php | |
46 | echo $nameunit; | |
47 | ?> | |
b003b818 | 48 | value ="" /> |
49 | </div> | |
50 | <?php | |
04e91671 | 51 | } else if ($question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ) {// display unit text input |
aeb15530 | 52 | ?> |
ca3ede76 | 53 | <div class="answer numerical "> |
b003b818 | 54 | <fieldset class="clearfix" id="generalheader"> |
4454447d | 55 | <legend class="ftoggler"> |
92b36005 PP |
56 | <?php |
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', ''); | |
61 | } | |
8f609a37 PP |
62 | echo get_string('unit', 'quiz'); |
63 | if ($state->responses['unit'] == '')$classunit = ''; | |
64 | ?> | |
4454447d | 65 | </legend> |
b003b818 | 66 | <input type="text" class="<?php echo $classunit; ?>" <?php echo "$readonly $nameunit $valueunit"; // |
67 | ?> size="<?php echo $textlength;?>"/> | |
8f609a37 | 68 | <?php if ($state->responses['unit'] != '') echo $feedbackimgunit; |
92b36005 PP |
69 | if ($options->feedback && $question->options->unitgradingtype == 1 && ! $valid_numerical_unit && ! $answerasterisk ){ |
70 | if ( $empty_unit) { | |
71 | print_string('unitmandatory', 'qtype_numerical'); | |
72 | }else { | |
73 | if(isset($question->options->units) && count($question->options->units) > 0){ | |
74 | $found = 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 ; | |
80 | break; | |
81 | } | |
82 | } | |
83 | if ($valid_unit_found == 0) { | |
84 | print_string('unitunknown', 'qtype_numerical'); | |
94909089 | 85 | } |
94909089 PP |
86 | } |
87 | } | |
88 | } | |
94909089 | 89 | ?> |
b003b818 | 90 | </fieldset> |
91 | </div> | |
aeb15530 | 92 | <?php |
b003b818 | 93 | |
04e91671 | 94 | } else if ($question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY ) {// display text |
aeb15530 | 95 | |
b003b818 | 96 | ?> |
97 | <div class="answer"> | |
98 | <fieldset class="clearfix" id="generalheader"> | |
4454447d PS |
99 | <legend class="ftoggler"> |
100 | <?php echo get_string('unit', 'quiz'); | |
4454447d PS |
101 | ?> |
102 | </legend> | |
aeb15530 PS |
103 | <input type="hidden" |
104 | <?php | |
105 | echo $nameunit; echo $valueunit ; | |
b003b818 | 106 | |
aeb15530 | 107 | ?> |
b003b818 | 108 | /> |
109 | <?php echo $question->options->units[0]->unit ; | |
110 | ||
aeb15530 | 111 | echo ' ' ; |
b003b818 | 112 | ?> |
113 | </fieldset> | |
114 | </div> | |
aeb15530 | 115 | |
b003b818 | 116 | <?php |
117 | ||
aeb15530 PS |
118 | //display the units as choice |
119 | ||
04e91671 | 120 | } else if ($question->options->showunits == NUMERICALQUESTIONUNITMULTICHOICEDISPLAY){?> |
b003b818 | 121 | |
122 | ||
aeb15530 PS |
123 | |
124 | <?php | |
4433c6c4 | 125 | //display the units as choice |
04e91671 | 126 | if ( isset($question->options->units)){?> |
4433c6c4 | 127 | <div class="answer"> |
aa384ade PP |
128 | <fieldset class="clearfix" id="generalheader"> |
129 | <legend class="ftoggler"> | |
92b36005 PP |
130 | <?php |
131 | echo get_string('selectunit', 'qtype_numerical'); | |
aa384ade PP |
132 | ?> |
133 | </legend> | |
92b36005 | 134 | <table > |
b003b818 | 135 | |
94909089 PP |
136 | <?php |
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 | |
140 | // the | |
92b36005 PP |
141 | // if(isset($state->responses['unit']) && $state->responses['unit'] != '' ){ |
142 | $valid_numerical_unit_index = -1; | |
94909089 | 143 | foreach ($question->options->units as $key => $unit) { |
92b36005 PP |
144 | $checked = ''; |
145 | $chosen = false; | |
146 | $classunit = 0 ; | |
147 | $feedbackimgunit = question_get_feedback_image(0); | |
148 | $valid_numerical_unit = false ; | |
149 | $validunit = false ; | |
b003b818 | 150 | $type = 'type="radio"'; |
92b36005 PP |
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 | |
159 | // as if it was used | |
160 | $testresponse = $state->responses['answer']/$unit->multiplier ; | |
161 | /* if(isset($state->responses['unit'])){ | |
162 | $testresponse .= $state->responses['unit'] ; | |
163 | } */ | |
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 ; | |
174 | $validunit = true ; | |
175 | ||
176 | $valid_numerical_unit_index = $key ; | |
177 | } | |
94909089 | 178 | } |
92b36005 PP |
179 | } |
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) ; // ; | |
184 | } | |
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 ; | |
191 | // } | |
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']){ | |
b003b818 | 195 | $checked = 'checked="checked"'; |
196 | $chosen = true; | |
92b36005 PP |
197 | }else { |
198 | $checked = ''; | |
b003b818 | 199 | } |
92b36005 PP |
200 | |
201 | ||
202 | $aid = $question->id ; | |
203 | $a = new stdClass; | |
204 | $a->id = $question->name_prefix."unit" ;//. "2" | |
205 | $a->class = '' ; | |
206 | $a->feedbackimg = ''; | |
207 | ||
208 | $a->control = "<input $readonly $nameunit $checked $type value=\"$key\" />"; | |
209 | ||
210 | if ($options->correct_responses && $classunit > 0 ) { //$answer->fraction | |
211 | $a->class = question_get_feedback_class($classunit); | |
212 | } | |
213 | if (($options->feedback && $chosen) || $options->correct_responses) { | |
214 | $a->feedbackimg = question_get_feedback_image($classunit, $chosen && $options->feedback); | |
215 | } | |
216 | ||
217 | // Print the control | |
218 | // Print the answer text | |
219 | $a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course); | |
220 | $row = 0 ; | |
221 | ||
b003b818 | 222 | ?> |
4433c6c4 PP |
223 | <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>"> |
224 | <td class="c0 control " style=" "> | |
225 | <?php echo $a->control.' '; ?> | |
226 | </td> | |
227 | <td style=" " class="c1 text <?php echo $a->class ?>"> | |
228 | <label for="<?php echo $a->id ?>"> | |
229 | <?php echo $a->text.'<br />'; ?> | |
94909089 | 230 | <?php echo $a->feedbackimg; |
92b36005 | 231 | if ($options->feedback && $classunit == 0 && $chosen && !$answerasterisk){ |
94909089 | 232 | print_string('unitnotvalid', 'qtype_numerical'); |
92b36005 PP |
233 | }else { |
234 | echo ' '; | |
94909089 PP |
235 | } |
236 | ?> | |
4433c6c4 PP |
237 | </label> |
238 | </td> | |
239 | </tr> | |
b003b818 | 240 | <?php } ?> |
4433c6c4 | 241 | </table> |
92b36005 PP |
242 | <?php if ($options->feedback && isset($state->responses['answer'])&& $state->responses['answer'] != '' && (!isset($state->responses['unit']) || $state->responses['unit'] == '') && ! $answerasterisk ){ |
243 | ||
244 | print_string('unitnotselected', 'qtype_numerical'); | |
245 | } | |
246 | ?> | |
247 | ||
248 | </fieldset> | |
4433c6c4 | 249 | </div> |
b003b818 | 250 | <?php } // end unit choices |
251 | // display intructions | |
252 | // general message first | |
253 | } | |
aeb15530 | 254 | |
b003b818 | 255 | if ($question->options->unitsleft == 1 ){?> |
aeb15530 | 256 | |
b003b818 | 257 | <div class="answer"> |
258 | <fieldset class="clearfix" id="generalheader"> | |
4454447d | 259 | <legend class="ftoggler"> |
92b36005 PP |
260 | <?php |
261 | echo $OUTPUT->help_icon('validnumberformats', 'qtype_numerical', ''); | |
262 | echo get_string('datasetnumber', 'quiz'); | |
263 | ?> | |
4454447d | 264 | </legend> |
b003b818 | 265 | <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; // |
266 | ?> size="<?php echo $textlength;?>"/> | |
267 | <?php echo $feedbackimg; ?> | |
268 | </fieldset> | |
aeb15530 PS |
269 | </div> |
270 | <?php } | |
ca3ede76 | 271 | |
b003b818 | 272 | //</div> put a div to enclose the answer and unit elements |
273 | ?> | |
ca3ede76 | 274 | </div> |
b003b818 | 275 | |
276 | ||
92b36005 | 277 | <?php if (!empty($question->options->instructions)){?> |
b003b818 | 278 | <div class="feedback"> |
279 | <fieldset class="clearfix" id="generalheader"> | |
4454447d PS |
280 | <legend class="ftoggler"> |
281 | <?php echo get_string('instructions', 'auth'); ?> | |
282 | </legend> | |
b003b818 | 283 | <div> |
fe6ce234 | 284 | <?php echo format_text($question->options->instructions, $question->options->instructionsformat, $formatoptions, $cmoptions->course);?> |
aeb15530 | 285 | </div> |
aeb15530 PS |
286 | </fieldset> |
287 | </div> | |
92b36005 | 288 | <?php }?> |
b003b818 | 289 | |
94909089 PP |
290 | <?php if ($feedback) { ?> |
291 | <div class="feedback"> | |
292 | <?php echo $feedback ?> | |
293 | </div> | |
294 | <?php } ?> | |
295 | <?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?> | |
296 | </div> |