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 * Mustache helper to load strings from string_manager.
22 * @copyright 2015 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace core\output;
29 use external_function_parameters;
30 use external_multiple_structure;
31 use external_single_structure;
39 * This class contains a list of webservice functions related to output.
41 * @copyright 2015 Damyon Wiese
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45 class external extends external_api {
47 * Returns description of load_template() parameters.
49 * @return external_function_parameters
51 public static function load_template_parameters() {
52 return new external_function_parameters(
53 array('component' => new external_value(PARAM_COMPONENT, 'component containing the template'),
54 'template' => new external_value(PARAM_ALPHANUMEXT, 'name of the template'),
55 'themename' => new external_value(PARAM_ALPHANUMEXT, 'The current theme.'),
61 * Return a mustache template, and all the strings it requires.
63 * @param string $component The component that holds the template.
64 * @param string $templatename The name of the template.
65 * @param string $themename The name of the current theme.
66 * @return string the template
68 public static function load_template($component, $template, $themename) {
69 global $DB, $CFG, $PAGE;
71 $params = self::validate_parameters(self::load_template_parameters(),
72 array('component' => $component,
73 'template' => $template,
74 'themename' => $themename));
76 $component = $params['component'];
77 $template = $params['template'];
78 $themename = $params['themename'];
80 $templatename = $component . '/' . $template;
82 // Will throw exceptions if the template does not exist.
83 $filename = mustache_template_finder::get_template_filepath($templatename, $themename);
84 $templatestr = file_get_contents($filename);
90 * Returns description of load_template() result value.
92 * @return external_description
94 public static function load_template_returns() {
95 return new external_value(PARAM_RAW, 'template');
99 * Returns description of load_icon_map() parameters.
101 * @return external_function_parameters
103 public static function load_fontawesome_icon_map_parameters() {
104 return new external_function_parameters([]);
108 * Return a mapping of icon names to icons.
110 * @param string $system
111 * @return array the mapping
113 public static function load_fontawesome_icon_map() {
115 $instance = icon_system::instance(icon_system::FONTAWESOME);
117 $map = $instance->get_icon_name_map();
121 foreach ($map as $from => $to) {
122 list($component, $pix) = explode(':', $from);
124 $one['component'] = $component;
133 * Returns description of load_icon_map() result value.
135 * @return external_description
137 public static function load_fontawesome_icon_map_returns() {
138 return new external_multiple_structure(new external_single_structure(
140 'component' => new external_value(PARAM_COMPONENT, 'The component for the icon.'),
141 'pix' => new external_value(PARAM_RAW, 'Value to map the icon from.'),
142 'to' => new external_value(PARAM_RAW, 'Value to map the icon to.')