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  /**
  18   * A step designed to be orphaned.
  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\target;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use tool_usertours\step;
  30  
  31  /**
  32   * A step designed to be orphaned.
  33   *
  34   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class unattached extends base {
  38      /**
  39       * @var     array       $forcedsettings The settings forced by this type.
  40       */
  41      protected static $forcedsettings = [
  42              'placement'     => 'top',
  43              'orphan'        => true,
  44              'reflex'        => false,
  45          ];
  46  
  47      /**
  48       * Convert the target value to a valid CSS selector for use in the
  49       * output configuration.
  50       *
  51       * @return string
  52       */
  53      public function convert_to_css() {
  54          return '';
  55      }
  56  
  57      /**
  58       * Convert the step target to a friendly name for use in the UI.
  59       *
  60       * @return string
  61       */
  62      public function get_displayname() {
  63          return get_string('target_unattached', 'tool_usertours');
  64      }
  65  
  66      /**
  67       * Add the target type configuration to the form.
  68       *
  69       * @param   MoodleQuickForm $mform      The form to add configuration to.
  70       * @return  $this
  71       */
  72      public static function add_config_to_form(\MoodleQuickForm $mform) {
  73          // There is no relevant value here.
  74          $mform->addElement('hidden', 'targetvalue_unattached', '');
  75          $mform->setType('targetvalue_unattached', PARAM_TEXT);
  76      }
  77  
  78      /**
  79       * Add the disabledIf values.
  80       *
  81       * @param   MoodleQuickForm $mform      The form to add configuration to.
  82       */
  83      public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) {
  84          $myvalue = \tool_usertours\target::get_target_constant_for_class(get_class());
  85  
  86          foreach (array_keys(self::$forcedsettings) as $settingname) {
  87              $mform->hideIf($settingname, 'targettype', 'eq', $myvalue);
  88          }
  89      }
  90  
  91      /**
  92       * Prepare data to submit to the form.
  93       *
  94       * @param   object          $data       The data being passed to the form
  95       */
  96      public function prepare_data_for_form($data) {
  97          $data->targetvalue_unattached = '';
  98      }
  99  
 100      /**
 101       * Fetch the targetvalue from the form for this target type.
 102       *
 103       * @param   stdClass        $data       The data submitted in the form
 104       * @return  string
 105       */
 106      public function get_value_from_form($data) {
 107          return '';
 108      }
 109  }