moodle /competency/classes/url.php

Language PHP Lines 192
MD5 Hash 1af153bbaacf451976e4dcc543aa75c0 Estimated Cost $1,187 (why?)
Repository https://bitbucket.org/moodle/moodle.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * URL manager.
 *
 * @package    core_competency
 * @copyright  2016 Frédéric Massart - FMCorz.net
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace core_competency;
defined('MOODLE_INTERNAL') || die();

use moodle_url;

/**
 * URL manager class.
 *
 * This class has to be used to get the URL to a resource, this allows for different
 * alternate frontends to be used without resorting to core hacks. Note that you
 * do not have to use this when you are navigating between pages of your own plugin.
 *
 * To set another resolver, set the following config value in config.php:
 * $CFG->core_competency_url_resolver = 'your_plugin\\your_url_resolver_class';
 *
 * Your URL resolver should implement the same methods as the ones listed in
 * this class (except for {{@link self::get()}}) but not statically.
 *
 * /!\ Note, resolvers MUST NEVER assume that the resource, or the resources
 * represented by the arguments, still exist.
 *
 * @package    core_competency
 * @copyright  2016 Frédéric Massart - FMCorz.net
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class url {

    /** @var url_resolver The URL resolver instance.*/
    protected static $resolver;

    /**
     * Defer to the resolver.
     *
     * @param string $resource The resource type.
     * @param array $args The arguments.
     * @return mixed
     */
    protected static function get($resource, $args) {
        global $CFG;
        if (!isset(static::$resolver)) {
            $klass = !empty($CFG->core_competency_url_resolver) ? $CFG->core_competency_url_resolver : 'tool_lp\\url_resolver';
            static::$resolver = new $klass();
        }
        if (!method_exists(static::$resolver, $resource)) {
            debugging("URL for '$resource' not implemented.", DEBUG_DEVELOPER);
            return new moodle_url('/');
        }
        return call_user_func_array([static::$resolver, $resource], $args);
    }

    /**
     * The URL where the competency can be found.
     *
     * @param int $competencyid The competency ID.
     * @param int $pagecontextid The ID of the context we are in.
     * @return moodle_url
     */
    public static function competency($competencyid, $pagecontextid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the framework can be found.
     *
     * @param int $frameworkid The framework ID.
     * @param int $pagecontextid The ID of the context we are in.
     * @return moodle_url
     */
    public static function framework($frameworkid, $pagecontextid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the frameworks can be found.
     *
     * @param int $pagecontextid The ID of the context that we are browsing.
     * @return moodle_url
     */
    public static function frameworks($pagecontextid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the plan can be found.
     *
     * @param int $planid The plan ID.
     * @return moodle_url
     */
    public static function plan($planid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the plans of a user can be found.
     *
     * @param int $userid The user ID.
     * @return moodle_url
     */
    public static function plans($userid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the template can be found.
     *
     * @param int $templateid The template ID.
     * @param int $pagecontextid The ID of the context we are in.
     * @return moodle_url
     */
    public static function template($templateid, $pagecontextid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the templates can be found.
     *
     * @param int $pagecontextid The ID of the context that we are browsing.
     * @return moodle_url
     */
    public function templates($pagecontextid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the user competency can be found.
     *
     * @param int $usercompetencyid The user competency ID
     * @return moodle_url
     */
    public static function user_competency($usercompetencyid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the user competency can be found in the context of a course.
     *
     * @param int $userid The user ID
     * @param int $competencyid The competency ID.
     * @param int $courseid The course ID.
     * @return moodle_url
     */
    public static function user_competency_in_course($userid, $competencyid, $courseid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the user competency can be found in the context of a plan.
     *
     * @param int $userid The user ID
     * @param int $competencyid The competency ID.
     * @param int $planid The plan ID.
     * @return moodle_url
     */
    public static function user_competency_in_plan($userid, $competencyid, $planid) {
        return static::get(__FUNCTION__, func_get_args());
    }

    /**
     * The URL where the user evidence (of prior learning) can be found.
     *
     * @param int $userevidenceid The user evidence ID
     * @return moodle_url
     */
    public static function user_evidence($userevidenceid) {
        return static::get(__FUNCTION__, func_get_args());
    }
}
Back to Top