PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/competency/classes/url.php

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