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  /**
  18   * Target base.
  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   * Target base.
  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  abstract class base {
  38      /**
  39       * @var     step        $step           The step being targetted.
  40       */
  41      protected $step;
  42  
  43      /**
  44       * @var     array       $forcedsettings The settings forced by this type.
  45       */
  46      protected static $forcedsettings = [];
  47  
  48      /**
  49       * Create the target type.
  50       *
  51       * @param   step        $step       The step being targetted.
  52       */
  53      public function __construct(step $step) {
  54          $this->step = $step;
  55      }
  56  
  57      /**
  58       * Convert the target value to a valid CSS selector for use in the
  59       * output configuration.
  60       *
  61       * @return string
  62       */
  63      abstract public function convert_to_css();
  64  
  65      /**
  66       * Convert the step target to a friendly name for use in the UI.
  67       *
  68       * @return string
  69       */
  70      abstract public function get_displayname();
  71  
  72      /**
  73       * Add the target type configuration to the form.
  74       *
  75       * @param   MoodleQuickForm $mform      The form to add configuration to.
  76       */
  77      public static function add_config_to_form(\MoodleQuickForm $mform) {
  78      }
  79  
  80      /**
  81       * Add the disabledIf values.
  82       *
  83       * @param   MoodleQuickForm $mform      The form to add configuration to.
  84       */
  85      public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) {
  86      }
  87  
  88      /**
  89       * Prepare data to submit to the form.
  90       *
  91       * @param   object          $data       The data being passed to the form
  92       */
  93      abstract public function prepare_data_for_form($data);
  94  
  95      /**
  96       * Whether the specified step setting is forced by this target type.
  97       *
  98       * @param   string          $key        The name of the key to check.
  99       * @return  boolean
 100       */
 101      public function is_setting_forced($key) {
 102          return isset(static::$forcedsettings[$key]);
 103      }
 104  
 105      /**
 106       * The value of the forced setting.
 107       *
 108       * @param   string          $key        The name of the key to check.
 109       * @return  mixed
 110       */
 111      public function get_forced_setting_value($key) {
 112          if ($this->is_setting_forced($key)) {
 113              return static::$forcedsettings[$key];
 114          }
 115  
 116          return null;
 117      }
 118  
 119      /**
 120       * Fetch the targetvalue from the form for this target type.
 121       *
 122       * @param   stdClass        $data       The data submitted in the form
 123       * @return  string
 124       */
 125      abstract public function get_value_from_form($data);
 126  }