MDL-20296 Units handling for numerical and calculatedquestions
[moodle.git] / question / type / numerical / display.html
CommitLineData
b003b818 1<?php
2// as the entry is controlled the question type here is numerical
3 $nameunit = "name=\"".$question->name_prefix."unit\"";
4 $nameanswer = "name=\"".$question->name_prefix."answer\"";
5//if left unit is placed before answer so we need to answer field text and a center pice for the show units options
6// split the respnse in 2 element numerical and units
7/*if (!empty($question->options->showunits)){
8 if(isset($question->options->units) && count($question->options->units)){
9 $length = 0;
10 $goodkey = 0 ;
11 foreach ($question->options->units as $key => $unit){
12 if (false === stripos($value, $unit->unit)){
13 }else{
14
15 if(strlen($unit->unit)> $length) {$length =strlen($unit->unit);
16 $goodkey = $key ;
17 }
18 }
19 }
20 if($length){
21 $value = str_replace($question->options->units[$goodkey]->unit, '' , $value);
22 }
23 $state->responses['unit']=$goodkey ;<div class="ablock clearfix">
24 }
25
26 }*/
27 if (isset($state->responses['answer']) && $state->responses['answer']!='') {
28 $valueanswer = ' value="'.s($state->responses['answer']).'" ';
29 } else {
30 $valueanswer = ' value="" ';
31 }
32 if (isset($state->responses['unit']) && $state->responses['unit']!='') {
33 $valueunit = ' value="'.s($state->responses['unit']).'" ';
34 } else {
35
36 $valueunit = ' value="" ';
37 if ($question->options->showunits == 2 ){
38 $valueunit = ' value="'.s($question->options->units[0]->unit).'" ';
39 }
40 }
41 // put a div to enclose the answer and unit elements<div class="clearfix"></div>
42 $textlength = 20 ;
43?>
44
45<?php
46 if ( $question->options->unitsleft == 0 ){ ?>
47
48 <div class="answer">
49 <fieldset class="answer" id="generalheader">
50 <legend class="ftoggler">
51 <?php echo get_string('number', 'quiz') ; ?>
52 </legend>
53 <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; //
54 ?> size="<?php echo $textlength;?>" />
55 <?php echo $feedbackimg; ?>
56</fieldset>
57 </div>
58
59
60<?php }// display unit
61 $class = '';
62 $feedbackimgunit = '';
63 if ($options->feedback){
64 $classunit = question_get_feedback_class(1-$this->raw_unitpenalty);
65 $feedbackimgunit = question_get_feedback_image(1-$this->raw_unitpenalty, $options->feedback);
66 }
67 if ($question->options->showunits == 3 || (isset($question->options->units) && count($question->options->units) == 0 )) {// no unit display or tested
68
69?>
70 <div class="answer">
71 <input type="hidden"
72 <?php
73 echo $nameunit;
74 ?>
75 value ="" />
76 </div>
77<?php
78 } else if ($question->options->showunits == 0 ) {// display unit text input
79?>
80<div class="answer">
81 <fieldset class="clearfix" id="generalheader">
82 <legend class="ftoggler">
83 <?php echo get_string('unit', 'quiz'); ?>
84 </legend>
85 <input type="text" class="<?php echo $classunit; ?>" <?php echo "$readonly $nameunit $valueunit"; //
86 ?> size="<?php echo $textlength;?>"/>
87 <?php echo $feedbackimgunit; ?>
88</fieldset>
89 </div>
90<?php
91
92 } else if ($question->options->showunits == 2 ) {// display text
93
94?>
95 <div class="answer">
96 <fieldset class="clearfix" id="generalheader">
97 <legend class="ftoggler">
98 <?php echo get_string('unit', 'quiz');
99 //echo $question->options->units[0]->unit ;
100 ?>
101 </legend>
102 <input type="hidden"
103 <?php
104 echo $nameunit; echo $valueunit ;
105
106 ?>
107 />
108 <?php echo $question->options->units[0]->unit ;
109
110 echo '&nbsp; ' ;
111 ?>
112 </fieldset>
113 </div>
114
115 <?php
116
117 //display the units as choice
118
119 } else if ($question->options->showunits == 1){?>
120
121
122
123<?php
124 //display the units as choice
125 if ($question->options->showunits == 1 && isset($question->options->units)){?>
126 <div class="answer">
127 <table class="answer">
128
129<?php foreach ($question->options->units as $key => $unit) {
130 $checked = '';
131 $chosen = false;
132
133 $type = 'type="radio"';
134 // $nameunit = "name=\"".$question->name_prefix;//."unit\"";
135 if (isset($state->responses['unit'])){
136 if ($state->responses['unit'] == $unit->unit) {
137 $checked = 'checked="checked"';
138 $chosen = true;
139 }
140 }else if ($key == 0) {
141 $checked = 'checked="checked"';
142 $chosen = true;
143 }
144
145 $aid = $question->id ;
146 $a = new stdClass;
147 $a->id = $question->name_prefix."unit" ;//. "2"
148 $a->class = '';
149 $a->feedbackimg = '';
150
151 // Print the control
152 $a->control = "<input $readonly $nameunit $checked $type value=\"$key\" />";
153
154 if ($options->correct_responses && $answer->fraction > 0) {
155 $a->class = question_get_feedback_class(1);
156 }
157 if (($options->feedback && $chosen) || $options->correct_responses) {
158 if ($type == ' type="checkbox" ') {
159 $a->feedbackimg = question_get_feedback_image($answer->fraction > 0 ? 1 : 0, $chosen && $options->feedback);
160 } else {
161 $a->feedbackimg = question_get_feedback_image($answer->fraction, $chosen && $options->feedback);
162 }
163 }
164
165 // Print the answer text
166 $a->text = format_text($unit->unit, FORMAT_MOODLE, $formatoptions, $cmoptions->course);
167 $row = 0 ;
168
169?>
170 <tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
171 <td class="c0 control">
172 <?php echo $a->control; ?>
173 </td>
174 <td class="c1 text <?php echo $a->class ?>">
175 <label for="<?php echo $a->id ?>">
176 <?php echo $a->text; ?>
177 <?php echo $a->feedbackimg; ?>
178 </label>
179 </td>
180 </tr>
181 <?php } ?>
182
183 </table>
184
185 </div>
186 <?php } // end unit choices
187 // display intructions
188 // general message first
189 }
190
191 if ($question->options->unitsleft == 1 ){?>
192
193 <div class="answer">
194 <fieldset class="clearfix" id="generalheader">
195 <legend class="ftoggler">
196 <?php echo get_string('number', 'quiz'); ?>
197 </legend>
198 <input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $nameanswer $valueanswer"; //
199 ?> size="<?php echo $textlength;?>"/>
200 <?php echo $feedbackimg; ?>
201 </fieldset>
202 </div>
203<?php }
204 //</div> put a div to enclose the answer and unit elements
205?>
206
207
208
209 <div class="feedback">
210 <fieldset class="clearfix" id="generalheader">
211 <legend class="ftoggler">
212 <?php echo get_string('instructions', 'quiz'); ?>
213 </legend>
214 <div class="feedback">
215 <?php echo get_string('validnumber', 'numerical');?>
216 </div>
217 <?php if (!empty($question->options->instructions)){?>
218 <div>
219 <?php echo format_text($question->options->instructions, true, $formatoptions, $cmoptions->course);?>
220 </div>
221 <?php }?>
222 </fieldset>
223 </div>
224
225 <?php ?>
226