Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]

   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  /**
  18   * Form for editing tours.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_usertours\local\forms;
  26  
  27  defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
  28  
  29  require_once($CFG->libdir . '/formslib.php');
  30  
  31  use \tool_usertours\helper;
  32  
  33  /**
  34   * Form for editing tours.
  35   *
  36   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class edittour extends \moodleform {
  40      /**
  41       * @var tool_usertours\tour $tour
  42       */
  43      protected $tour;
  44  
  45      /**
  46       * Create the edit tour form.
  47       *
  48       * @param   tour        $tour       The tour being editted.
  49       */
  50      public function __construct(\tool_usertours\tour $tour) {
  51          $this->tour = $tour;
  52  
  53          parent::__construct($tour->get_edit_link());
  54      }
  55  
  56      /**
  57       * Form definition.
  58       */
  59      public function definition() {
  60          $mform = $this->_form;
  61  
  62          // ID of existing tour.
  63          $mform->addElement('hidden', 'id');
  64          $mform->setType('id', PARAM_INT);
  65  
  66          // Name of the tour.
  67          $mform->addElement('text', 'name', get_string('name', 'tool_usertours'));
  68          $mform->addRule('name', get_string('required'), 'required', null, 'client');
  69          $mform->setType('name', PARAM_TEXT);
  70          $mform->addHelpButton('name', 'name', 'tool_usertours');
  71  
  72          // Admin-only descriptions.
  73          $mform->addElement('textarea', 'description', get_string('description', 'tool_usertours'));
  74          $mform->setType('description', PARAM_RAW);
  75          $mform->addHelpButton('description', 'description', 'tool_usertours');
  76  
  77          // Application.
  78          $mform->addElement('text', 'pathmatch', get_string('pathmatch', 'tool_usertours'));
  79          $mform->setType('pathmatch', PARAM_RAW);
  80          $mform->addHelpButton('pathmatch', 'pathmatch', 'tool_usertours');
  81  
  82          $mform->addElement('checkbox', 'enabled', get_string('tourisenabled', 'tool_usertours'));
  83  
  84          $mform->addElement('text', 'endtourlabel', get_string('endtourlabel', 'tool_usertours'));
  85          $mform->setType('endtourlabel', PARAM_TEXT);
  86          $mform->addHelpButton('endtourlabel', 'endtourlabel', 'tool_usertours');
  87  
  88          $mform->addElement('checkbox', 'displaystepnumbers', get_string('displaystepnumbers', 'tool_usertours'));
  89          $mform->addHelpButton('displaystepnumbers', 'displaystepnumbers', 'tool_usertours');
  90  
  91          // Configuration.
  92          $this->tour->add_config_to_form($mform);
  93  
  94          // Filters.
  95          $mform->addElement('header', 'filters', get_string('filter_header', 'tool_usertours'));
  96          $mform->addElement('static', 'filterhelp', '', get_string('filter_help', 'tool_usertours'));
  97  
  98          foreach (helper::get_all_filters() as $filterclass) {
  99              $filterclass::add_filter_to_form($mform);
 100          }
 101  
 102          $this->add_action_buttons();
 103      }
 104  }