Commit | Line | Data |
---|---|---|
274d79c9 DW |
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 | /** | |
18 | * This is the external API for this tool. | |
19 | * | |
20 | * @package tool_templatelibrary | |
21 | * @copyright 2015 Damyon Wiese | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | namespace tool_templatelibrary; | |
25 | ||
26 | require_once("$CFG->libdir/externallib.php"); | |
27 | ||
28 | use external_api; | |
29 | use external_function_parameters; | |
30 | use external_value; | |
31 | use external_format_value; | |
32 | use external_single_structure; | |
33 | use external_multiple_structure; | |
34 | use invalid_parameter_exception; | |
35 | ||
36 | /** | |
37 | * This is the external API for this tool. | |
38 | * | |
39 | * @copyright 2015 Damyon Wiese | |
40 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
41 | */ | |
42 | class external extends external_api { | |
43 | ||
44 | /** | |
45 | * Returns description of list_templates() parameters. | |
46 | * | |
47 | * @return external_function_parameters | |
48 | */ | |
49 | public static function list_templates_parameters() { | |
50 | $component = new external_value( | |
51 | PARAM_COMPONENT, | |
52 | 'The component to search', | |
53 | VALUE_DEFAULT, | |
54 | '' | |
55 | ); | |
56 | $search = new external_value( | |
57 | PARAM_RAW, | |
58 | 'The search string', | |
59 | VALUE_DEFAULT, | |
60 | '' | |
61 | ); | |
62 | $params = array('component' => $component, 'search' => $search); | |
63 | return new external_function_parameters($params); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Expose to AJAX | |
68 | * @return boolean | |
69 | */ | |
70 | public static function list_templates_is_allowed_from_ajax() { | |
71 | return true; | |
72 | } | |
73 | ||
74 | /** | |
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] | |
79 | */ | |
80 | public static function list_templates($component, $search) { | |
81 | $params = self::validate_parameters(self::list_templates_parameters(), | |
82 | array( | |
83 | 'component' => $component, | |
84 | 'search' => $search, | |
85 | )); | |
86 | ||
87 | return api::list_templates($component, $search); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Returns description of list_templates() result value. | |
92 | * | |
93 | * @return external_description | |
94 | */ | |
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)')); | |
97 | } | |
98 | } |