Commit | Line | Data |
---|---|---|
1adbd2c3 | 1 | <?php |
01910dff | 2 | defined('MOODLE_INTERNAL') OR die('not allowed'); |
6ee09cfe | 3 | require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); |
4 | ||
5 | define('FEEDBACK_MULTICHOICE_TYPE_SEP', '>>>>>'); | |
6 | define('FEEDBACK_MULTICHOICE_LINE_SEP', '|'); | |
7 | define('FEEDBACK_MULTICHOICE_ADJUST_SEP', '<<<<<'); | |
79473294 AG |
8 | define('FEEDBACK_MULTICHOICE_IGNOREEMPTY', 'i'); |
9 | define('FEEDBACK_MULTICHOICE_HIDENOSELECT', 'h'); | |
6ee09cfe | 10 | |
11 | class feedback_item_multichoice extends feedback_item_base { | |
12 | var $type = "multichoice"; | |
a59ff6b0 AG |
13 | var $commonparams; |
14 | var $item_form; | |
15 | var $item; | |
39790bd8 | 16 | |
6ee09cfe | 17 | function init() { |
d4b1d58c | 18 | |
6ee09cfe | 19 | } |
d4b1d58c | 20 | |
a59ff6b0 AG |
21 | function build_editform($item, $feedback, $cm) { |
22 | global $DB, $CFG; | |
23 | require_once('multichoice_form.php'); | |
24 | ||
25 | //get the lastposition number of the feedback_items | |
26 | $position = $item->position; | |
27 | $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); | |
28 | if($position == -1){ | |
29 | $i_formselect_last = $lastposition + 1; | |
30 | $i_formselect_value = $lastposition + 1; | |
31 | $item->position = $lastposition + 1; | |
32 | }else { | |
33 | $i_formselect_last = $lastposition; | |
34 | $i_formselect_value = $item->position; | |
35 | } | |
36 | //the elements for position dropdownlist | |
37 | $positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true); | |
39790bd8 | 38 | |
a59ff6b0 AG |
39 | $item->presentation = empty($item->presentation) ? '' : $item->presentation; |
40 | $info = $this->get_info($item); | |
41 | ||
79473294 AG |
42 | $item->ignoreempty = $this->ignoreempty($item); |
43 | $item->hidenoselect = $this->hidenoselect($item); | |
39790bd8 | 44 | |
73043833 AG |
45 | //all items for dependitem |
46 | $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); | |
a59ff6b0 AG |
47 | $commonparams = array('cmid'=>$cm->id, |
48 | 'id'=>isset($item->id) ? $item->id : NULL, | |
49 | 'typ'=>$item->typ, | |
73043833 | 50 | 'items'=>$feedbackitems, |
a59ff6b0 AG |
51 | 'feedback'=>$feedback->id); |
52 | ||
53 | //build the form | |
54 | $this->item_form = new feedback_multichoice_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'info'=>$info)); | |
55 | } | |
56 | ||
57 | //this function only can used after the call of build_editform() | |
58 | function show_editform() { | |
59 | $this->item_form->display(); | |
60 | } | |
39790bd8 | 61 | |
a59ff6b0 AG |
62 | function is_cancelled() { |
63 | return $this->item_form->is_cancelled(); | |
64 | } | |
65 | ||
66 | function get_data() { | |
67 | if($this->item = $this->item_form->get_data()) { | |
68 | return true; | |
69 | } | |
70 | return false; | |
71 | } | |
72 | ||
73 | function save_item() { | |
74 | global $DB; | |
39790bd8 | 75 | |
a59ff6b0 AG |
76 | if(!$item = $this->item_form->get_data()) { |
77 | return false; | |
78 | } | |
39790bd8 | 79 | |
b8baf0ad | 80 | if(isset($item->clone_item) AND $item->clone_item) { |
9e1aed53 AG |
81 | $item->id = ''; //to clone this item |
82 | $item->position++; | |
83 | } | |
39790bd8 PS |
84 | |
85 | $this->set_ignoreempty($item, $item->ignoreempty); | |
79473294 AG |
86 | $this->set_hidenoselect($item, $item->hidenoselect); |
87 | ||
45c2f92a | 88 | $item->hasvalue = $this->get_hasvalue(); |
a59ff6b0 AG |
89 | if(!$item->id) { |
90 | $item->id = $DB->insert_record('feedback_item', $item); | |
91 | }else { | |
92 | $DB->update_record('feedback_item', $item); | |
93 | } | |
39790bd8 | 94 | |
a59ff6b0 AG |
95 | return $DB->get_record('feedback_item', array('id'=>$item->id)); |
96 | } | |
97 | ||
6ee09cfe | 98 | |
99 | //liefert ein eindimensionales Array mit drei Werten(typ, name, XXX) | |
100 | //XXX ist ein eindimensionales Array (anzahl der Antworten bei Typ Radio) Jedes Element ist eine Struktur (answertext, answercount) | |
101 | function get_analysed($item, $groupid = false, $courseid = false) { | |
102 | $info = $this->get_info($item); | |
d4b1d58c | 103 | |
6ee09cfe | 104 | $analysedItem = array(); |
105 | $analysedItem[] = $item->typ; | |
106 | $analysedItem[] = $item->name; | |
107 | //die moeglichen Antworten extrahieren | |
108 | $answers = null; | |
109 | // $presentation = ''; | |
110 | // @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info | |
d4b1d58c | 111 | |
294ce987 | 112 | $answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); |
6ee09cfe | 113 | if(!is_array($answers)) return null; |
114 | ||
115 | //die Werte holen | |
79473294 | 116 | $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item)); |
6ee09cfe | 117 | if(!$values) return null; |
118 | //schleife ueber den Werten und ueber die Antwortmoeglichkeiten | |
d4b1d58c | 119 | |
6ee09cfe | 120 | $analysedAnswer = array(); |
121 | if($info->subtype == 'c') { | |
2b9ce62e | 122 | $sizeofanswers = sizeof($answers); |
80c12897 | 123 | for ($i = 1; $i <= $sizeofanswers; $i++) { |
6ee09cfe | 124 | $ans = null; |
125 | $ans->answertext = $answers[$i-1]; | |
126 | $ans->answercount = 0; | |
80c12897 | 127 | foreach ($values as $value) { |
6ee09cfe | 128 | //ist die Antwort gleich dem index der Antworten + 1? |
129 | $vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value); | |
80c12897 | 130 | foreach ($vallist as $val) { |
6ee09cfe | 131 | if ($val == $i) { |
132 | $ans->answercount++; | |
133 | } | |
134 | } | |
135 | } | |
136 | $ans->quotient = $ans->answercount / sizeof($values); | |
137 | $analysedAnswer[] = $ans; | |
138 | } | |
139 | }else { | |
2b9ce62e | 140 | $sizeofanswers = sizeof($answers); |
80c12897 | 141 | for ($i = 1; $i <= $sizeofanswers; $i++) { |
6ee09cfe | 142 | $ans = null; |
143 | $ans->answertext = $answers[$i-1]; | |
144 | $ans->answercount = 0; | |
80c12897 | 145 | foreach ($values as $value) { |
6ee09cfe | 146 | //ist die Antwort gleich dem index der Antworten + 1? |
147 | if ($value->value == $i) { | |
148 | $ans->answercount++; | |
149 | } | |
150 | } | |
151 | $ans->quotient = $ans->answercount / sizeof($values); | |
152 | $analysedAnswer[] = $ans; | |
153 | } | |
154 | } | |
155 | $analysedItem[] = $analysedAnswer; | |
156 | return $analysedItem; | |
157 | } | |
158 | ||
159 | function get_printval($item, $value) { | |
160 | $info = $this->get_info($item); | |
d4b1d58c | 161 | |
6ee09cfe | 162 | $printval = ''; |
d4b1d58c | 163 | |
80c12897 SH |
164 | if (!isset($value->value)) { |
165 | return $printval; | |
166 | } | |
d4b1d58c | 167 | |
6ee09cfe | 168 | // @list($presentation) = explode(FEEDBACK_RADIO_ADJUST_SEP, $item->presentation); //remove the adjustment-info |
d4b1d58c | 169 | |
294ce987 | 170 | $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); |
d4b1d58c | 171 | |
80c12897 | 172 | if ($info->subtype == 'c') { |
6ee09cfe | 173 | $vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value)); |
2b9ce62e | 174 | $sizeofvallist = sizeof($vallist); |
80c12897 SH |
175 | $sizeofpresentation = sizeof($presentation); |
176 | for ($i = 0; $i < $sizeofvallist; $i++) { | |
177 | for ($k = 0; $k < $sizeofpresentation; $k++) { | |
178 | if ($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0 | |
6ee09cfe | 179 | $printval .= trim($presentation[$k]) . chr(10); |
180 | break; | |
181 | } | |
182 | } | |
183 | } | |
80c12897 | 184 | } else { |
6ee09cfe | 185 | $index = 1; |
186 | foreach($presentation as $pres){ | |
80c12897 | 187 | if ($value->value == $index){ |
6ee09cfe | 188 | $printval = $pres; |
189 | break; | |
190 | } | |
191 | $index++; | |
192 | } | |
193 | } | |
194 | return $printval; | |
195 | } | |
196 | ||
efc59167 | 197 | function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { |
6ee09cfe | 198 | $sep_dec = get_string('separator_decimal', 'feedback'); |
199 | if(substr($sep_dec, 0, 2) == '[['){ | |
200 | $sep_dec = FEEDBACK_DECIMAL; | |
201 | } | |
d4b1d58c | 202 | |
6ee09cfe | 203 | $sep_thous = get_string('separator_thousand', 'feedback'); |
204 | if(substr($sep_thous, 0, 2) == '[['){ | |
205 | $sep_thous = FEEDBACK_THOUSAND; | |
206 | } | |
d4b1d58c | 207 | |
6ee09cfe | 208 | $analysedItem = $this->get_analysed($item, $groupid, $courseid); |
209 | if($analysedItem) { | |
efc59167 | 210 | // $itemnr++; |
294ce987 | 211 | $itemname = $analysedItem[1]; |
b7a47958 | 212 | echo '<tr><th colspan="2" align="left">'. $itemnr . ' ('. $item->label .') ' . $itemname .'</th></tr>'; |
6ee09cfe | 213 | $analysedVals = $analysedItem[2]; |
214 | $pixnr = 0; | |
215 | foreach($analysedVals as $val) { | |
216 | if( function_exists("bcmod")) { | |
217 | $intvalue = bcmod($pixnr, 10); | |
218 | }else { | |
219 | $intvalue = 0; | |
220 | } | |
221 | $pix = "pics/$intvalue.gif"; | |
222 | $pixnr++; | |
223 | $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); | |
224 | $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); | |
225 | echo '<tr><td align="left" valign="top">- ' . trim($val->answertext) . ':</td><td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'"><img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" /> ' . $val->answercount . (($val->quotient > 0)?' ('. $quotient . ' %)':'').'</td></tr>'; | |
226 | } | |
227 | } | |
efc59167 | 228 | // return $itemnr; |
6ee09cfe | 229 | } |
230 | ||
51129b99 | 231 | function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) { |
6ee09cfe | 232 | $analysed_item = $this->get_analysed($item, $groupid, $courseid); |
233 | ||
6ee09cfe | 234 | $data = $analysed_item[2]; |
235 | ||
51129b99 | 236 | // $worksheet->setFormat("<l><f><ro2><vo><c:green>"); |
6ee09cfe | 237 | //frage schreiben |
51129b99 AG |
238 | $worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2_green); |
239 | $worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2_green); | |
80c12897 | 240 | if (is_array($data)) { |
b692e4aa | 241 | $sizeofdata = sizeof($data); |
80c12897 | 242 | for ($i = 0; $i < $sizeofdata; $i++) { |
6ee09cfe | 243 | $aData = $data[$i]; |
d4b1d58c | 244 | |
51129b99 AG |
245 | // $worksheet->setFormat("<l><f><ro2><vo><c:blue>"); |
246 | $worksheet->write_string($rowOffset, $i + 2, trim($aData->answertext), $xlsFormats->value_blue); | |
d4b1d58c | 247 | |
51129b99 AG |
248 | // $worksheet->setFormat("<l><vo>"); |
249 | $worksheet->write_number($rowOffset + 1, $i + 2, $aData->answercount, $xlsFormats->default); | |
250 | // $worksheet->setFormat("<l><f><vo><pr>"); | |
251 | $worksheet->write_number($rowOffset + 2, $i + 2, $aData->quotient, $xlsFormats->procent); | |
6ee09cfe | 252 | } |
253 | } | |
80c12897 | 254 | $rowOffset += 3; |
6ee09cfe | 255 | return $rowOffset; |
256 | } | |
39790bd8 PS |
257 | |
258 | /** | |
9d5fbd65 AG |
259 | * print the item at the edit-page of feedback |
260 | * | |
261 | * @global object | |
262 | * @param object $item | |
263 | * @return void | |
264 | */ | |
265 | function print_item_preview($item) { | |
73043833 | 266 | global $OUTPUT, $DB; |
9d5fbd65 AG |
267 | $info = $this->get_info($item); |
268 | $align = right_to_left() ? 'right' : 'left'; | |
269 | ||
270 | $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); | |
271 | ||
272 | ||
273 | //test if required and no value is set so we have to mark this item | |
274 | //we have to differ check and the other subtypes | |
afdb1920 | 275 | $requiredmark = ($item->required == 1) ? '<span class="feedback_required_mark">*</span>' : ''; |
39790bd8 | 276 | |
afdb1920 AG |
277 | //print the question and label |
278 | echo '<div class="feedback_item_label_'.$align.'">'; | |
279 | echo '('.$item->label.') '; | |
280 | echo format_text($item->name.$requiredmark, true, false, false); | |
73043833 AG |
281 | if($item->dependitem) { |
282 | if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { | |
283 | echo ' <span class="feedback_depend">('.$dependitem->label.'->'.$item->dependvalue.')</span>'; | |
284 | } | |
285 | } | |
afdb1920 | 286 | echo '</div>'; |
39790bd8 | 287 | |
afdb1920 AG |
288 | //print the presentation |
289 | echo '<div class="feedback_item_presentation_'.$align.'">'; | |
9d5fbd65 AG |
290 | $index = 1; |
291 | $checked = ''; | |
afdb1920 AG |
292 | echo '<ul>'; |
293 | if($info->horizontal) { | |
294 | $hv = 'h'; | |
295 | }else { | |
296 | $hv = 'v'; | |
297 | } | |
39790bd8 | 298 | |
79473294 | 299 | if($info->subtype == 'r' AND !$this->hidenoselect($item)) { |
afdb1920 | 300 | //print the "not_selected" item on radiobuttons |
9d5fbd65 | 301 | ?> |
afdb1920 AG |
302 | <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> |
303 | <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> | |
304 | <input type="radio" name="<?php echo $item->typ . '_' . $item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" checked="checked" /> | |
305 | </span> | |
306 | <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> | |
307 | <label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?> </label> | |
308 | </span> | |
309 | </li> | |
9d5fbd65 AG |
310 | <?php |
311 | } | |
9d5fbd65 AG |
312 | |
313 | switch($info->subtype) { | |
314 | case 'r': | |
315 | $this->print_item_radio($presentation, $item, false, $info, $align); | |
316 | break; | |
317 | case 'c': | |
318 | $this->print_item_check($presentation, $item, false, $info, $align); | |
319 | break; | |
320 | case 'd': | |
321 | $this->print_item_dropdown($presentation, $item, false, $info, $align); | |
322 | break; | |
323 | } | |
afdb1920 AG |
324 | echo '</ul>'; |
325 | echo '</div>'; | |
9d5fbd65 | 326 | } |
39790bd8 PS |
327 | |
328 | /** | |
9d5fbd65 AG |
329 | * print the item at the complete-page of feedback |
330 | * | |
331 | * @global object | |
332 | * @param object $item | |
333 | * @param string $value | |
334 | * @param bool $highlightrequire | |
335 | * @return void | |
336 | */ | |
337 | function print_item_complete($item, $value = '', $highlightrequire = false) { | |
d4b1d58c | 338 | global $OUTPUT; |
6ee09cfe | 339 | $info = $this->get_info($item); |
e372f4c7 | 340 | $align = right_to_left() ? 'right' : 'left'; |
d4b1d58c | 341 | |
294ce987 | 342 | $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); |
d4b1d58c | 343 | |
344 | ||
6ee09cfe | 345 | //test if required and no value is set so we have to mark this item |
346 | //we have to differ check and the other subtypes | |
347 | if($info->subtype == 'c') { | |
348 | if (is_array($value)) { | |
349 | $values = $value; | |
350 | }else { | |
351 | $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); | |
352 | } | |
353 | if($highlightrequire AND $item->required AND $values[0] == '') { | |
afdb1920 | 354 | $highlight = ' missingrequire'; |
6ee09cfe | 355 | }else { |
356 | $highlight = ''; | |
357 | } | |
358 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; | |
6ee09cfe | 359 | }else { |
360 | if($highlightrequire AND $item->required AND intval($value) <= 0) { | |
afdb1920 | 361 | $highlight = ' missingrequire'; |
6ee09cfe | 362 | }else { |
363 | $highlight = ''; | |
364 | } | |
365 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; | |
6ee09cfe | 366 | } |
afdb1920 AG |
367 | |
368 | //print the question and label | |
369 | echo '<div class="feedback_item_label_'.$align.$highlight.'">'; | |
370 | echo format_text($item->name.$requiredmark, true, false, false); | |
371 | echo '</div>'; | |
372 | ||
373 | //print the presentation | |
374 | echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; | |
39790bd8 | 375 | |
afdb1920 AG |
376 | echo '<ul>'; |
377 | if($info->horizontal) { | |
378 | $hv = 'h'; | |
379 | }else { | |
380 | $hv = 'v'; | |
381 | } | |
9d5fbd65 | 382 | //print the "not_selected" item on radiobuttons |
79473294 | 383 | if($info->subtype == 'r' AND !$this->hidenoselect($item)) { |
9d5fbd65 | 384 | ?> |
afdb1920 AG |
385 | <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> |
386 | <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> | |
387 | <input type="radio" name="<?php echo $item->typ.'_'.$item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" <?php echo $value ? '' : 'checked="checked"';?> /> | |
388 | </span> | |
389 | <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> | |
390 | <label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?> </label> | |
391 | </span> | |
392 | </li> | |
9d5fbd65 AG |
393 | <?php |
394 | } | |
9d5fbd65 AG |
395 | |
396 | switch($info->subtype) { | |
397 | case 'r': | |
398 | $this->print_item_radio($presentation, $item, $value, $info, $align); | |
399 | break; | |
400 | case 'c': | |
401 | $this->print_item_check($presentation, $item, $value, $info, $align); | |
402 | break; | |
403 | case 'd': | |
404 | $this->print_item_dropdown($presentation, $item, $value, $info, $align); | |
405 | break; | |
406 | } | |
afdb1920 AG |
407 | echo '</ul>'; |
408 | echo '</div>'; | |
9d5fbd65 | 409 | } |
d4b1d58c | 410 | |
39790bd8 | 411 | /** |
9d5fbd65 AG |
412 | * print the item at the complete-page of feedback |
413 | * | |
414 | * @global object | |
415 | * @param object $item | |
416 | * @param string $value | |
417 | * @return void | |
418 | */ | |
419 | function print_item_show_value($item, $value = '') { | |
420 | global $OUTPUT; | |
421 | $info = $this->get_info($item); | |
422 | $align = right_to_left() ? 'right' : 'left'; | |
423 | ||
424 | $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); | |
425 | ||
426 | ||
427 | //test if required and no value is set so we have to mark this item | |
428 | //we have to differ check and the other subtypes | |
429 | if($info->subtype == 'c') { | |
430 | if (is_array($value)) { | |
431 | $values = $value; | |
432 | }else { | |
433 | $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); | |
6ee09cfe | 434 | } |
9d5fbd65 | 435 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; |
9d5fbd65 AG |
436 | }else { |
437 | $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':''; | |
9d5fbd65 | 438 | } |
39790bd8 | 439 | |
afdb1920 AG |
440 | //print the question and label |
441 | echo '<div class="feedback_item_label_'.$align.'">'; | |
442 | echo '('.$item->label.') '; | |
443 | echo format_text($item->name . $requiredmark, true, false, false); | |
444 | echo '</div>'; | |
39790bd8 | 445 | |
afdb1920 AG |
446 | //print the presentation |
447 | echo '<div class="feedback_item_presentation_'.$align.'">'; | |
9d5fbd65 | 448 | $index = 1; |
9d5fbd65 AG |
449 | if($info->subtype == 'c') { |
450 | echo $OUTPUT->box_start('generalbox boxalign'.$align); | |
451 | foreach($presentation as $pres){ | |
452 | foreach($values as $val) { | |
453 | if($val == $index){ | |
afdb1920 AG |
454 | echo '<div class="feedback_item_multianswer">'; |
455 | echo text_to_html($pres, true, false, false); | |
456 | echo '</div>'; | |
9d5fbd65 AG |
457 | break; |
458 | } | |
6ee09cfe | 459 | } |
9d5fbd65 | 460 | $index++; |
6ee09cfe | 461 | } |
9d5fbd65 AG |
462 | echo $OUTPUT->box_end(); |
463 | }else { | |
464 | foreach($presentation as $pres){ | |
465 | if($value == $index){ | |
466 | echo $OUTPUT->box_start('generalbox boxalign'.$align); | |
467 | echo text_to_html($pres, true, false, false); | |
468 | echo $OUTPUT->box_end(); | |
469 | break; | |
470 | } | |
471 | $index++; | |
6ee09cfe | 472 | } |
6ee09cfe | 473 | } |
afdb1920 | 474 | echo '</div>'; |
6ee09cfe | 475 | } |
476 | ||
477 | function check_value($value, $item) { | |
478 | $info = $this->get_info($item); | |
d4b1d58c | 479 | |
6ee09cfe | 480 | if($info->subtype == 'c') { |
481 | if((!isset($value) OR !is_array($value) OR $value[0] == '' OR $value[0] == 0) AND $item->required != 1){ | |
482 | return true; | |
483 | } | |
484 | if($value[0] == ""){ | |
485 | return false; | |
486 | } | |
487 | return true; | |
488 | }else { | |
489 | //if the item is not required, so the check is true if no value is given | |
490 | if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true; | |
491 | if(intval($value) > 0)return true; | |
492 | } | |
493 | return false; | |
494 | } | |
495 | ||
496 | function create_value($data) { | |
497 | $vallist = $data; | |
498 | return trim($this->item_arrayToString($vallist)); | |
499 | } | |
39790bd8 | 500 | |
73043833 AG |
501 | //compares the dbvalue with the dependvalue |
502 | //dbvalue is the number of one selection | |
503 | //dependvalue is the presentation of one selection | |
504 | function compare_value($item, $dbvalue, $dependvalue) { | |
6ee09cfe | 505 | |
73043833 AG |
506 | if (is_array($dbvalue)) { |
507 | $dbvalues = $dbvalue; | |
508 | }else { | |
509 | $dbvalues = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $dbvalue); | |
510 | } | |
39790bd8 | 511 | |
73043833 AG |
512 | $info = $this->get_info($item); |
513 | $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); | |
514 | $index = 1; | |
515 | foreach($presentation as $pres) { | |
516 | foreach($dbvalues as $dbval) { | |
517 | if($dbval == $index AND trim($pres) == $dependvalue) { | |
518 | return true; | |
519 | } | |
520 | } | |
521 | $index++; | |
522 | } | |
523 | return false; | |
524 | } | |
39790bd8 | 525 | |
6ee09cfe | 526 | function get_presentation($data) { |
527 | $present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues)); | |
528 | if(!isset($data->subtype)) { | |
529 | $subtype = 'r'; | |
530 | }else { | |
531 | $subtype = substr($data->subtype, 0, 1); | |
532 | } | |
533 | if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') { | |
534 | $present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1'; | |
535 | } | |
536 | return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present; | |
537 | } | |
538 | ||
539 | function get_hasvalue() { | |
540 | return 1; | |
541 | } | |
d4b1d58c | 542 | |
6ee09cfe | 543 | function get_info($item) { |
544 | $presentation = empty($item->presentation) ? '' : $item->presentation; | |
d4b1d58c | 545 | |
39790bd8 | 546 | $info = new stdClass(); |
6ee09cfe | 547 | //check the subtype of the multichoice |
548 | //it can be check(c), radio(r) or dropdown(d) | |
549 | $info->subtype = ''; | |
550 | $info->presentation = ''; | |
551 | $info->horizontal = false; | |
d4b1d58c | 552 | |
6ee09cfe | 553 | @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation); |
554 | if(!isset($info->subtype)) { | |
555 | $info->subtype = 'r'; | |
556 | } | |
557 | ||
558 | if($info->subtype != 'd') { | |
559 | @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation); | |
560 | if(isset($info->horizontal) AND $info->horizontal == 1) { | |
561 | $info->horizontal = true; | |
562 | }else { | |
563 | $info->horizontal = false; | |
564 | } | |
565 | } | |
566 | return $info; | |
567 | } | |
d4b1d58c | 568 | |
6ee09cfe | 569 | function item_arrayToString($value) { |
80c12897 | 570 | if (!is_array($value)) { |
6ee09cfe | 571 | return $value; |
572 | } | |
573 | $retval = ''; | |
574 | $arrvals = array_values($value); | |
575 | $arrvals = clean_param($arrvals, PARAM_INT); //prevent sql-injection | |
576 | $retval = $arrvals[0]; | |
b692e4aa | 577 | $sizeofarrvals = sizeof($arrvals); |
80c12897 | 578 | for ($i = 1; $i < $sizeofarrvals; $i++) { |
6ee09cfe | 579 | $retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i]; |
580 | } | |
581 | return $retval; | |
582 | } | |
d4b1d58c | 583 | |
6ee09cfe | 584 | function print_item_radio($presentation, $item, $value, $info, $align) { |
585 | $index = 1; | |
586 | $checked = ''; | |
39790bd8 | 587 | |
afdb1920 AG |
588 | if($info->horizontal) { |
589 | $hv = 'h'; | |
590 | }else { | |
591 | $hv = 'v'; | |
592 | } | |
593 | ||
6ee09cfe | 594 | foreach($presentation as $radio){ |
595 | if($value == $index){ | |
596 | $checked = 'checked="checked"'; | |
597 | }else{ | |
598 | $checked = ''; | |
599 | } | |
600 | $inputname = $item->typ . '_' . $item->id; | |
601 | $inputid = $inputname.'_'.$index; | |
6ee09cfe | 602 | ?> |
afdb1920 AG |
603 | <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> |
604 | <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> | |
605 | <input type="radio" name="<?php echo $inputname;?>" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> /> | |
606 | </span> | |
607 | <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> | |
6ee09cfe | 608 | <label for="<?php echo $inputid;?>"><?php echo text_to_html($radio, true, false, false);?> </label> |
afdb1920 AG |
609 | </span> |
610 | </li> | |
6ee09cfe | 611 | <?php |
6ee09cfe | 612 | $index++; |
613 | } | |
614 | } | |
615 | ||
616 | function print_item_check($presentation, $item, $value, $info, $align) { | |
d4b1d58c | 617 | |
6ee09cfe | 618 | if (is_array($value)) { |
619 | $values = $value; | |
620 | }else { | |
621 | $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); | |
622 | } | |
39790bd8 | 623 | |
afdb1920 AG |
624 | if($info->horizontal) { |
625 | $hv = 'h'; | |
626 | }else { | |
627 | $hv = 'v'; | |
628 | } | |
d4b1d58c | 629 | |
6ee09cfe | 630 | $index = 1; |
631 | $checked = ''; | |
632 | foreach($presentation as $check){ | |
633 | foreach($values as $val) { | |
634 | if($val == $index){ | |
635 | $checked = 'checked="checked"'; | |
636 | break; | |
637 | }else{ | |
638 | $checked = ''; | |
639 | } | |
640 | } | |
641 | $inputname = $item->typ. '_' . $item->id; | |
642 | $inputid = $item->typ. '_' . $item->id.'_'.$index; | |
6ee09cfe | 643 | ?> |
afdb1920 AG |
644 | <li class="feedback_item_check_<?php echo $hv.'_'.$align;?>"> |
645 | <span class="feedback_item_check_<?php echo $hv.'_'.$align;?>"> | |
646 | <input type="checkbox" name="<?php echo $inputname;?>[]" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> /> | |
647 | </span> | |
648 | <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> | |
649 | <label for="<?php echo $inputid;?>"><?php echo text_to_html($check, true, false, false);?> </label> | |
650 | </span> | |
651 | </li> | |
6ee09cfe | 652 | <?php |
6ee09cfe | 653 | $index++; |
654 | } | |
655 | } | |
d4b1d58c | 656 | |
6ee09cfe | 657 | function print_item_dropdown($presentation, $item, $value, $info, $align) { |
afdb1920 AG |
658 | if($info->horizontal) { |
659 | $hv = 'h'; | |
660 | }else { | |
661 | $hv = 'v'; | |
6ee09cfe | 662 | } |
39790bd8 | 663 | |
6ee09cfe | 664 | ?> |
afdb1920 AG |
665 | <li class="feedback_item_select_<?php echo $hv.'_'.$align;?>"> |
666 | <select name="<?php echo $item->typ .'_' . $item->id;?>" size="1"> | |
667 | <option value="0"> </option> | |
668 | <?php | |
669 | $index = 1; | |
670 | $checked = ''; | |
671 | foreach($presentation as $dropdown){ | |
672 | if($value == $index){ | |
673 | $selected = 'selected="selected"'; | |
674 | }else{ | |
675 | $selected = ''; | |
676 | } | |
677 | ?> | |
678 | <option value="<?php echo $index;?>" <?php echo $selected;?>><?php echo text_to_html($dropdown, true, false, false);?></option> | |
679 | <?php | |
680 | $index++; | |
681 | } | |
682 | ?> | |
683 | </select> | |
684 | </li> | |
6ee09cfe | 685 | <?php |
686 | } | |
39790bd8 | 687 | |
79473294 AG |
688 | function set_ignoreempty($item, $ignoreempty=true) { |
689 | $item->options = str_replace(FEEDBACK_MULTICHOICE_IGNOREEMPTY, '', $item->options); | |
690 | if($ignoreempty) { | |
691 | $item->options .= FEEDBACK_MULTICHOICE_IGNOREEMPTY; | |
692 | } | |
693 | } | |
39790bd8 | 694 | |
79473294 AG |
695 | function ignoreempty($item) { |
696 | if(strstr($item->options, FEEDBACK_MULTICHOICE_IGNOREEMPTY)) { | |
697 | return true; | |
698 | } | |
699 | return false; | |
700 | } | |
39790bd8 | 701 | |
79473294 AG |
702 | function set_hidenoselect($item, $hidenoselect=true) { |
703 | $item->options = str_replace(FEEDBACK_MULTICHOICE_HIDENOSELECT, '', $item->options); | |
704 | if($hidenoselect) { | |
705 | $item->options .= FEEDBACK_MULTICHOICE_HIDENOSELECT; | |
706 | } | |
707 | } | |
39790bd8 | 708 | |
79473294 AG |
709 | function hidenoselect($item) { |
710 | if(strstr($item->options, FEEDBACK_MULTICHOICE_HIDENOSELECT)) { | |
711 | return true; | |
712 | } | |
713 | return false; | |
714 | } | |
39790bd8 PS |
715 | |
716 | ||
6cc1599e AG |
717 | function can_switch_require() { |
718 | return true; | |
719 | } | |
6ee09cfe | 720 | } |