MDL-28014 - unpropitious use of bcmod()
[moodle.git] / mod / feedback / item / multichoicerated / lib.php
CommitLineData
1adbd2c3 1<?php
01910dff 2defined('MOODLE_INTERNAL') OR die('not allowed');
6ee09cfe 3require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
4
5define('FEEDBACK_RADIORATED_ADJUST_SEP', '<<<<<');
6
7define('FEEDBACK_MULTICHOICERATED_MAXCOUNT', 10); //count of possible items
8define('FEEDBACK_MULTICHOICERATED_VALUE_SEP', '####');
9define('FEEDBACK_MULTICHOICERATED_VALUE_SEP2', '/');
10define('FEEDBACK_MULTICHOICERATED_TYPE_SEP', '>>>>>');
11define('FEEDBACK_MULTICHOICERATED_LINE_SEP', '|');
12define('FEEDBACK_MULTICHOICERATED_ADJUST_SEP', '<<<<<');
79473294
AG
13define('FEEDBACK_MULTICHOICERATED_IGNOREEMPTY', 'i');
14define('FEEDBACK_MULTICHOICERATED_HIDENOSELECT', 'h');
6ee09cfe 15
16class feedback_item_multichoicerated extends feedback_item_base {
17 var $type = "multichoicerated";
271fdd62
AG
18 var $commonparams;
19 var $item_form;
20 var $item;
39790bd8 21
6ee09cfe 22 function init() {
d4b1d58c 23
6ee09cfe 24 }
d4b1d58c 25
271fdd62
AG
26 function build_editform($item, $feedback, $cm) {
27 global $DB, $CFG;
6ee09cfe 28 require_once('multichoicerated_form.php');
d4b1d58c 29
271fdd62
AG
30 //get the lastposition number of the feedback_items
31 $position = $item->position;
32 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
33 if($position == -1){
34 $i_formselect_last = $lastposition + 1;
35 $i_formselect_value = $lastposition + 1;
36 $item->position = $lastposition + 1;
37 }else {
38 $i_formselect_last = $lastposition;
39 $i_formselect_value = $item->position;
40 }
41 //the elements for position dropdownlist
42 $positionlist = array_slice(range(0,$i_formselect_last),1,$i_formselect_last,true);
39790bd8 43
6ee09cfe 44 $item->presentation = empty($item->presentation) ? '' : $item->presentation;
6ee09cfe 45 $info = $this->get_info($item);
39790bd8 46
79473294
AG
47 $item->ignoreempty = $this->ignoreempty($item);
48 $item->hidenoselect = $this->hidenoselect($item);
6ee09cfe 49
73043833
AG
50 //all items for dependitem
51 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
271fdd62
AG
52 $commonparams = array('cmid'=>$cm->id,
53 'id'=>isset($item->id) ? $item->id : NULL,
54 'typ'=>$item->typ,
73043833 55 'items'=>$feedbackitems,
271fdd62 56 'feedback'=>$feedback->id);
d4b1d58c 57
271fdd62
AG
58 //build the form
59 $this->item_form = new feedback_multichoicerated_form('edit_item.php', array('item'=>$item, 'common'=>$commonparams, 'positionlist'=>$positionlist, 'position'=>$position, 'info'=>$info));
60 }
d4b1d58c 61
271fdd62
AG
62 //this function only can used after the call of build_editform()
63 function show_editform() {
64 $this->item_form->display();
65 }
39790bd8 66
271fdd62
AG
67 function is_cancelled() {
68 return $this->item_form->is_cancelled();
69 }
6ee09cfe 70
271fdd62
AG
71 function get_data() {
72 if($this->item = $this->item_form->get_data()) {
73 return true;
74 }
75 return false;
76 }
d4b1d58c 77
271fdd62
AG
78 function save_item() {
79 global $DB;
39790bd8 80
271fdd62
AG
81 if(!$item = $this->item_form->get_data()) {
82 return false;
83 }
39790bd8 84
b8baf0ad 85 if(isset($item->clone_item) AND $item->clone_item) {
9e1aed53
AG
86 $item->id = ''; //to clone this item
87 $item->position++;
88 }
39790bd8
PS
89
90 $this->set_ignoreempty($item, $item->ignoreempty);
79473294 91 $this->set_hidenoselect($item, $item->hidenoselect);
39790bd8 92
45c2f92a 93 $item->hasvalue = $this->get_hasvalue();
271fdd62
AG
94 if(!$item->id) {
95 $item->id = $DB->insert_record('feedback_item', $item);
96 }else {
97 $DB->update_record('feedback_item', $item);
98 }
39790bd8 99
271fdd62 100 return $DB->get_record('feedback_item', array('id'=>$item->id));
6ee09cfe 101 }
102
271fdd62 103
6ee09cfe 104 //liefert ein eindimensionales Array mit drei Werten(typ, name, XXX)
105 //XXX ist ein eindimensionales Array (Mittelwert der Werte der Antworten bei Typ Radio_rated) Jedes Element ist eine Struktur (answertext, avg)
106 function get_analysed($item, $groupid = false, $courseid = false) {
107 $analysedItem = array();
108 $analysedItem[] = $item->typ;
109 $analysedItem[] = $item->name;
d4b1d58c 110
6ee09cfe 111 //die moeglichen Antworten extrahieren
112 $info = $this->get_info($item);
113 $lines = null;
294ce987 114 $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
6ee09cfe 115 if(!is_array($lines)) return null;
116
117 //die Werte holen
79473294 118 $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item));
6ee09cfe 119 if(!$values) return null;
120 //schleife ueber den Werten und ueber die Antwortmoeglichkeiten
d4b1d58c 121
6ee09cfe 122 $analysedAnswer = array();
b692e4aa
AB
123 $sizeoflines = sizeof($lines);
124 for($i = 1; $i <= $sizeoflines; $i++) {
6ee09cfe 125 $item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]);
126 $ans = null;
127 $ans->answertext = $item_values[1];
128 $avg = 0.0;
129 $anscount = 0;
130 foreach($values as $value) {
131 //ist die Antwort gleich dem index der Antworten + 1?
132 if ($value->value == $i) {
133 $avg += $item_values[0]; //erst alle Werte aufsummieren
134 $anscount++;
135 }
136 }
137 $ans->answercount = $anscount;
138 $ans->avg = doubleval($avg) / doubleval(sizeof($values));
139 $ans->value = $item_values[0];
140 $ans->quotient = $ans->answercount / sizeof($values);
141 $analysedAnswer[] = $ans;
142 }
143 $analysedItem[] = $analysedAnswer;
144 return $analysedItem;
145 }
146
147 function get_printval($item, $value) {
148 $printval = '';
d4b1d58c 149
6ee09cfe 150 if(!isset($value->value)) return $printval;
d4b1d58c 151
6ee09cfe 152 $info = $this->get_info($item);
d4b1d58c 153
294ce987 154 $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
6ee09cfe 155 $index = 1;
156 foreach($presentation as $pres){
157 if($value->value == $index){
158 $item_label = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
159 $printval = $item_label[1];
160 break;
161 }
162 $index++;
163 }
164 return $printval;
165 }
166
efc59167 167 function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
6ee09cfe 168 $sep_dec = get_string('separator_decimal', 'feedback');
169 if(substr($sep_dec, 0, 2) == '[['){
170 $sep_dec = FEEDBACK_DECIMAL;
171 }
d4b1d58c 172
6ee09cfe 173 $sep_thous = get_string('separator_thousand', 'feedback');
174 if(substr($sep_thous, 0, 2) == '[['){
175 $sep_thous = FEEDBACK_THOUSAND;
176 }
d4b1d58c 177
6ee09cfe 178 $analysedItem = $this->get_analysed($item, $groupid, $courseid);
179 if($analysedItem) {
180 //echo '<table>';
efc59167 181 // $itemnr++;
b7a47958 182 echo '<tr><th colspan="2" align="left">'. $itemnr . '&nbsp;('. $item->label .') ' . $analysedItem[1] .'</th></tr>';
6ee09cfe 183 $analysedVals = $analysedItem[2];
184 $pixnr = 0;
185 $avg = 0.0;
186 foreach($analysedVals as $val) {
b7030c3d 187 $intvalue = $pixnr % 10;
6ee09cfe 188 $pix = "pics/$intvalue.gif";
189 $pixnr++;
190 $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
d4b1d58c 191
6ee09cfe 192 $avg += $val->avg;
193 $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
194 echo '<tr><td align="left" valign="top">-&nbsp;&nbsp;' . trim($val->answertext) . ' ('.$val->value.'):</td><td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'"><img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />' . $val->answercount. (($val->quotient > 0)?'&nbsp;('. $quotient . '&nbsp;%)':'') . '</td></tr>';
195 }
196 $avg = number_format(($avg), 2, $sep_dec, $sep_thous);
197 echo '<tr><td align="left" colspan="2"><b>'.get_string('average', 'feedback').': '.$avg.'</b></td></tr>';
198 //echo '</table>';
199 }
efc59167 200 // return $itemnr;
6ee09cfe 201 }
202
51129b99 203 function excelprint_item(&$worksheet, $rowOffset, $xlsFormats, $item, $groupid, $courseid = false) {
6ee09cfe 204 $analysed_item = $this->get_analysed($item, $groupid, $courseid);
205
6ee09cfe 206 $data = $analysed_item[2];
207
51129b99 208 // $worksheet->setFormat("<l><f><ro2><vo><c:green>");
6ee09cfe 209 //frage schreiben
51129b99
AG
210 $worksheet->write_string($rowOffset, 0, $item->label, $xlsFormats->head2);
211 $worksheet->write_string($rowOffset, 1, $analysed_item[1], $xlsFormats->head2);
6ee09cfe 212 if(is_array($data)) {
213 $avg = 0.0;
b692e4aa
AB
214 $sizeofdata = sizeof($data);
215 for($i = 0; $i < $sizeofdata; $i++) {
6ee09cfe 216 $aData = $data[$i];
d4b1d58c 217
51129b99
AG
218 // $worksheet->setFormat("<l><f><ro2><vo><c:blue>");
219 $worksheet->write_string($rowOffset, $i + 2, trim($aData->answertext).' ('.$aData->value.')', $xlsFormats->value_bold);
d4b1d58c 220
51129b99
AG
221 // $worksheet->setFormat("<l><vo>");
222 $worksheet->write_number($rowOffset + 1, $i + 2, $aData->answercount, $xlsFormats->default);
6ee09cfe 223 //$worksheet->setFormat("<l><f><vo>");
224 //$worksheet->write_number($rowOffset + 2, $i + 1, $aData->avg);
225 $avg += $aData->avg;
226 }
227 //mittelwert anzeigen
51129b99
AG
228 // $worksheet->setFormat("<l><f><ro2><vo><c:red>");
229 $worksheet->write_string($rowOffset, sizeof($data) + 2, get_string('average', 'feedback'), $xlsFormats->value_bold);
d4b1d58c 230
51129b99
AG
231 // $worksheet->setFormat("<l><f><vo>");
232 $worksheet->write_number($rowOffset + 1, sizeof($data) + 2, $avg, $xlsFormats->value_bold);
6ee09cfe 233 }
234 $rowOffset +=2 ;
235 return $rowOffset;
236 }
39790bd8
PS
237
238 /**
9d5fbd65
AG
239 * print the item at the edit-page of feedback
240 *
241 * @global object
242 * @param object $item
243 * @return void
244 */
245 function print_item_preview($item) {
73043833 246 global $OUTPUT, $DB;
39790bd8 247
9d5fbd65
AG
248 $align = right_to_left() ? 'right' : 'left';
249 $info = $this->get_info($item);
6ee09cfe 250
9d5fbd65
AG
251 $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
252 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
afdb1920
AG
253 //print the question and label
254 echo '<div class="feedback_item_label_'.$align.'">';
255 echo '('.$item->label.') ';
256 echo format_text($item->name.$requiredmark, true, false, false);
73043833
AG
257 if($item->dependitem) {
258 if($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
259 echo ' <span class="feedback_depend">('.$dependitem->label.'-&gt;'.$item->dependvalue.')</span>';
260 }
261 }
afdb1920 262 echo '</div>';
39790bd8 263
afdb1920
AG
264 //print the presentation
265 echo '<div class="feedback_item_presentation_'.$align.'">';
9d5fbd65
AG
266 switch($info->subtype) {
267 case 'r':
268 $this->print_item_radio($item, false, $info, $align, true, $lines);
269 break;
270 case 'd':
271 $this->print_item_dropdown($item, false, $info, $align, true, $lines);
272 break;
273 }
afdb1920 274 echo '</div>';
9d5fbd65 275 }
39790bd8
PS
276
277 /**
9d5fbd65
AG
278 * print the item at the complete-page of feedback
279 *
280 * @global object
281 * @param object $item
282 * @param string $value
283 * @param bool $highlightrequire
284 * @return void
285 */
286 function print_item_complete($item, $value = '', $highlightrequire = false) {
d4b1d58c 287 global $OUTPUT;
e372f4c7 288 $align = right_to_left() ? 'right' : 'left';
6ee09cfe 289 $info = $this->get_info($item);
d4b1d58c 290
294ce987 291 $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
6ee09cfe 292 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
293 if($highlightrequire AND $item->required AND intval($value) <= 0) {
afdb1920 294 $highlight = ' missingrequire';
6ee09cfe 295 }else {
296 $highlight = '';
297 }
39790bd8 298
afdb1920
AG
299 //print the question and label
300 echo '<div class="feedback_item_label_'.$align.$highlight.'">';
301 echo format_text($item->name.$requiredmark, true, false, false);
302 echo '</div>';
39790bd8 303
afdb1920
AG
304 //print the presentation
305 echo '<div class="feedback_item_presentation_'.$align.$highlight.'">';
9d5fbd65
AG
306 switch($info->subtype) {
307 case 'r':
308 $this->print_item_radio($item, $value, $info, $align, false, $lines);
309 break;
310 case 'd':
311 $this->print_item_dropdown($item, $value, $info, $align, false, $lines);
312 break;
313 }
afdb1920 314 echo '</div>';
9d5fbd65
AG
315 }
316
39790bd8 317 /**
9d5fbd65
AG
318 * print the item at the complete-page of feedback
319 *
320 * @global object
321 * @param object $item
322 * @param string $value
323 * @return void
324 */
325 function print_item_show_value($item, $value = '') {
326 global $OUTPUT;
327 $align = right_to_left() ? 'right' : 'left';
328 $info = $this->get_info($item);
329
330 $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
331 $requiredmark = ($item->required == 1)?'<span class="feedback_required_mark">*</span>':'';
39790bd8 332
afdb1920
AG
333 //print the question and label
334 echo '<div class="feedback_item_label_'.$align.'">';
9d5fbd65 335 echo '('.$item->label.') ';
b7a47958 336 echo format_text($item->name . $requiredmark, true, false, false);
afdb1920 337 echo '</div>';
39790bd8 338
afdb1920
AG
339 //print the presentation
340 echo '<div class="feedback_item_presentation_'.$align.'">';
6ee09cfe 341 $index = 1;
9d5fbd65
AG
342 foreach($lines as $line){
343 if($value == $index){
344 $item_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
345 echo $OUTPUT->box_start('generalbox boxalign'.$align);
346 echo text_to_html($item_value[1], true, false, false);
347 echo $OUTPUT->box_end();
348 break;
6ee09cfe 349 }
9d5fbd65 350 $index++;
6ee09cfe 351 }
afdb1920 352 echo '</div>';
6ee09cfe 353 }
354
355 function check_value($value, $item) {
356 if((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) return true;
357 if(intval($value) > 0)return true;
358 return false;
359 }
360
361 function create_value($data) {
79473294 362 $data = trim($data);
6ee09cfe 363 return $data;
364 }
365
73043833
AG
366 //compares the dbvalue with the dependvalue
367 //dbvalue is the number of one selection
368 //dependvalue is the presentation of one selection
369 function compare_value($item, $dbvalue, $dependvalue) {
370
371 if (is_array($dbvalue)) {
372 $dbvalues = $dbvalue;
373 }else {
374 $dbvalues = explode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $dbvalue);
375 }
39790bd8 376
73043833
AG
377 $info = $this->get_info($item);
378 $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
379 $index = 1;
380 foreach($presentation as $pres) {
381 $presvalues = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
382
383 foreach($dbvalues as $dbval) {
384 if($dbval == $index AND trim($presvalues[1]) == $dependvalue) {
385 return true;
386 }
387 }
388 $index++;
389 }
390 return false;
391 }
6ee09cfe 392 function get_presentation($data) {
393 // $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues));
394 $present = $this->prepare_presentation_values_save(trim($data->itemvalues), FEEDBACK_MULTICHOICERATED_VALUE_SEP2, FEEDBACK_MULTICHOICERATED_VALUE_SEP);
395 // $present = str_replace("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, trim($data->itemvalues));
396 if(!isset($data->subtype)) {
397 $subtype = 'r';
398 }else {
399 $subtype = substr($data->subtype, 0, 1);
400 }
401 if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
402 $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
403 }
404 return $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$present;
405 }
406
407 function get_hasvalue() {
408 return 1;
409 }
d4b1d58c 410
6ee09cfe 411 function get_info($item) {
412 $presentation = empty($item->presentation) ? '' : $item->presentation;
d4b1d58c 413
39790bd8 414 $info = new stdClass();
6ee09cfe 415 //check the subtype of the multichoice
416 //it can be check(c), radio(r) or dropdown(d)
417 $info->subtype = '';
418 $info->presentation = '';
419 $info->horizontal = false;
39790bd8 420
271fdd62 421 @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICERATED_TYPE_SEP, $item->presentation);
d4b1d58c 422
6ee09cfe 423 if(!isset($info->subtype)) {
424 $info->subtype = 'r';
425 }
426
427
428 if($info->subtype != 'd') {
271fdd62
AG
429 @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICERATED_ADJUST_SEP, $info->presentation);
430
6ee09cfe 431 if(isset($info->horizontal) AND $info->horizontal == 1) {
432 $info->horizontal = true;
433 }else {
434 $info->horizontal = false;
435 }
436 }
437
271fdd62 438 $info->values = $this->prepare_presentation_values_print($info->presentation, FEEDBACK_MULTICHOICERATED_VALUE_SEP, FEEDBACK_MULTICHOICERATED_VALUE_SEP2);
6ee09cfe 439 return $info;
440 }
d4b1d58c 441
9d5fbd65 442 function print_item_radio($item, $value, $info, $align, $showrating, $lines) {
6ee09cfe 443 $index = 1;
444 $checked = '';
39790bd8 445
6ee09cfe 446 if($info->horizontal) {
afdb1920
AG
447 $hv = 'h';
448 }else {
449 $hv = 'v';
6ee09cfe 450 }
afdb1920 451 echo '<ul>';
79473294
AG
452 if(!$this->hidenoselect($item)) {
453 ?>
454 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
455 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
456 <input type="radio" name="<?php echo $item->typ . '_' . $item->id ;?>" id="<?php echo $item->typ . '_' . $item->id.'_xxx';?>" value="" checked="checked" />
457 </span>
458 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
459 <label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"><?php print_string('not_selected', 'feedback');?>&nbsp;</label>
460 </span>
461 </li>
462 <?php
463 }
6ee09cfe 464 foreach($lines as $line){
465 if($value == $index){
466 $checked = 'checked="checked"';
467 }else{
468 $checked = '';
469 }
470 $radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
471 $inputname = $item->typ . '_' . $item->id;
472 $inputid = $inputname.'_'.$index;
39790bd8 473 ?>
afdb1920
AG
474 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
475 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
476 <input type="radio" name="<?php echo $inputname;?>" id="<?php echo $inputid;?>" value="<?php echo $index;?>" <?php echo $checked;?> />
477 </span>
478 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
479 <label for="<?php echo $inputid;?>">
480 <?php
481 if($showrating) {
482 echo text_to_html('('.$radio_value[0].') '.$radio_value[1], true, false, false);
483 }else {
484 echo text_to_html($radio_value[1], true, false, false);
485 }
486 ?>
487 </label>
488 </span>
489 </li>
6ee09cfe 490 <?php
6ee09cfe 491 $index++;
492 }
afdb1920 493 echo '</ul>';
6ee09cfe 494 }
d4b1d58c 495
9d5fbd65 496 function print_item_dropdown($item, $value, $info, $align, $showrating, $lines) {
afdb1920
AG
497 if($info->horizontal) {
498 $hv = 'h';
499 }else {
500 $hv = 'v';
6ee09cfe 501 }
afdb1920
AG
502 echo '<ul>';
503 ?>
504 <li class="feedback_item_select_<?php echo $hv.'_'.$align;?>">
6a471fe0 505 <select name="<?php echo $item->typ.'_'.$item->id;?>">
afdb1920
AG
506 <option value="0">&nbsp;</option>
507 <?php
508 $index = 1;
509 $checked = '';
510 foreach($lines as $line){
511 if($value == $index){
512 $selected = 'selected="selected"';
513 }else{
514 $selected = '';
515 }
516 $dropdown_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
517 if($showrating) {
518 echo '<option value="'.$index.'" '.$selected.'>'.clean_text('('.$dropdown_value[0].') '.$dropdown_value[1]).'</option>';
519 }else {
520 echo '<option value="'.$index.'" '.$selected.'>'.clean_text($dropdown_value[1]).'</option>';
521 }
522 $index++;
523 }
524 ?>
525 </select>
526 </li>
527 <?php
528 echo '</ul>';
6ee09cfe 529 }
d4b1d58c 530
271fdd62
AG
531 function prepare_presentation_values($linesep1, $linesep2, $valuestring, $valuesep1, $valuesep2) {
532 $lines = explode($linesep1, $valuestring);
6ee09cfe 533 $newlines = array();
534 foreach($lines as $line) {
535 $value = '';
536 $text = '';
537 if(strpos($line, $valuesep1) === false) {
538 $value = 0;
539 $text = $line;
540 }else {
541 @list($value, $text) = explode($valuesep1, $line, 2);
542 }
d4b1d58c 543
6ee09cfe 544 $value = intval($value);
545 $newlines[] = $value.$valuesep2.$text;
546 }
271fdd62 547 $newlines = implode($linesep2, $newlines);
6ee09cfe 548 return $newlines;
549 }
d4b1d58c 550
271fdd62
AG
551 function prepare_presentation_values_print($valuestring, $valuesep1, $valuesep2) {
552 return $this->prepare_presentation_values(FEEDBACK_MULTICHOICERATED_LINE_SEP, "\n", $valuestring, $valuesep1, $valuesep2);
553 }
d4b1d58c 554
271fdd62
AG
555 function prepare_presentation_values_save($valuestring, $valuesep1, $valuesep2) {
556 return $this->prepare_presentation_values("\n", FEEDBACK_MULTICHOICERATED_LINE_SEP, $valuestring, $valuesep1, $valuesep2);
6ee09cfe 557 }
79473294
AG
558
559 function set_ignoreempty($item, $ignoreempty=true) {
560 $item->options = str_replace(FEEDBACK_MULTICHOICERATED_IGNOREEMPTY, '', $item->options);
561 if($ignoreempty) {
562 $item->options .= FEEDBACK_MULTICHOICERATED_IGNOREEMPTY;
563 }
564 }
39790bd8 565
79473294
AG
566 function ignoreempty($item) {
567 if(strstr($item->options, FEEDBACK_MULTICHOICERATED_IGNOREEMPTY)) {
568 return true;
569 }
570 return false;
571 }
39790bd8 572
79473294
AG
573 function set_hidenoselect($item, $hidenoselect=true) {
574 $item->options = str_replace(FEEDBACK_MULTICHOICERATED_HIDENOSELECT, '', $item->options);
575 if($hidenoselect) {
576 $item->options .= FEEDBACK_MULTICHOICERATED_HIDENOSELECT;
577 }
578 }
39790bd8 579
79473294
AG
580 function hidenoselect($item) {
581 if(strstr($item->options, FEEDBACK_MULTICHOICERATED_HIDENOSELECT)) {
582 return true;
583 }
584 return false;
585 }
39790bd8 586
6cc1599e
AG
587 function can_switch_require() {
588 return true;
589 }
79473294 590
6ee09cfe 591}