Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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_numeric_form extends feedback_item_form {
  20      protected $type = "numeric";
  21  
  22      public function definition() {
  23  
  24          $item = $this->_customdata['item'];
  25          $common = $this->_customdata['common'];
  26          $positionlist = $this->_customdata['positionlist'];
  27          $position = $this->_customdata['position'];
  28  
  29          $mform =& $this->_form;
  30  
  31          $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
  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, 'maxlength'=>255));
  38          $mform->addElement('text',
  39                              'label',
  40                              get_string('item_label', 'feedback'),
  41                              array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
  42  
  43          $mform->addElement('text',
  44                              'rangefrom',
  45                              get_string('numeric_range_from', 'feedback'),
  46                              array('size'=>10, 'maxlength'=>10));
  47          $mform->setType('rangefrom', PARAM_RAW);
  48  
  49          $mform->addElement('text',
  50                              'rangeto',
  51                              get_string('numeric_range_to', 'feedback'),
  52                              array('size'=>10, 'maxlength'=>10));
  53          $mform->setType('rangeto', PARAM_RAW);
  54  
  55          parent::definition();
  56          $this->set_data($item);
  57  
  58      }
  59  
  60      public function get_data() {
  61          if (!$item = parent::get_data()) {
  62              return false;
  63          }
  64  
  65          $num1 = unformat_float($item->rangefrom, true);
  66          if ($num1 === false || $num1 === null) {
  67              $num1 = '-';
  68          }
  69  
  70          $num2 = unformat_float($item->rangeto, true);
  71          if ($num2 === false || $num2 === null) {
  72              $num2 = '-';
  73          }
  74  
  75          if ($num1 === '-' OR $num2 === '-') {
  76              $item->presentation = $num1 . '|'. $num2;
  77              return $item;
  78          }
  79  
  80          if ($num1 > $num2) {
  81              $item->presentation =  $num2 . '|'. $num1;
  82          } else {
  83              $item->presentation = $num1 . '|'. $num2;
  84          }
  85          return $item;
  86      }
  87  
  88  }