source: moodle/trunk/fuentes/admin/tool/templatelibrary/classes/external.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 4.4 KB
Line 
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 */
24namespace tool_templatelibrary;
25
26require_once("$CFG->libdir/externallib.php");
27
28use external_api;
29use external_function_parameters;
30use external_value;
31use external_format_value;
32use external_single_structure;
33use external_multiple_structure;
34use 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 */
42class 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     * 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]
71     */
72    public static function list_templates($component, $search) {
73        $params = self::validate_parameters(self::list_templates_parameters(),
74                                            array(
75                                                'component' => $component,
76                                                'search' => $search,
77                                            ));
78
79        return api::list_templates($component, $search);
80    }
81
82    /**
83     * Returns description of list_templates() result value.
84     *
85     * @return external_description
86     */
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)'));
89    }
90
91    /**
92     * Returns description of load_canonical_template() parameters.
93     *
94     * @return external_function_parameters
95     */
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'))
100            );
101    }
102
103    /**
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.
107     *
108     * @param string $component The component that holds the template.
109     * @param string $template The name of the template.
110     * @return string the template
111     */
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));
116
117        $component = $params['component'];
118        $template = $params['template'];
119
120        return api::load_canonical_template($component, $template);
121    }
122
123    /**
124     * Returns description of load_canonical_template() result value.
125     *
126     * @return external_description
127     */
128    public static function load_canonical_template_returns() {
129        return new external_value(PARAM_RAW, 'template');
130    }
131}
Note: See TracBrowser for help on using the repository browser.