MDL-61135 templates: improve loading icon for loading templates
[moodle.git] / competency / classes / url.php
blobf9d87396f30caececd1e43e698a57667137847b0
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.
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/>.
17 /**
18 * URL manager.
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
25 namespace core_competency;
26 defined('MOODLE_INTERNAL') || die();
28 use moodle_url;
30 /**
31 * URL manager class.
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.
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';
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.
43 * /!\ Note, resolvers MUST NEVER assume that the resource, or the resources
44 * represented by the arguments, still exist.
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
50 class url {
52 /** @var url_resolver The URL resolver instance.*/
53 protected static $resolver;
55 /**
56 * Defer to the resolver.
58 * @param string $resource The resource type.
59 * @param array $args The arguments.
60 * @return mixed
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();
68 if (!method_exists(static::$resolver, $resource)) {
69 debugging("URL for '$resource' not implemented.", DEBUG_DEVELOPER);
70 return new moodle_url('/');
72 return call_user_func_array([static::$resolver, $resource], $args);
75 /**
76 * The URL where the competency can be found.
78 * @param int $competencyid The competency ID.
79 * @param int $pagecontextid The ID of the context we are in.
80 * @return moodle_url
82 public static function competency($competencyid, $pagecontextid) {
83 return static::get(__FUNCTION__, func_get_args());
86 /**
87 * The URL where the framework can be found.
89 * @param int $frameworkid The framework ID.
90 * @param int $pagecontextid The ID of the context we are in.
91 * @return moodle_url
93 public static function framework($frameworkid, $pagecontextid) {
94 return static::get(__FUNCTION__, func_get_args());
97 /**
98 * The URL where the frameworks can be found.
100 * @param int $pagecontextid The ID of the context that we are browsing.
101 * @return moodle_url
103 public static function frameworks($pagecontextid) {
104 return static::get(__FUNCTION__, func_get_args());
108 * The URL where the plan can be found.
110 * @param int $planid The plan ID.
111 * @return moodle_url
113 public static function plan($planid) {
114 return static::get(__FUNCTION__, func_get_args());
118 * The URL where the plans of a user can be found.
120 * @param int $userid The user ID.
121 * @return moodle_url
123 public static function plans($userid) {
124 return static::get(__FUNCTION__, func_get_args());
128 * The URL where the template can be found.
130 * @param int $templateid The template ID.
131 * @param int $pagecontextid The ID of the context we are in.
132 * @return moodle_url
134 public static function template($templateid, $pagecontextid) {
135 return static::get(__FUNCTION__, func_get_args());
139 * The URL where the templates can be found.
141 * @param int $pagecontextid The ID of the context that we are browsing.
142 * @return moodle_url
144 public function templates($pagecontextid) {
145 return static::get(__FUNCTION__, func_get_args());
149 * The URL where the user competency can be found.
151 * @param int $usercompetencyid The user competency ID
152 * @return moodle_url
154 public static function user_competency($usercompetencyid) {
155 return static::get(__FUNCTION__, func_get_args());
159 * The URL where the user competency can be found in the context of a course.
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
166 public static function user_competency_in_course($userid, $competencyid, $courseid) {
167 return static::get(__FUNCTION__, func_get_args());
171 * The URL where the user competency can be found in the context of a plan.
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
178 public static function user_competency_in_plan($userid, $competencyid, $planid) {
179 return static::get(__FUNCTION__, func_get_args());
183 * The URL where the user evidence (of prior learning) can be found.
185 * @param int $userevidenceid The user evidence ID
186 * @return moodle_url
188 public static function user_evidence($userevidenceid) {
189 return static::get(__FUNCTION__, func_get_args());