|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00017 defined('MOODLE_INTERNAL') OR die('not allowed'); 00018 require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php'); 00019 00020 define('FEEDBACK_MULTICHOICE_TYPE_SEP', '>>>>>'); 00021 define('FEEDBACK_MULTICHOICE_LINE_SEP', '|'); 00022 define('FEEDBACK_MULTICHOICE_ADJUST_SEP', '<<<<<'); 00023 define('FEEDBACK_MULTICHOICE_IGNOREEMPTY', 'i'); 00024 define('FEEDBACK_MULTICHOICE_HIDENOSELECT', 'h'); 00025 00026 class feedback_item_multichoice extends feedback_item_base { 00027 protected $type = "multichoice"; 00028 private $commonparams; 00029 private $item_form; 00030 private $item; 00031 00032 public function init() { 00033 00034 } 00035 00036 public function build_editform($item, $feedback, $cm) { 00037 global $DB, $CFG; 00038 require_once('multichoice_form.php'); 00039 00040 //get the lastposition number of the feedback_items 00041 $position = $item->position; 00042 $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id)); 00043 if ($position == -1) { 00044 $i_formselect_last = $lastposition + 1; 00045 $i_formselect_value = $lastposition + 1; 00046 $item->position = $lastposition + 1; 00047 } else { 00048 $i_formselect_last = $lastposition; 00049 $i_formselect_value = $item->position; 00050 } 00051 //the elements for position dropdownlist 00052 $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true); 00053 00054 $item->presentation = empty($item->presentation) ? '' : $item->presentation; 00055 $info = $this->get_info($item); 00056 00057 $item->ignoreempty = $this->ignoreempty($item); 00058 $item->hidenoselect = $this->hidenoselect($item); 00059 00060 //all items for dependitem 00061 $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item); 00062 $commonparams = array('cmid'=>$cm->id, 00063 'id'=>isset($item->id) ? $item->id : null, 00064 'typ'=>$item->typ, 00065 'items'=>$feedbackitems, 00066 'feedback'=>$feedback->id); 00067 00068 //build the form 00069 $customdata = array('item' => $item, 00070 'common' => $commonparams, 00071 'positionlist' => $positionlist, 00072 'position' => $position, 00073 'info' => $info); 00074 00075 $this->item_form = new feedback_multichoice_form('edit_item.php', $customdata); 00076 } 00077 00078 //this function only can used after the call of build_editform() 00079 public function show_editform() { 00080 $this->item_form->display(); 00081 } 00082 00083 public function is_cancelled() { 00084 return $this->item_form->is_cancelled(); 00085 } 00086 00087 public function get_data() { 00088 if ($this->item = $this->item_form->get_data()) { 00089 return true; 00090 } 00091 return false; 00092 } 00093 00094 public function save_item() { 00095 global $DB; 00096 00097 if (!$item = $this->item_form->get_data()) { 00098 return false; 00099 } 00100 00101 if (isset($item->clone_item) AND $item->clone_item) { 00102 $item->id = ''; //to clone this item 00103 $item->position++; 00104 } 00105 00106 $this->set_ignoreempty($item, $item->ignoreempty); 00107 $this->set_hidenoselect($item, $item->hidenoselect); 00108 00109 $item->hasvalue = $this->get_hasvalue(); 00110 if (!$item->id) { 00111 $item->id = $DB->insert_record('feedback_item', $item); 00112 } else { 00113 $DB->update_record('feedback_item', $item); 00114 } 00115 00116 return $DB->get_record('feedback_item', array('id'=>$item->id)); 00117 } 00118 00119 00120 //gets an array with three values(typ, name, XXX) 00121 //XXX is an object with answertext, answercount and quotient 00122 public function get_analysed($item, $groupid = false, $courseid = false) { 00123 $info = $this->get_info($item); 00124 00125 $analysed_item = array(); 00126 $analysed_item[] = $item->typ; 00127 $analysed_item[] = $item->name; 00128 00129 //get the possible answers 00130 $answers = null; 00131 $answers = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); 00132 if (!is_array($answers)) { 00133 return null; 00134 } 00135 00136 //get the values 00137 $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item)); 00138 if (!$values) { 00139 return null; 00140 } 00141 00142 //get answertext, answercount and quotient for each answer 00143 $analysed_answer = array(); 00144 if ($info->subtype == 'c') { 00145 $sizeofanswers = count($answers); 00146 for ($i = 1; $i <= $sizeofanswers; $i++) { 00147 $ans = null; 00148 $ans->answertext = $answers[$i-1]; 00149 $ans->answercount = 0; 00150 foreach ($values as $value) { 00151 //ist die Antwort gleich dem index der Antworten + 1? 00152 $vallist = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value->value); 00153 foreach ($vallist as $val) { 00154 if ($val == $i) { 00155 $ans->answercount++; 00156 } 00157 } 00158 } 00159 $ans->quotient = $ans->answercount / count($values); 00160 $analysed_answer[] = $ans; 00161 } 00162 } else { 00163 $sizeofanswers = count($answers); 00164 for ($i = 1; $i <= $sizeofanswers; $i++) { 00165 $ans = null; 00166 $ans->answertext = $answers[$i-1]; 00167 $ans->answercount = 0; 00168 foreach ($values as $value) { 00169 //ist die Antwort gleich dem index der Antworten + 1? 00170 if ($value->value == $i) { 00171 $ans->answercount++; 00172 } 00173 } 00174 $ans->quotient = $ans->answercount / count($values); 00175 $analysed_answer[] = $ans; 00176 } 00177 } 00178 $analysed_item[] = $analysed_answer; 00179 return $analysed_item; 00180 } 00181 00182 public function get_printval($item, $value) { 00183 $info = $this->get_info($item); 00184 00185 $printval = ''; 00186 00187 if (!isset($value->value)) { 00188 return $printval; 00189 } 00190 00191 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); 00192 00193 if ($info->subtype == 'c') { 00194 $vallist = array_values(explode (FEEDBACK_MULTICHOICE_LINE_SEP, $value->value)); 00195 $sizeofvallist = count($vallist); 00196 $sizeofpresentation = count($presentation); 00197 for ($i = 0; $i < $sizeofvallist; $i++) { 00198 for ($k = 0; $k < $sizeofpresentation; $k++) { 00199 if ($vallist[$i] == ($k + 1)) {//Die Werte beginnen bei 1, das Array aber mit 0 00200 $printval .= trim($presentation[$k]) . chr(10); 00201 break; 00202 } 00203 } 00204 } 00205 } else { 00206 $index = 1; 00207 foreach ($presentation as $pres) { 00208 if ($value->value == $index) { 00209 $printval = $pres; 00210 break; 00211 } 00212 $index++; 00213 } 00214 } 00215 return $printval; 00216 } 00217 00218 public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) { 00219 $sep_dec = get_string('separator_decimal', 'feedback'); 00220 if (substr($sep_dec, 0, 2) == '[[') { 00221 $sep_dec = FEEDBACK_DECIMAL; 00222 } 00223 00224 $sep_thous = get_string('separator_thousand', 'feedback'); 00225 if (substr($sep_thous, 0, 2) == '[[') { 00226 $sep_thous = FEEDBACK_THOUSAND; 00227 } 00228 00229 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 00230 if ($analysed_item) { 00231 $itemname = $analysed_item[1]; 00232 echo '<tr><th colspan="2" align="left">'; 00233 echo $itemnr.' ('.$item->label.') '.$itemname; 00234 echo '</th></tr>'; 00235 00236 $analysed_vals = $analysed_item[2]; 00237 $pixnr = 0; 00238 foreach ($analysed_vals as $val) { 00239 $intvalue = $pixnr % 10; 00240 $pix = "pics/$intvalue.gif"; 00241 $pixnr++; 00242 $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH); 00243 $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous); 00244 $str_quotient = ''; 00245 if ($val->quotient > 0) { 00246 $str_quotient = ' ('. $quotient . ' %)'; 00247 } 00248 echo '<tr>'; 00249 echo '<td align="left" valign="top"> 00250 - '.trim($val->answertext).': 00251 </td> 00252 <td align="left" style="width:'.FEEDBACK_MAX_PIX_LENGTH.';"> 00253 <img alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" /> 00254 '.$val->answercount.$str_quotient.' 00255 </td>'; 00256 echo '</tr>'; 00257 } 00258 } 00259 } 00260 00261 public function excelprint_item(&$worksheet, $row_offset, 00262 $xls_formats, $item, 00263 $groupid, $courseid = false) { 00264 00265 $analysed_item = $this->get_analysed($item, $groupid, $courseid); 00266 00267 $data = $analysed_item[2]; 00268 00269 //frage schreiben 00270 $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2); 00271 $worksheet->write_string($row_offset, 1, $analysed_item[1], $xls_formats->head2); 00272 if (is_array($data)) { 00273 $sizeofdata = count($data); 00274 for ($i = 0; $i < $sizeofdata; $i++) { 00275 $analysed_data = $data[$i]; 00276 00277 $worksheet->write_string($row_offset, 00278 $i + 2, 00279 trim($analysed_data->answertext), 00280 $xls_formats->head2); 00281 00282 $worksheet->write_number($row_offset + 1, 00283 $i + 2, 00284 $analysed_data->answercount, 00285 $xls_formats->default); 00286 00287 $worksheet->write_number($row_offset + 2, 00288 $i + 2, 00289 $analysed_data->quotient, 00290 $xls_formats->procent); 00291 } 00292 } 00293 $row_offset += 3; 00294 return $row_offset; 00295 } 00296 00304 public function print_item_preview($item) { 00305 global $OUTPUT, $DB; 00306 $info = $this->get_info($item); 00307 $align = right_to_left() ? 'right' : 'left'; 00308 00309 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); 00310 $str_required_mark = '<span class="feedback_required_mark">*</span>'; 00311 00312 //test if required and no value is set so we have to mark this item 00313 //we have to differ check and the other subtypes 00314 $requiredmark = ($item->required == 1) ? $str_required_mark : ''; 00315 00316 //print the question and label 00317 echo '<div class="feedback_item_label_'.$align.'">'; 00318 echo '('.$item->label.') '; 00319 echo format_text($item->name.$requiredmark, true, false, false); 00320 if ($item->dependitem) { 00321 if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) { 00322 echo ' <span class="feedback_depend">'; 00323 echo '('.$dependitem->label.'->'.$item->dependvalue.')'; 00324 echo '</span>'; 00325 } 00326 } 00327 echo '</div>'; 00328 00329 //print the presentation 00330 echo '<div class="feedback_item_presentation_'.$align.'">'; 00331 $index = 1; 00332 $checked = ''; 00333 echo '<ul>'; 00334 if ($info->horizontal) { 00335 $hv = 'h'; 00336 } else { 00337 $hv = 'v'; 00338 } 00339 00340 if ($info->subtype == 'r' AND !$this->hidenoselect($item)) { 00341 //print the "not_selected" item on radiobuttons 00342 ?> 00343 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> 00344 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> 00345 <?php 00346 echo '<input type="radio" '. 00347 'name="'.$item->typ.'_'.$item->id.'[]" '. 00348 'id="'.$item->typ.'_'.$item->id.'_xxx" '. 00349 'value="" checked="checked" />'; 00350 ?> 00351 </span> 00352 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> 00353 <label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>"> 00354 <?php print_string('not_selected', 'feedback');?> 00355 </label> 00356 </span> 00357 </li> 00358 <?php 00359 } 00360 00361 switch($info->subtype) { 00362 case 'r': 00363 $this->print_item_radio($presentation, $item, false, $info, $align); 00364 break; 00365 case 'c': 00366 $this->print_item_check($presentation, $item, false, $info, $align); 00367 break; 00368 case 'd': 00369 $this->print_item_dropdown($presentation, $item, false, $info, $align); 00370 break; 00371 } 00372 echo '</ul>'; 00373 echo '</div>'; 00374 } 00375 00385 public function print_item_complete($item, $value = null, $highlightrequire = false) { 00386 global $OUTPUT; 00387 $info = $this->get_info($item); 00388 $align = right_to_left() ? 'right' : 'left'; 00389 00390 if ($value == null) { 00391 $value = array(); 00392 } 00393 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); 00394 $str_required_mark = '<span class="feedback_required_mark">*</span>'; 00395 00396 //test if required and no value is set so we have to mark this item 00397 //we have to differ check and the other subtypes 00398 // if ($info->subtype == 'c') { 00399 if (is_array($value)) { 00400 $values = $value; 00401 } else { 00402 $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); 00403 } 00404 $highlight = ''; 00405 if ($highlightrequire AND $item->required) { 00406 if (count($values) == 0 OR $values[0] == '' OR $values[0] == 0) { 00407 $highlight = ' missingrequire'; 00408 } 00409 } 00410 $requiredmark = ($item->required == 1) ? $str_required_mark : ''; 00411 // } else { 00412 // if ($highlightrequire AND $item->required AND intval($value) <= 0) { 00413 // $highlight = ' missingrequire'; 00414 // } else { 00415 // $highlight = ''; 00416 // } 00417 // $requiredmark = ($item->required == 1) ? $str_required_mark : ''; 00418 // } 00419 00420 //print the question and label 00421 echo '<div class="feedback_item_label_'.$align.$highlight.'">'; 00422 echo format_text($item->name.$requiredmark, true, false, false); 00423 echo '</div>'; 00424 00425 //print the presentation 00426 echo '<div class="feedback_item_presentation_'.$align.$highlight.'">'; 00427 00428 echo '<ul>'; 00429 if ($info->horizontal) { 00430 $hv = 'h'; 00431 } else { 00432 $hv = 'v'; 00433 } 00434 //print the "not_selected" item on radiobuttons 00435 if ($info->subtype == 'r' AND !$this->hidenoselect($item)) { 00436 ?> 00437 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> 00438 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> 00439 <?php 00440 $checked = ''; 00441 // if (!$value) { 00442 // $checked = 'checked="checked"'; 00443 // } 00444 if (count($values) == 0 OR $values[0] == '' OR $values[0] == 0) { 00445 $checked = 'checked="checked"'; 00446 } 00447 echo '<input type="radio" '. 00448 'name="'.$item->typ.'_'.$item->id.'[]" '. 00449 'id="'.$item->typ.'_'.$item->id.'_xxx" '. 00450 'value="" '.$checked.' />'; 00451 ?> 00452 </span> 00453 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> 00454 <label for="<?php echo $item->typ.'_'.$item->id.'_xxx';?>"> 00455 <?php print_string('not_selected', 'feedback');?> 00456 </label> 00457 </span> 00458 </li> 00459 <?php 00460 } 00461 00462 switch($info->subtype) { 00463 case 'r': 00464 $this->print_item_radio($presentation, $item, $value, $info, $align); 00465 break; 00466 case 'c': 00467 $this->print_item_check($presentation, $item, $value, $info, $align); 00468 break; 00469 case 'd': 00470 $this->print_item_dropdown($presentation, $item, $value, $info, $align); 00471 break; 00472 } 00473 echo '</ul>'; 00474 echo '</div>'; 00475 } 00476 00485 public function print_item_show_value($item, $value = null) { 00486 global $OUTPUT; 00487 $info = $this->get_info($item); 00488 $align = right_to_left() ? 'right' : 'left'; 00489 00490 if ($value == null) { 00491 $value = array(); 00492 } 00493 00494 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); 00495 00496 //test if required and no value is set so we have to mark this item 00497 //we have to differ check and the other subtypes 00498 if ($info->subtype == 'c') { 00499 if (is_array($value)) { 00500 $values = $value; 00501 } else { 00502 $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); 00503 } 00504 } 00505 $requiredmark = ''; 00506 if ($item->required == 1) { 00507 $requiredmark = '<span class="feedback_required_mark">*</span>'; 00508 } 00509 00510 //print the question and label 00511 echo '<div class="feedback_item_label_'.$align.'">'; 00512 echo '('.$item->label.') '; 00513 echo format_text($item->name . $requiredmark, true, false, false); 00514 echo '</div>'; 00515 00516 //print the presentation 00517 echo '<div class="feedback_item_presentation_'.$align.'">'; 00518 $index = 1; 00519 if ($info->subtype == 'c') { 00520 echo $OUTPUT->box_start('generalbox boxalign'.$align); 00521 foreach ($presentation as $pres) { 00522 foreach ($values as $val) { 00523 if ($val == $index) { 00524 echo '<div class="feedback_item_multianswer">'; 00525 echo text_to_html($pres, true, false, false); 00526 echo '</div>'; 00527 break; 00528 } 00529 } 00530 $index++; 00531 } 00532 echo $OUTPUT->box_end(); 00533 } else { 00534 foreach ($presentation as $pres) { 00535 if ($value == $index) { 00536 echo $OUTPUT->box_start('generalbox boxalign'.$align); 00537 echo text_to_html($pres, true, false, false); 00538 echo $OUTPUT->box_end(); 00539 break; 00540 } 00541 $index++; 00542 } 00543 } 00544 echo '</div>'; 00545 } 00546 00547 public function check_value($value, $item) { 00548 $info = $this->get_info($item); 00549 00550 if ($item->required != 1) { 00551 return true; 00552 } 00553 00554 if (!isset($value) OR !is_array($value) OR $value[0] == '' OR $value[0] == 0) { 00555 return false; 00556 } 00557 00558 return true; 00559 } 00560 00561 public function create_value($data) { 00562 $vallist = $data; 00563 return trim($this->item_array_to_string($vallist)); 00564 } 00565 00566 //compares the dbvalue with the dependvalue 00567 //dbvalue is the number of one selection 00568 //dependvalue is the presentation of one selection 00569 public function compare_value($item, $dbvalue, $dependvalue) { 00570 00571 if (is_array($dbvalue)) { 00572 $dbvalues = $dbvalue; 00573 } else { 00574 $dbvalues = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $dbvalue); 00575 } 00576 00577 $info = $this->get_info($item); 00578 $presentation = explode (FEEDBACK_MULTICHOICE_LINE_SEP, $info->presentation); 00579 $index = 1; 00580 foreach ($presentation as $pres) { 00581 foreach ($dbvalues as $dbval) { 00582 if ($dbval == $index AND trim($pres) == $dependvalue) { 00583 return true; 00584 } 00585 } 00586 $index++; 00587 } 00588 return false; 00589 } 00590 00591 public function get_presentation($data) { 00592 $present = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($data->itemvalues)); 00593 if (!isset($data->subtype)) { 00594 $subtype = 'r'; 00595 } else { 00596 $subtype = substr($data->subtype, 0, 1); 00597 } 00598 if (isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') { 00599 $present .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1'; 00600 } 00601 return $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$present; 00602 } 00603 00604 public function get_hasvalue() { 00605 return 1; 00606 } 00607 00608 private function get_info($item) { 00609 $presentation = empty($item->presentation) ? '' : $item->presentation; 00610 00611 $info = new stdClass(); 00612 //check the subtype of the multichoice 00613 //it can be check(c), radio(r) or dropdown(d) 00614 $info->subtype = ''; 00615 $info->presentation = ''; 00616 $info->horizontal = false; 00617 00618 $parts = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation); 00619 @list($info->subtype, $info->presentation) = $parts; 00620 if (!isset($info->subtype)) { 00621 $info->subtype = 'r'; 00622 } 00623 00624 if ($info->subtype != 'd') { 00625 $parts = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation); 00626 @list($info->presentation, $info->horizontal) = $parts; 00627 if (isset($info->horizontal) AND $info->horizontal == 1) { 00628 $info->horizontal = true; 00629 } else { 00630 $info->horizontal = false; 00631 } 00632 } 00633 return $info; 00634 } 00635 00636 private function item_array_to_string($value) { 00637 if (!is_array($value)) { 00638 return $value; 00639 } 00640 $retval = ''; 00641 $arrvals = array_values($value); 00642 $arrvals = clean_param_array($arrvals, PARAM_INT); //prevent sql-injection 00643 $retval = $arrvals[0]; 00644 $sizeofarrvals = count($arrvals); 00645 for ($i = 1; $i < $sizeofarrvals; $i++) { 00646 $retval .= FEEDBACK_MULTICHOICE_LINE_SEP.$arrvals[$i]; 00647 } 00648 return $retval; 00649 } 00650 00651 private function print_item_radio($presentation, $item, $value, $info, $align) { 00652 $index = 1; 00653 $checked = ''; 00654 00655 if (is_array($value)) { 00656 $values = $value; 00657 } else { 00658 $values = array($value); 00659 } 00660 00661 if ($info->horizontal) { 00662 $hv = 'h'; 00663 } else { 00664 $hv = 'v'; 00665 } 00666 00667 foreach ($presentation as $radio) { 00668 foreach ($values as $val) { 00669 if ($val == $index) { 00670 $checked = 'checked="checked"'; 00671 break; 00672 } else { 00673 $checked = ''; 00674 } 00675 } 00676 $inputname = $item->typ . '_' . $item->id; 00677 $inputid = $inputname.'_'.$index; 00678 ?> 00679 <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> 00680 <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>"> 00681 <?php 00682 echo '<input type="radio" '. 00683 'name="'.$inputname.'[]" '. 00684 'id="'.$inputid.'" '. 00685 'value="'.$index.'" '.$checked.' />'; 00686 ?> 00687 </span> 00688 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> 00689 <label for="<?php echo $inputid;?>"> 00690 <?php echo text_to_html($radio, true, false, false);?> 00691 </label> 00692 </span> 00693 </li> 00694 <?php 00695 $index++; 00696 } 00697 } 00698 00699 private function print_item_check($presentation, $item, $value, $info, $align) { 00700 00701 if (is_array($value)) { 00702 $values = $value; 00703 } else { 00704 $values = explode(FEEDBACK_MULTICHOICE_LINE_SEP, $value); 00705 } 00706 00707 if ($info->horizontal) { 00708 $hv = 'h'; 00709 } else { 00710 $hv = 'v'; 00711 } 00712 00713 $index = 1; 00714 $checked = ''; 00715 foreach ($presentation as $check) { 00716 foreach ($values as $val) { 00717 if ($val == $index) { 00718 $checked = 'checked="checked"'; 00719 break; 00720 } else { 00721 $checked = ''; 00722 } 00723 } 00724 $inputname = $item->typ. '_' . $item->id; 00725 $inputid = $item->typ. '_' . $item->id.'_'.$index; 00726 ?> 00727 <li class="feedback_item_check_<?php echo $hv.'_'.$align;?>"> 00728 <span class="feedback_item_check_<?php echo $hv.'_'.$align;?>"> 00729 <?php 00730 echo '<input type="checkbox" '. 00731 'name="'.$inputname.'[]" '. 00732 'id="'.$inputid.'" '. 00733 'value="'.$index.'" '.$checked.' />'; 00734 ?> 00735 </span> 00736 <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>"> 00737 <label for="<?php echo $inputid;?>"> 00738 <?php echo text_to_html($check, true, false, false);?> 00739 </label> 00740 </span> 00741 </li> 00742 <?php 00743 $index++; 00744 } 00745 } 00746 00747 private function print_item_dropdown($presentation, $item, $value, $info, $align) { 00748 if (is_array($value)) { 00749 $values = $value; 00750 } else { 00751 $values = array($value); 00752 } 00753 00754 if ($info->horizontal) { 00755 $hv = 'h'; 00756 } else { 00757 $hv = 'v'; 00758 } 00759 00760 ?> 00761 <li class="feedback_item_select_<?php echo $hv.'_'.$align;?>"> 00762 <select name="<?php echo $item->typ .'_' . $item->id;?>[]" size="1"> 00763 <option value="0"> </option> 00764 <?php 00765 $index = 1; 00766 $selected = ''; 00767 foreach ($presentation as $dropdown) { 00768 foreach ($values as $val) { 00769 if ($val == $index) { 00770 $selected = 'selected="selected"'; 00771 break; 00772 } else { 00773 $selected = ''; 00774 } 00775 } 00776 ?> 00777 <option value="<?php echo $index;?>" <?php echo $selected;?>> 00778 <?php echo text_to_html($dropdown, true, false, false);?> 00779 </option> 00780 <?php 00781 $index++; 00782 } 00783 ?> 00784 </select> 00785 </li> 00786 <?php 00787 } 00788 00789 public function set_ignoreempty($item, $ignoreempty=true) { 00790 $item->options = str_replace(FEEDBACK_MULTICHOICE_IGNOREEMPTY, '', $item->options); 00791 if ($ignoreempty) { 00792 $item->options .= FEEDBACK_MULTICHOICE_IGNOREEMPTY; 00793 } 00794 } 00795 00796 public function ignoreempty($item) { 00797 if (strstr($item->options, FEEDBACK_MULTICHOICE_IGNOREEMPTY)) { 00798 return true; 00799 } 00800 return false; 00801 } 00802 00803 public function set_hidenoselect($item, $hidenoselect=true) { 00804 $item->options = str_replace(FEEDBACK_MULTICHOICE_HIDENOSELECT, '', $item->options); 00805 if ($hidenoselect) { 00806 $item->options .= FEEDBACK_MULTICHOICE_HIDENOSELECT; 00807 } 00808 } 00809 00810 public function hidenoselect($item) { 00811 if (strstr($item->options, FEEDBACK_MULTICHOICE_HIDENOSELECT)) { 00812 return true; 00813 } 00814 return false; 00815 } 00816 00817 public function can_switch_require() { 00818 return true; 00819 } 00820 00821 public function value_type() { 00822 return PARAM_INT; 00823 } 00824 00825 public function value_is_array() { 00826 return true; 00827 } 00828 }