Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 and 403]

   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  require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
  18  
  19  class feedback_multichoicerated_form extends feedback_item_form {
  20      protected $type = "multichoicerated";
  21  
  22      public function definition() {
  23          $item = $this->_customdata['item'];
  24          $common = $this->_customdata['common'];
  25          $positionlist = $this->_customdata['positionlist'];
  26          $position = $this->_customdata['position'];
  27  
  28          $mform =& $this->_form;
  29  
  30          $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
  31  
  32          $mform->addElement('advcheckbox', 'required', get_string('required', 'feedback'), '' , null , array(0, 1));
  33  
  34          $mform->addElement('text',
  35                              'name',
  36                              get_string('item_name', 'feedback'),
  37                              array('size'=>FEEDBACK_ITEM_NAME_TEXTBOX_SIZE,
  38                                    'maxlength'=>255));
  39  
  40          $mform->addElement('text',
  41                              'label',
  42                              get_string('item_label', 'feedback'),
  43                              array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE,
  44                                    'maxlength'=>255));
  45  
  46          $mform->addElement('select',
  47                              'subtype',
  48                              get_string('multichoicetype', 'feedback').'&nbsp;',
  49                              array('r'=>get_string('radio', 'feedback'),
  50                                    'd'=>get_string('dropdown', 'feedback')));
  51  
  52          $mform->addElement('select',
  53                              'horizontal',
  54                              get_string('adjustment', 'feedback').'&nbsp;',
  55                              array(0 => get_string('vertical', 'feedback'),
  56                                    1 => get_string('horizontal', 'feedback')));
  57          $mform->hideIf('horizontal', 'subtype', 'eq', 'd');
  58  
  59          $mform->addElement('selectyesno',
  60                             'hidenoselect',
  61                             get_string('hide_no_select_option', 'feedback'));
  62          $mform->hideIf('hidenoselect', 'subtype', 'eq', 'd');
  63  
  64          $mform->addElement('selectyesno',
  65                             'ignoreempty',
  66                             get_string('do_not_analyse_empty_submits', 'feedback'));
  67          $mform->disabledIf('ignoreempty', 'required', 'eq', '1');
  68  
  69          $this->values = $mform->addElement('textarea',
  70                              'values',
  71                              get_string('multichoice_values', 'feedback'),
  72                              'wrap="virtual" rows="10" cols="65"');
  73  
  74          $mform->addElement('static',
  75                              'hint',
  76                              '',
  77                              get_string('use_one_line_for_each_value', 'feedback'));
  78  
  79          parent::definition();
  80          $this->set_data($item);
  81  
  82      }
  83  
  84      public function set_data($item) {
  85          $info = $this->_customdata['info'];
  86  
  87          $item->horizontal = $info->horizontal;
  88  
  89          $item->subtype = $info->subtype;
  90  
  91          $item->values = $info->values;
  92  
  93          return parent::set_data($item);
  94      }
  95  
  96      public function get_data() {
  97          if (!$item = parent::get_data()) {
  98              return false;
  99          }
 100  
 101          $itemobj = new feedback_item_multichoicerated();
 102  
 103          $presentation = $itemobj->prepare_presentation_values_save(trim($item->values),
 104                                                  FEEDBACK_MULTICHOICERATED_VALUE_SEP2,
 105                                                  FEEDBACK_MULTICHOICERATED_VALUE_SEP);
 106          if (!isset($item->subtype)) {
 107              $subtype = 'r';
 108          } else {
 109              $subtype = substr($item->subtype, 0, 1);
 110          }
 111          if (isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') {
 112              $presentation .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
 113          }
 114          $item->presentation = $subtype.FEEDBACK_MULTICHOICERATED_TYPE_SEP.$presentation;
 115          if (!isset($item->hidenoselect)) {
 116              $item->hidenoselect = 1;
 117          }
 118          if (!isset($item->ignoreempty)) {
 119              $item->ignoreempty = 0;
 120          }
 121          return $item;
 122      }
 123  }