Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 37... Línea 37...
37
     * Returns description of load_template() parameters.
37
     * Returns description of load_template() parameters.
38
     *
38
     *
39
     * @return external_function_parameters
39
     * @return external_function_parameters
40
     */
40
     */
41
    public static function load_template_parameters() {
41
    public static function load_template_parameters() {
42
        return new external_function_parameters(
42
        return new external_function_parameters([
43
                array('component' => new external_value(PARAM_COMPONENT, 'component containing the template'),
43
            'component' => new external_value(PARAM_COMPONENT, 'component containing the template'),
44
                      'template' => new external_value(PARAM_SAFEPATH, 'name of the template'),
44
            'template' => new external_value(PARAM_SAFEPATH, 'name of the template'),
45
                      'themename' => new external_value(PARAM_ALPHANUMEXT, 'The current theme.'),
45
            'themename' => new external_value(PARAM_ALPHANUMEXT, 'The current theme.'),
46
                      'includecomments' => new external_value(PARAM_BOOL, 'Include comments or not', VALUE_DEFAULT, false)
46
            'includecomments' => new external_value(PARAM_BOOL, 'Include comments or not', VALUE_DEFAULT, false),
47
                         )
-
 
48
            );
47
        ]);
49
    }
48
    }
Línea 50... Línea 49...
50
 
49
 
51
    /**
50
    /**
52
     * Return a mustache template, and all the strings it requires.
51
     * Return a mustache template, and all the strings it requires.
Línea 58... Línea 57...
58
     */
57
     */
59
    public static function load_template($component, $template, $themename, $includecomments = false) {
58
    public static function load_template($component, $template, $themename, $includecomments = false) {
60
        global $DB, $CFG, $PAGE;
59
        global $DB, $CFG, $PAGE;
Línea 61... Línea 60...
61
 
60
 
62
        $PAGE->set_context(context_system::instance());
61
        $PAGE->set_context(context_system::instance());
-
 
62
        $params = self::validate_parameters(
-
 
63
            self::load_template_parameters(),
63
        $params = self::validate_parameters(self::load_template_parameters(),
64
            [
64
                                            array('component' => $component,
65
                'component' => $component,
65
                                                  'template' => $template,
66
                'template' => $template,
66
                                                  'themename' => $themename,
67
                'themename' => $themename,
-
 
68
                'includecomments' => $includecomments,
-
 
69
            ],
Línea 67... Línea 70...
67
                                                  'includecomments' => $includecomments));
70
        );
68
 
71
 
69
        $loader = new mustache_template_source_loader();
72
        $loader = new mustache_template_source_loader();
70
        // Will throw exceptions if the template does not exist.
73
        // Will throw exceptions if the template does not exist.
71
        return $loader->load(
74
        return $loader->load(
72
            $params['component'],
75
            $params['component'],
73
            $params['template'],
76
            $params['template'],
74
            $params['themename'],
77
            $params['themename'],
75
            $params['includecomments']
78
            $params['includecomments'],
Línea 76... Línea 79...
76
        );
79
        );
77
    }
80
    }
Línea 106... Línea 109...
106
     * @param string $component The component that holds the template.
109
     * @param string $component The component that holds the template.
107
     * @param string $template The name of the template.
110
     * @param string $template The name of the template.
108
     * @param string $themename The name of the current theme.
111
     * @param string $themename The name of the current theme.
109
     * @param bool $includecomments Whether to strip comments from the template source.
112
     * @param bool $includecomments Whether to strip comments from the template source.
110
     * @param string $lang moodle translation language, null means use current.
113
     * @param string $lang moodle translation language, null means use current.
111
     * @return string the template
114
     * @return array the template
112
     */
115
     */
113
    public static function load_template_with_dependencies(
116
    public static function load_template_with_dependencies(
114
        string $component,
117
        string $component,
115
        string $template,
118
        string $template,
116
        string $themename,
119
        string $themename,
117
        bool $includecomments = false,
120
        bool $includecomments = false,
118
        string $lang = null
121
        ?string $lang = null
119
    ) {
122
    ) {
120
        global $DB, $CFG, $PAGE;
123
        global $DB, $CFG, $PAGE;
Línea 121... Línea 124...
121
 
124
 
122
        $params = self::validate_parameters(
125
        $params = self::validate_parameters(
123
            self::load_template_with_dependencies_parameters(),
126
            self::load_template_with_dependencies_parameters(),
124
            [
127
            [
125
                'component' => $component,
128
                'component' => $component,
126
                'template' => $template,
129
                'template' => $template,
127
                'themename' => $themename,
130
                'themename' => $themename,
128
                'includecomments' => $includecomments,
131
                'includecomments' => $includecomments,
129
                'lang' => $lang
132
                'lang' => $lang,
130
            ]
133
            ]
Línea 131... Línea 134...
131
        );
134
        );
132
 
135
 
Línea 139... Línea 142...
139
            $params['includecomments'],
142
            $params['includecomments'],
140
            [],
143
            [],
141
            [],
144
            [],
142
            $params['lang']
145
            $params['lang']
143
        );
146
        );
144
        $formatdependencies = function($dependency) {
147
        $formatdependencies = function ($dependency) {
145
            $results = [];
148
            $results = [];
146
            foreach ($dependency as $dependencycomponent => $dependencyvalues) {
149
            foreach ($dependency as $dependencycomponent => $dependencyvalues) {
147
                foreach ($dependencyvalues as $dependencyname => $dependencyvalue) {
150
                foreach ($dependencyvalues as $dependencyname => $dependencyvalue) {
148
                    array_push($results, [
151
                    array_push($results, [
149
                        'component' => $dependencycomponent,
152
                        'component' => $dependencycomponent,
150
                        'name' => $dependencyname,
153
                        'name' => $dependencyname,
151
                        'value' => $dependencyvalue
154
                        'value' => $dependencyvalue,
152
                    ]);
155
                    ]);
153
                }
156
                }
154
            }
157
            }
155
            return $results;
158
            return $results;
156
        };
159
        };
Línea 157... Línea 160...
157
 
160
 
158
        // Now we have to unpack the dependencies into a format that can be returned
161
        // Now we have to unpack the dependencies into a format that can be returned
159
        // by external functions (because they don't support dynamic keys).
162
        // by external functions (because they don't support dynamic keys).
160
        return [
163
        return [
161
            'templates' => $formatdependencies($dependencies['templates']),
164
            'templates' => $formatdependencies($dependencies['templates']),
162
            'strings' => $formatdependencies($dependencies['strings'])
165
            'strings' => $formatdependencies($dependencies['strings']),
163
        ];
166
        ];
Línea 164... Línea 167...
164
    }
167
    }
165
 
168
 
Línea 170... Línea 173...
170
     */
173
     */
171
    public static function load_template_with_dependencies_returns() {
174
    public static function load_template_with_dependencies_returns() {
172
        $resourcestructure = new external_single_structure([
175
        $resourcestructure = new external_single_structure([
173
            'component' => new external_value(PARAM_COMPONENT, 'component containing the resource'),
176
            'component' => new external_value(PARAM_COMPONENT, 'component containing the resource'),
174
            'name' => new external_value(PARAM_TEXT, 'name of the resource'),
177
            'name' => new external_value(PARAM_TEXT, 'name of the resource'),
175
            'value' => new external_value(PARAM_RAW, 'resource value')
178
            'value' => new external_value(PARAM_RAW, 'resource value'),
176
        ]);
179
        ]);
Línea 177... Línea 180...
177
 
180
 
178
        return new external_single_structure([
181
        return new external_single_structure([
179
            'templates' => new external_multiple_structure($resourcestructure),
182
            'templates' => new external_multiple_structure($resourcestructure),
180
            'strings' => new external_multiple_structure($resourcestructure)
183
            'strings' => new external_multiple_structure($resourcestructure),
181
        ]);
184
        ]);
182
    }
-
 
183
 
-
 
184
    /**
-
 
185
     * Returns description of load_icon_map() parameters.
-
 
186
     *
-
 
187
     * @return external_function_parameters
-
 
188
     */
-
 
189
    public static function load_fontawesome_icon_map_parameters() {
-
 
190
        return new external_function_parameters([]);
-
 
191
    }
-
 
192
 
-
 
193
    /**
-
 
194
     * Return a mapping of icon names to icons.
-
 
195
     *
-
 
196
     * @deprecated since Moodle 3.10
-
 
197
     * @return array the mapping
-
 
198
     */
-
 
199
    public static function load_fontawesome_icon_map() {
-
 
200
        global $PAGE;
-
 
201
 
-
 
202
        return load_fontawesome_map::execute($PAGE->theme->name);
-
 
203
    }
-
 
204
 
-
 
205
    /**
-
 
206
     * Returns description of load_icon_map() result value.
-
 
207
     *
-
 
208
     * @return \core_external\external_description
-
 
209
     */
-
 
210
    public static function load_fontawesome_icon_map_returns() {
-
 
211
        return load_fontawesome_map::execute_returns();
-
 
212
    }
-
 
213
 
-
 
214
    /**
-
 
215
     * The `load_fontawesome_icon_map` function has been replaced with
-
 
216
     * @see load_fontawesome_map::execute()
-
 
217
     *
-
 
218
     * @return bool
-
 
219
     */
-
 
220
    public static function load_fontawesome_icon_map_is_deprecated() {
-
 
221
        return true;
-
 
222
    }
185
    }