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);
70 public static function list_templates_is_allowed_from_ajax() {
75 * Loads the list of templates.
76 * @param string $component Limit the search to a component.
77 * @param string $search The search string.
78 * @return array[string]
80 public static function list_templates($component, $search) {
81 $params = self::validate_parameters(self::list_templates_parameters(),
83 'component' => $component,
87 return api::list_templates($component, $search);
91 * Returns description of list_templates() result value.
93 * @return external_description
95 public static function list_templates_returns() {
96 return new external_multiple_structure(new external_value(PARAM_RAW, 'The template name (format is component/templatename)'));