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   * URL manager.
  19   *
  20   * @package    core_competency
  21   * @copyright  2016 Frédéric Massart - FMCorz.net
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_competency;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  use moodle_url;
  29  
  30  /**
  31   * URL manager class.
  32   *
  33   * This class has to be used to get the URL to a resource, this allows for different
  34   * alternate frontends to be used without resorting to core hacks. Note that you
  35   * do not have to use this when you are navigating between pages of your own plugin.
  36   *
  37   * To set another resolver, set the following config value in config.php:
  38   * $CFG->core_competency_url_resolver = 'your_plugin\\your_url_resolver_class';
  39   *
  40   * Your URL resolver should implement the same methods as the ones listed in
  41   * this class (except for {{@link self::get()}}) but not statically.
  42   *
  43   * /!\ Note, resolvers MUST NEVER assume that the resource, or the resources
  44   * represented by the arguments, still exist.
  45   *
  46   * @package    core_competency
  47   * @copyright  2016 Frédéric Massart - FMCorz.net
  48   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  49   */
  50  class url {
  51  
  52      /** @var url_resolver The URL resolver instance.*/
  53      protected static $resolver;
  54  
  55      /**
  56       * Defer to the resolver.
  57       *
  58       * @param string $resource The resource type.
  59       * @param array $args The arguments.
  60       * @return mixed
  61       */
  62      protected static function get($resource, $args) {
  63          global $CFG;
  64          if (!isset(static::$resolver)) {
  65              $klass = !empty($CFG->core_competency_url_resolver) ? $CFG->core_competency_url_resolver : 'tool_lp\\url_resolver';
  66              static::$resolver = new $klass();
  67          }
  68          if (!method_exists(static::$resolver, $resource)) {
  69              debugging("URL for '$resource' not implemented.", DEBUG_DEVELOPER);
  70              return new moodle_url('/');
  71          }
  72          return call_user_func_array([static::$resolver, $resource], $args);
  73      }
  74  
  75      /**
  76       * The URL where the competency can be found.
  77       *
  78       * @param int $competencyid The competency ID.
  79       * @param int $pagecontextid The ID of the context we are in.
  80       * @return moodle_url
  81       */
  82      public static function competency($competencyid, $pagecontextid) {
  83          return static::get(__FUNCTION__, func_get_args());
  84      }
  85  
  86      /**
  87       * The URL where the framework can be found.
  88       *
  89       * @param int $frameworkid The framework ID.
  90       * @param int $pagecontextid The ID of the context we are in.
  91       * @return moodle_url
  92       */
  93      public static function framework($frameworkid, $pagecontextid) {
  94          return static::get(__FUNCTION__, func_get_args());
  95      }
  96  
  97      /**
  98       * The URL where the frameworks can be found.
  99       *
 100       * @param int $pagecontextid The ID of the context that we are browsing.
 101       * @return moodle_url
 102       */
 103      public static function frameworks($pagecontextid) {
 104          return static::get(__FUNCTION__, func_get_args());
 105      }
 106  
 107      /**
 108       * The URL where the plan can be found.
 109       *
 110       * @param int $planid The plan ID.
 111       * @return moodle_url
 112       */
 113      public static function plan($planid) {
 114          return static::get(__FUNCTION__, func_get_args());
 115      }
 116  
 117      /**
 118       * The URL where the plans of a user can be found.
 119       *
 120       * @param int $userid The user ID.
 121       * @return moodle_url
 122       */
 123      public static function plans($userid) {
 124          return static::get(__FUNCTION__, func_get_args());
 125      }
 126  
 127      /**
 128       * The URL where the template can be found.
 129       *
 130       * @param int $templateid The template ID.
 131       * @param int $pagecontextid The ID of the context we are in.
 132       * @return moodle_url
 133       */
 134      public static function template($templateid, $pagecontextid) {
 135          return static::get(__FUNCTION__, func_get_args());
 136      }
 137  
 138      /**
 139       * The URL where the templates can be found.
 140       *
 141       * @param int $pagecontextid The ID of the context that we are browsing.
 142       * @return moodle_url
 143       */
 144      public function templates($pagecontextid) {
 145          return static::get(__FUNCTION__, func_get_args());
 146      }
 147  
 148      /**
 149       * The URL where the user competency can be found.
 150       *
 151       * @param int $usercompetencyid The user competency ID
 152       * @return moodle_url
 153       */
 154      public static function user_competency($usercompetencyid) {
 155          return static::get(__FUNCTION__, func_get_args());
 156      }
 157  
 158      /**
 159       * The URL where the user competency can be found in the context of a course.
 160       *
 161       * @param int $userid The user ID
 162       * @param int $competencyid The competency ID.
 163       * @param int $courseid The course ID.
 164       * @return moodle_url
 165       */
 166      public static function user_competency_in_course($userid, $competencyid, $courseid) {
 167          return static::get(__FUNCTION__, func_get_args());
 168      }
 169  
 170      /**
 171       * The URL where the user competency can be found in the context of a plan.
 172       *
 173       * @param int $userid The user ID
 174       * @param int $competencyid The competency ID.
 175       * @param int $planid The plan ID.
 176       * @return moodle_url
 177       */
 178      public static function user_competency_in_plan($userid, $competencyid, $planid) {
 179          return static::get(__FUNCTION__, func_get_args());
 180      }
 181  
 182      /**
 183       * The URL where the user evidence (of prior learning) can be found.
 184       *
 185       * @param int $userevidenceid The user evidence ID
 186       * @return moodle_url
 187       */
 188      public static function user_evidence($userevidenceid) {
 189          return static::get(__FUNCTION__, func_get_args());
 190      }
 191  }