Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace tool_templatelibrary;
18
 
19
use core_external\external_api;
20
use core_external\external_function_parameters;
21
use core_external\external_multiple_structure;
22
use core_external\external_value;
23
 
24
/**
25
 * This is the external API for this tool.
26
 *
27
 * @copyright  2015 Damyon Wiese
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class external extends external_api {
31
 
32
    /**
33
     * Returns description of list_templates() parameters.
34
     *
35
     * @return external_function_parameters
36
     */
37
    public static function list_templates_parameters() {
38
        $component = new external_value(
39
            PARAM_COMPONENT,
40
            'The component to search',
41
            VALUE_DEFAULT,
42
            ''
43
        );
44
        $search = new external_value(
45
            PARAM_RAW,
46
            'The search string',
47
            VALUE_DEFAULT,
48
            ''
49
        );
50
        $themename = new external_value(
51
            PARAM_COMPONENT,
52
            'The current theme',
53
            VALUE_DEFAULT,
54
            ''
55
        );
56
        $params = array('component' => $component, 'search' => $search, 'themename' => $themename);
57
        return new external_function_parameters($params);
58
    }
59
 
60
    /**
61
     * Loads the list of templates.
62
     * @param string $component Limit the search to a component.
63
     * @param string $search The search string.
64
     * @param string $themename The name of theme
65
     * @return array[string]
66
     */
67
    public static function list_templates($component, $search, $themename = '') {
68
        $params = self::validate_parameters(self::list_templates_parameters(),
69
                                            array(
70
                                                'component' => $component,
71
                                                'search' => $search,
72
                                                'themename' => $themename,
73
                                            ));
74
 
75
        return api::list_templates($component, $search, $themename);
76
    }
77
 
78
    /**
79
     * Returns description of list_templates() result value.
80
     *
81
     * @return \core_external\external_description
82
     */
83
    public static function list_templates_returns() {
84
        return new external_multiple_structure(new external_value(PARAM_RAW, 'The template name (format is component/templatename)'));
85
    }
86
 
87
    /**
88
     * Returns description of load_canonical_template() parameters.
89
     *
90
     * @return external_function_parameters
91
     */
92
    public static function load_canonical_template_parameters() {
93
        return new external_function_parameters(
94
                array('component' => new external_value(PARAM_COMPONENT, 'component containing the template'),
95
                      'template' => new external_value(PARAM_SAFEPATH, 'name of the template'))
96
            );
97
    }
98
 
99
    /**
100
     * Return a mustache template.
101
     * Note - this function differs from the function core_output_load_template
102
     * because it will never return a theme overridden version of a template.
103
     *
104
     * @param string $component The component that holds the template.
105
     * @param string $template The name of the template.
106
     * @return string the template, false if template doesn't exist.
107
     */
108
    public static function load_canonical_template($component, $template) {
109
        $params = self::validate_parameters(self::load_canonical_template_parameters(),
110
                                            array('component' => $component,
111
                                                  'template' => $template));
112
 
113
        $component = $params['component'];
114
        $template = $params['template'];
115
 
116
        return api::load_canonical_template($component, $template);
117
    }
118
 
119
    /**
120
     * Returns description of load_canonical_template() result value.
121
     *
122
     * @return \core_external\external_description
123
     */
124
    public static function load_canonical_template_returns() {
125
        return new external_value(PARAM_RAW, 'template');
126
    }
127
}