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/>.
18 * This is the external API for this tool.
20 * @package tool_templatelibrary
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace tool_templatelibrary;
26 require_once("$CFG->libdir/externallib.php");
29 use external_function_parameters;
31 use external_format_value;
32 use external_single_structure;
33 use external_multiple_structure;
34 use invalid_parameter_exception;
37 * This is the external API for this tool.
39 * @copyright 2015 Damyon Wiese
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class external extends external_api {
45 * Returns description of list_templates() parameters.
47 * @return external_function_parameters
49 public static function list_templates_parameters() {
50 $component = new external_value(
52 'The component to search',
56 $search = new external_value(
62 $params = array('component' => $component, 'search' => $search);
63 return new external_function_parameters($params);
67 * Loads the list of templates.
68 * @param string $component Limit the search to a component.
69 * @param string $search The search string.
70 * @return array[string]
72 public static function list_templates($component, $search) {
73 $params = self::validate_parameters(self::list_templates_parameters(),
75 'component' => $component,
79 return api::list_templates($component, $search);
83 * Returns description of list_templates() result value.
85 * @return external_description
87 public static function list_templates_returns() {
88 return new external_multiple_structure(new external_value(PARAM_RAW, 'The template name (format is component/templatename)'));
92 * Returns description of load_canonical_template() parameters.
94 * @return external_function_parameters
96 public static function load_canonical_template_parameters() {
97 return new external_function_parameters(
98 array('component' => new external_value(PARAM_COMPONENT, 'component containing the template'),
99 'template' => new external_value(PARAM_ALPHANUMEXT, 'name of the template'))
104 * Return a mustache template.
105 * Note - this function differs from the function core_output_load_template
106 * because it will never return a theme overridden version of a template.
108 * @param string $component The component that holds the template.
109 * @param string $template The name of the template.
110 * @return string the template
112 public static function load_canonical_template($component, $template) {
113 $params = self::validate_parameters(self::load_canonical_template_parameters(),
114 array('component' => $component,
115 'template' => $template));
117 $component = $params['component'];
118 $template = $params['template'];
120 return api::load_canonical_template($component, $template);
124 * Returns description of load_canonical_template() result value.
126 * @return external_description
128 public static function load_canonical_template_returns() {
129 return new external_value(PARAM_RAW, 'template');