[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/feedback/item/multichoicerated/ -> lib.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  defined('MOODLE_INTERNAL') OR die('not allowed');
  18  require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_class.php');
  19  
  20  define('FEEDBACK_RADIORATED_ADJUST_SEP', '<<<<<');
  21  
  22  define('FEEDBACK_MULTICHOICERATED_MAXCOUNT', 10); //count of possible items
  23  define('FEEDBACK_MULTICHOICERATED_VALUE_SEP', '####');
  24  define('FEEDBACK_MULTICHOICERATED_VALUE_SEP2', '/');
  25  define('FEEDBACK_MULTICHOICERATED_TYPE_SEP', '>>>>>');
  26  define('FEEDBACK_MULTICHOICERATED_LINE_SEP', '|');
  27  define('FEEDBACK_MULTICHOICERATED_ADJUST_SEP', '<<<<<');
  28  define('FEEDBACK_MULTICHOICERATED_IGNOREEMPTY', 'i');
  29  define('FEEDBACK_MULTICHOICERATED_HIDENOSELECT', 'h');
  30  
  31  class feedback_item_multichoicerated extends feedback_item_base {
  32      protected $type = "multichoicerated";
  33      private $commonparams;
  34      private $item_form;
  35      private $item;
  36  
  37      public function init() {
  38  
  39      }
  40  
  41      public function build_editform($item, $feedback, $cm) {
  42          global $DB, $CFG;
  43          require_once ('multichoicerated_form.php');
  44  
  45          //get the lastposition number of the feedback_items
  46          $position = $item->position;
  47          $lastposition = $DB->count_records('feedback_item', array('feedback'=>$feedback->id));
  48          if ($position == -1) {
  49              $i_formselect_last = $lastposition + 1;
  50              $i_formselect_value = $lastposition + 1;
  51              $item->position = $lastposition + 1;
  52          } else {
  53              $i_formselect_last = $lastposition;
  54              $i_formselect_value = $item->position;
  55          }
  56          //the elements for position dropdownlist
  57          $positionlist = array_slice(range(0, $i_formselect_last), 1, $i_formselect_last, true);
  58  
  59          $item->presentation = empty($item->presentation) ? '' : $item->presentation;
  60          $info = $this->get_info($item);
  61  
  62          $item->ignoreempty = $this->ignoreempty($item);
  63          $item->hidenoselect = $this->hidenoselect($item);
  64  
  65          //all items for dependitem
  66          $feedbackitems = feedback_get_depend_candidates_for_item($feedback, $item);
  67          $commonparams = array('cmid'=>$cm->id,
  68                               'id'=>isset($item->id) ? $item->id : null,
  69                               'typ'=>$item->typ,
  70                               'items'=>$feedbackitems,
  71                               'feedback'=>$feedback->id);
  72  
  73          //build the form
  74          $customdata = array('item' => $item,
  75                              'common' => $commonparams,
  76                              'positionlist' => $positionlist,
  77                              'position' => $position,
  78                              'info' => $info);
  79  
  80          $this->item_form = new feedback_multichoicerated_form('edit_item.php', $customdata);
  81      }
  82  
  83      //this function only can used after the call of build_editform()
  84      public function show_editform() {
  85          $this->item_form->display();
  86      }
  87  
  88      public function is_cancelled() {
  89          return $this->item_form->is_cancelled();
  90      }
  91  
  92      public function get_data() {
  93          if ($this->item = $this->item_form->get_data()) {
  94              return true;
  95          }
  96          return false;
  97      }
  98  
  99      public function save_item() {
 100          global $DB;
 101  
 102          if (!$item = $this->item_form->get_data()) {
 103              return false;
 104          }
 105  
 106          if (isset($item->clone_item) AND $item->clone_item) {
 107              $item->id = ''; //to clone this item
 108              $item->position++;
 109          }
 110  
 111          $this->set_ignoreempty($item, $item->ignoreempty);
 112          $this->set_hidenoselect($item, $item->hidenoselect);
 113  
 114          $item->hasvalue = $this->get_hasvalue();
 115          if (!$item->id) {
 116              $item->id = $DB->insert_record('feedback_item', $item);
 117          } else {
 118              $DB->update_record('feedback_item', $item);
 119          }
 120  
 121          return $DB->get_record('feedback_item', array('id'=>$item->id));
 122      }
 123  
 124  
 125      //gets an array with three values(typ, name, XXX)
 126      //XXX is an object with answertext, answercount and quotient
 127      public function get_analysed($item, $groupid = false, $courseid = false) {
 128          $analysed_item = array();
 129          $analysed_item[] = $item->typ;
 130          $analysed_item[] = $item->name;
 131  
 132          //die moeglichen Antworten extrahieren
 133          $info = $this->get_info($item);
 134          $lines = null;
 135          $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
 136          if (!is_array($lines)) {
 137              return null;
 138          }
 139  
 140          //die Werte holen
 141          $values = feedback_get_group_values($item, $groupid, $courseid, $this->ignoreempty($item));
 142          if (!$values) {
 143              return null;
 144          }
 145          //schleife ueber den Werten und ueber die Antwortmoeglichkeiten
 146  
 147          $analysed_answer = array();
 148          $sizeoflines = count($lines);
 149          for ($i = 1; $i <= $sizeoflines; $i++) {
 150              $item_values = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $lines[$i-1]);
 151              $ans = new stdClass();
 152              $ans->answertext = $item_values[1];
 153              $avg = 0.0;
 154              $anscount = 0;
 155              foreach ($values as $value) {
 156                  //ist die Antwort gleich dem index der Antworten + 1?
 157                  if ($value->value == $i) {
 158                      $avg += $item_values[0]; //erst alle Werte aufsummieren
 159                      $anscount++;
 160                  }
 161              }
 162              $ans->answercount = $anscount;
 163              $ans->avg = doubleval($avg) / doubleval(count($values));
 164              $ans->value = $item_values[0];
 165              $ans->quotient = $ans->answercount / count($values);
 166              $analysed_answer[] = $ans;
 167          }
 168          $analysed_item[] = $analysed_answer;
 169          return $analysed_item;
 170      }
 171  
 172      public function get_printval($item, $value) {
 173          $printval = '';
 174  
 175          if (!isset($value->value)) {
 176              return $printval;
 177          }
 178  
 179          $info = $this->get_info($item);
 180  
 181          $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
 182          $index = 1;
 183          foreach ($presentation as $pres) {
 184              if ($value->value == $index) {
 185                  $item_label = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
 186                  $printval = $item_label[1];
 187                  break;
 188              }
 189              $index++;
 190          }
 191          return $printval;
 192      }
 193  
 194      public function print_analysed($item, $itemnr = '', $groupid = false, $courseid = false) {
 195          global $OUTPUT;
 196          $sep_dec = get_string('separator_decimal', 'feedback');
 197          if (substr($sep_dec, 0, 2) == '[[') {
 198              $sep_dec = FEEDBACK_DECIMAL;
 199          }
 200  
 201          $sep_thous = get_string('separator_thousand', 'feedback');
 202          if (substr($sep_thous, 0, 2) == '[[') {
 203              $sep_thous = FEEDBACK_THOUSAND;
 204          }
 205  
 206          $analysed_item = $this->get_analysed($item, $groupid, $courseid);
 207          if ($analysed_item) {
 208              echo '<tr><th colspan="2" align="left">';
 209              echo $itemnr.'&nbsp;('.$item->label.') '.$analysed_item[1];
 210              echo '</th></tr>';
 211              $analysed_vals = $analysed_item[2];
 212              $pixnr = 0;
 213              $avg = 0.0;
 214              foreach ($analysed_vals as $val) {
 215                  $intvalue = $pixnr % 10;
 216                  $pix = $OUTPUT->pix_url('multichoice/' . $intvalue, 'feedback');
 217                  $pixnr++;
 218                  $pixwidth = intval($val->quotient * FEEDBACK_MAX_PIX_LENGTH);
 219  
 220                  $avg += $val->avg;
 221                  $quotient = number_format(($val->quotient * 100), 2, $sep_dec, $sep_thous);
 222                  echo '<tr>';
 223                  echo '<td align="left" valign="top">';
 224                  echo '-&nbsp;&nbsp;'.trim($val->answertext).' ('.$val->value.'):</td>';
 225                  echo '<td align="left" style="width: '.FEEDBACK_MAX_PIX_LENGTH.'">';
 226                  echo '<img class="feedback_bar_image" alt="'.$intvalue.'" src="'.$pix.'" height="5" width="'.$pixwidth.'" />';
 227                  echo $val->answercount;
 228                  if ($val->quotient > 0) {
 229                      echo '&nbsp;('.$quotient.'&nbsp;%)';
 230                  } else {
 231                      echo '';
 232                  }
 233                  echo '</td></tr>';
 234              }
 235              $avg = number_format(($avg), 2, $sep_dec, $sep_thous);
 236              echo '<tr><td align="left" colspan="2"><b>';
 237              echo get_string('average', 'feedback').': '.$avg.'</b>';
 238              echo '</td></tr>';
 239          }
 240      }
 241  
 242      public function excelprint_item(&$worksheet, $row_offset,
 243                               $xls_formats, $item,
 244                               $groupid, $courseid = false) {
 245  
 246          $analysed_item = $this->get_analysed($item, $groupid, $courseid);
 247  
 248          $data = $analysed_item[2];
 249  
 250          //write the item
 251          $worksheet->write_string($row_offset, 0, $item->label, $xls_formats->head2);
 252          $worksheet->write_string($row_offset, 1, $analysed_item[1], $xls_formats->head2);
 253          if (is_array($data)) {
 254              $avg = 0.0;
 255              $sizeofdata = count($data);
 256              for ($i = 0; $i < $sizeofdata; $i++) {
 257                  $analysed_data = $data[$i];
 258  
 259                  $worksheet->write_string($row_offset,
 260                                  $i + 2,
 261                                  trim($analysed_data->answertext).' ('.$analysed_data->value.')',
 262                                  $xls_formats->value_bold);
 263  
 264                  $worksheet->write_number($row_offset + 1,
 265                                  $i + 2,
 266                                  $analysed_data->answercount,
 267                                  $xls_formats->default);
 268  
 269                  $avg += $analysed_data->avg;
 270              }
 271              //mittelwert anzeigen
 272              $worksheet->write_string($row_offset,
 273                                  count($data) + 2,
 274                                  get_string('average', 'feedback'),
 275                                  $xls_formats->value_bold);
 276  
 277              $worksheet->write_number($row_offset + 1,
 278                                  count($data) + 2,
 279                                  $avg,
 280                                  $xls_formats->value_bold);
 281          }
 282          $row_offset +=2;
 283          return $row_offset;
 284      }
 285  
 286      /**
 287       * print the item at the edit-page of feedback
 288       *
 289       * @global object
 290       * @param object $item
 291       * @return void
 292       */
 293      public function print_item_preview($item) {
 294          global $OUTPUT, $DB;
 295  
 296          $align = right_to_left() ? 'right' : 'left';
 297          $info = $this->get_info($item);
 298          $strrequiredmark = '<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'.
 299              get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />';
 300  
 301          $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
 302          $requiredmark = ($item->required == 1) ? $strrequiredmark : '';
 303          //print the question and label
 304          echo '<div class="feedback_item_label_'.$align.'">';
 305          if ($info->subtype == 'd') {
 306              echo '<label for="'. $item->typ . '_' . $item->id .'">';
 307          }
 308          echo '('.$item->label.') ';
 309          echo format_text($item->name . $requiredmark, FORMAT_HTML, array('noclean' => true, 'para' => false));
 310          if ($item->dependitem) {
 311              if ($dependitem = $DB->get_record('feedback_item', array('id'=>$item->dependitem))) {
 312                  echo ' <span class="feedback_depend">';
 313                  echo '('.$dependitem->label.'-&gt;'.$item->dependvalue.')';
 314                  echo '</span>';
 315              }
 316          }
 317          if ($info->subtype == 'd') {
 318              echo '</label>';
 319          }
 320          echo '</div>';
 321  
 322          //print the presentation
 323          echo '<div class="feedback_item_presentation_'.$align.'">';
 324          switch($info->subtype) {
 325              case 'r':
 326                  $this->print_item_radio($item, false, $info, $align, true, $lines);
 327                  break;
 328              case 'd':
 329                  $this->print_item_dropdown($item, false, $info, $align, true, $lines);
 330                  break;
 331          }
 332          echo '</div>';
 333      }
 334  
 335      /**
 336       * print the item at the complete-page of feedback
 337       *
 338       * @global object
 339       * @param object $item
 340       * @param string $value
 341       * @param bool $highlightrequire
 342       * @return void
 343       */
 344      public function print_item_complete($item, $value = '', $highlightrequire = false) {
 345          global $OUTPUT;
 346          $align = right_to_left() ? 'right' : 'left';
 347          $info = $this->get_info($item);
 348          $strrequiredmark = '<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'.
 349              get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />';
 350  
 351          $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
 352          $requiredmark = ($item->required == 1) ? $strrequiredmark : '';
 353  
 354          //print the question and label
 355          $inputname = $item->typ . '_' . $item->id;
 356          echo '<div class="feedback_item_label_'.$align.'">';
 357          if ($info->subtype == 'd') {
 358              echo '<label for="'. $inputname .'">';
 359              echo format_text($item->name.$requiredmark, true, false, false);
 360              if ($highlightrequire AND $item->required AND intval($value) <= 0) {
 361                  echo '<br class="error"><span id="id_error_'.$inputname.'" class="error"> '.get_string('err_required', 'form').
 362                      '</span><br id="id_error_break_'.$inputname.'" class="error" >';
 363              }
 364              echo '</label>';
 365          } else {
 366              echo format_text($item->name . $requiredmark, FORMAT_HTML, array('noclean' => true, 'para' => false));
 367              if ($highlightrequire AND $item->required AND intval($value) <= 0) {
 368                  echo '<br class="error"><span id="id_error_'.$inputname.'" class="error"> '.get_string('err_required', 'form').
 369                      '</span><br id="id_error_break_'.$inputname.'" class="error" >';
 370              }
 371          }
 372          echo '</div>';
 373  
 374          //print the presentation
 375          echo '<div class="feedback_item_presentation_'.$align.'">';
 376          switch($info->subtype) {
 377              case 'r':
 378                  $this->print_item_radio($item, $value, $info, $align, false, $lines);
 379                  break;
 380              case 'd':
 381                  $this->print_item_dropdown($item, $value, $info, $align, false, $lines);
 382                  break;
 383          }
 384          echo '</div>';
 385      }
 386  
 387      /**
 388       * print the item at the complete-page of feedback
 389       *
 390       * @global object
 391       * @param object $item
 392       * @param string $value
 393       * @return void
 394       */
 395      public function print_item_show_value($item, $value = '') {
 396          global $OUTPUT;
 397          $align = right_to_left() ? 'right' : 'left';
 398          $info = $this->get_info($item);
 399  
 400          $lines = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
 401          $requiredmark = ($item->required == 1)?'<img class="req" title="'.get_string('requiredelement', 'form').'" alt="'.
 402              get_string('requiredelement', 'form').'" src="'.$OUTPUT->pix_url('req') .'" />':'';
 403  
 404          //print the question and label
 405          echo '<div class="feedback_item_label_'.$align.'">';
 406              echo '('.$item->label.') ';
 407              echo format_text($item->name . $requiredmark, FORMAT_HTML, array('noclean' => true, 'para' => false));
 408          echo '</div>';
 409  
 410          //print the presentation
 411          echo '<div class="feedback_item_presentation_'.$align.'">';
 412          $index = 1;
 413          foreach ($lines as $line) {
 414              if ($value == $index) {
 415                  $item_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
 416                  echo $OUTPUT->box_start('generalbox boxalign'.$align);
 417                  echo format_text($item_value[1], FORMAT_HTML, array('noclean' => true, 'para' => false));
 418                  echo $OUTPUT->box_end();
 419                  break;
 420              }
 421              $index++;
 422          }
 423          echo '</div>';
 424      }
 425  
 426      public function check_value($value, $item) {
 427          if ((!isset($value) OR $value == '' OR $value == 0) AND $item->required != 1) {
 428              return true;
 429          }
 430          if (intval($value) > 0) {
 431              return true;
 432          }
 433          return false;
 434      }
 435  
 436      public function create_value($data) {
 437          $data = trim($data);
 438          return $data;
 439      }
 440  
 441      //compares the dbvalue with the dependvalue
 442      //dbvalue is the number of one selection
 443      //dependvalue is the presentation of one selection
 444      public function compare_value($item, $dbvalue, $dependvalue) {
 445  
 446          if (is_array($dbvalue)) {
 447              $dbvalues = $dbvalue;
 448          } else {
 449              $dbvalues = explode(FEEDBACK_MULTICHOICERATED_LINE_SEP, $dbvalue);
 450          }
 451  
 452          $info = $this->get_info($item);
 453          $presentation = explode (FEEDBACK_MULTICHOICERATED_LINE_SEP, $info->presentation);
 454          $index = 1;
 455          foreach ($presentation as $pres) {
 456              $presvalues = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $pres);
 457  
 458              foreach ($dbvalues as $dbval) {
 459                  if ($dbval == $index AND trim($presvalues[1]) == $dependvalue) {
 460                      return true;
 461                  }
 462              }
 463              $index++;
 464          }
 465          return false;
 466      }
 467  
 468      public function get_presentation($data) {
 469          $present = $this->prepare_presentation_values_save(trim($data->itemvalues),
 470                                              FEEDBACK_MULTICHOICERATED_VALUE_SEP2,
 471                                              FEEDBACK_MULTICHOICERATED_VALUE_SEP);
 472          if (!isset($data->subtype)) {
 473              $subtype = 'r';
 474          } else {
 475              $subtype = substr($data->subtype, 0, 1);
 476          }
 477          if (isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd') {
 478              $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
 479          }
 480          return $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$present;
 481      }
 482  
 483      public function get_hasvalue() {
 484          return 1;
 485      }
 486  
 487      public function get_info($item) {
 488          $presentation = empty($item->presentation) ? '' : $item->presentation;
 489  
 490          $info = new stdClass();
 491          //check the subtype of the multichoice
 492          //it can be check(c), radio(r) or dropdown(d)
 493          $info->subtype = '';
 494          $info->presentation = '';
 495          $info->horizontal = false;
 496  
 497          $parts = explode(FEEDBACK_MULTICHOICERATED_TYPE_SEP, $item->presentation);
 498          @list($info->subtype, $info->presentation) = $parts;
 499  
 500          if (!isset($info->subtype)) {
 501              $info->subtype = 'r';
 502          }
 503  
 504          if ($info->subtype != 'd') {
 505              $parts = explode(FEEDBACK_MULTICHOICERATED_ADJUST_SEP, $info->presentation);
 506              @list($info->presentation, $info->horizontal) = $parts;
 507  
 508              if (isset($info->horizontal) AND $info->horizontal == 1) {
 509                  $info->horizontal = true;
 510              } else {
 511                  $info->horizontal = false;
 512              }
 513          }
 514  
 515          $info->values = $this->prepare_presentation_values_print($info->presentation,
 516                                                      FEEDBACK_MULTICHOICERATED_VALUE_SEP,
 517                                                      FEEDBACK_MULTICHOICERATED_VALUE_SEP2);
 518          return $info;
 519      }
 520  
 521      private function print_item_radio($item, $value, $info, $align, $showrating, $lines) {
 522          $index = 1;
 523          $checked = '';
 524  
 525          if ($info->horizontal) {
 526              $hv = 'h';
 527          } else {
 528              $hv = 'v';
 529          }
 530          echo '<fieldset>';
 531          echo '<ul>';
 532          if (!$this->hidenoselect($item)) {
 533              ?>
 534                  <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
 535                      <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
 536                          <?php
 537                          echo '<input type="radio" '.
 538                                      'name="'.$item->typ.'_'.$item->id.'" '.
 539                                      'id="'.$item->typ.'_'.$item->id.'_xxx" '.
 540                                      'value="" checked="checked" />';
 541                          ?>
 542                      </span>
 543                      <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
 544                          <label for="<?php echo $item->typ . '_' . $item->id.'_xxx';?>">
 545                          <?php print_string('not_selected', 'feedback');?>&nbsp;
 546                          </label>
 547                      </span>
 548                  </li>
 549              <?php
 550          }
 551          foreach ($lines as $line) {
 552              if ($value == $index) {
 553                  $checked = 'checked="checked"';
 554              } else {
 555                  $checked = '';
 556              }
 557              $radio_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
 558              $inputname = $item->typ . '_' . $item->id;
 559              $inputid = $inputname.'_'.$index;
 560          ?>
 561              <li class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
 562                  <span class="feedback_item_radio_<?php echo $hv.'_'.$align;?>">
 563                  <?php
 564                  echo '<input type="radio" '.
 565                              'name="'.$inputname.'" '.
 566                              'id="'.$inputid.'" '.
 567                              'value="'.$index.'" '.$checked.' />';
 568                  ?>
 569                  </span>
 570                  <span class="feedback_item_radiolabel_<?php echo $hv.'_'.$align;?>">
 571                      <label for="<?php echo $inputid;?>">
 572                          <?php
 573                              if ($showrating) {
 574                                  $str_rating_value = '('.$radio_value[0].') '.$radio_value[1];
 575                                  echo format_text($str_rating_value, FORMAT_HTML, array('noclean' => true, 'para' => false));
 576                              } else {
 577                                  echo format_text($radio_value[1], FORMAT_HTML, array('noclean' => true, 'para' => false));
 578                              }
 579                          ?>
 580                      </label>
 581                  </span>
 582              </li>
 583          <?php
 584              $index++;
 585          }
 586          echo '</ul>';
 587          echo '</fieldset>';
 588      }
 589  
 590      private function print_item_dropdown($item, $value, $info, $align, $showrating, $lines) {
 591          if ($info->horizontal) {
 592              $hv = 'h';
 593          } else {
 594              $hv = 'v';
 595          }
 596          ?>
 597          <div class="feedback_item_select_<?php echo $hv.'_'.$align;?>">
 598              <select id="<?php echo $item->typ.'_'.$item->id;?>" name="<?php echo $item->typ.'_'.$item->id;?>">
 599                  <option value="0">&nbsp;</option>
 600                  <?php
 601                  $index = 1;
 602                  $checked = '';
 603                  foreach ($lines as $line) {
 604                      if ($value == $index) {
 605                          $selected = 'selected="selected"';
 606                      } else {
 607                          $selected = '';
 608                      }
 609                      $dropdown_value = explode(FEEDBACK_MULTICHOICERATED_VALUE_SEP, $line);
 610                      if ($showrating) {
 611                          echo '<option value="'.$index.'" '.$selected.'>';
 612                          echo format_text('(' . $dropdown_value[0] . ') ' . $dropdown_value[1], FORMAT_HTML, array('para' => false));
 613                          echo '</option>';
 614                      } else {
 615                          echo '<option value="'.$index.'" '.$selected.'>';
 616                          echo format_text($dropdown_value[1], FORMAT_HTML, array('para' => false));
 617                          echo '</option>';
 618                      }
 619                      $index++;
 620                  }
 621                  ?>
 622              </select>
 623          </div>
 624          <?php
 625      }
 626  
 627      public function prepare_presentation_values($linesep1,
 628                                           $linesep2,
 629                                           $valuestring,
 630                                           $valuesep1,
 631                                           $valuesep2) {
 632  
 633          $lines = explode($linesep1, $valuestring);
 634          $newlines = array();
 635          foreach ($lines as $line) {
 636              $value = '';
 637              $text = '';
 638              if (strpos($line, $valuesep1) === false) {
 639                  $value = 0;
 640                  $text = $line;
 641              } else {
 642                  @list($value, $text) = explode($valuesep1, $line, 2);
 643              }
 644  
 645              $value = intval($value);
 646              $newlines[] = $value.$valuesep2.$text;
 647          }
 648          $newlines = implode($linesep2, $newlines);
 649          return $newlines;
 650      }
 651  
 652      public function prepare_presentation_values_print($valuestring, $valuesep1, $valuesep2) {
 653          $valuestring = str_replace(array("\n","\r"), "", $valuestring);
 654          return $this->prepare_presentation_values(FEEDBACK_MULTICHOICERATED_LINE_SEP,
 655                                                    "\n",
 656                                                    $valuestring,
 657                                                    $valuesep1,
 658                                                    $valuesep2);
 659      }
 660  
 661      public function prepare_presentation_values_save($valuestring, $valuesep1, $valuesep2) {
 662          $valuestring = str_replace("\r", "\n", $valuestring);
 663          $valuestring = str_replace("\n\n", "\n", $valuestring);
 664          return $this->prepare_presentation_values("\n",
 665                          FEEDBACK_MULTICHOICERATED_LINE_SEP,
 666                          $valuestring,
 667                          $valuesep1,
 668                          $valuesep2);
 669      }
 670  
 671      public function set_ignoreempty($item, $ignoreempty=true) {
 672          $item->options = str_replace(FEEDBACK_MULTICHOICERATED_IGNOREEMPTY, '', $item->options);
 673          if ($ignoreempty) {
 674              $item->options .= FEEDBACK_MULTICHOICERATED_IGNOREEMPTY;
 675          }
 676      }
 677  
 678      public function ignoreempty($item) {
 679          if (strstr($item->options, FEEDBACK_MULTICHOICERATED_IGNOREEMPTY)) {
 680              return true;
 681          }
 682          return false;
 683      }
 684  
 685      public function set_hidenoselect($item, $hidenoselect=true) {
 686          $item->options = str_replace(FEEDBACK_MULTICHOICERATED_HIDENOSELECT, '', $item->options);
 687          if ($hidenoselect) {
 688              $item->options .= FEEDBACK_MULTICHOICERATED_HIDENOSELECT;
 689          }
 690      }
 691  
 692      public function hidenoselect($item) {
 693          if (strstr($item->options, FEEDBACK_MULTICHOICERATED_HIDENOSELECT)) {
 694              return true;
 695          }
 696          return false;
 697      }
 698  
 699      public function can_switch_require() {
 700          return true;
 701      }
 702  
 703      public function value_type() {
 704          return PARAM_INT;
 705      }
 706  
 707      public function clean_input_value($value) {
 708          return clean_param($value, $this->value_type());
 709      }
 710  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1