2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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();
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
52 /** @var url_resolver The URL resolver instance.*/
53 protected static $resolver;
56 * Defer to the resolver.
58 * @param string $resource The resource type.
59 * @param array $args The arguments.
62 protected static function get($resource, $args) {
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);
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.
82 public static function competency($competencyid, $pagecontextid) {
83 return static::get(__FUNCTION__
, func_get_args());
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.
93 public static function framework($frameworkid, $pagecontextid) {
94 return static::get(__FUNCTION__
, func_get_args());
98 * The URL where the frameworks can be found.
100 * @param int $pagecontextid The ID of the context that we are browsing.
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.
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.
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.
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.
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
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.
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.
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
188 public static function user_evidence($userevidenceid) {
189 return static::get(__FUNCTION__
, func_get_args());