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 core\external\output\icon_system;
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_single_structure;
23
use core_external\external_value;
24
use core\output\icon_system_fontawesome;
25
use theme_config;
26
 
27
/**
28
 * Web service to load font awesome icon maps.
29
 *
30
 * @package    core
31
 * @category   external
32
 * @copyright  2020 Andrew Nicols <andrew@nicols.co.uk>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class load_fontawesome_map extends external_api {
36
 
37
    /**
38
     * Description of the parameters suitable for the `execute` function.
39
     *
40
     * @return external_function_parameters
41
     */
42
    public static function execute_parameters() {
43
        return new external_function_parameters([
44
            'themename' => new external_value(PARAM_ALPHANUMEXT, 'The theme to fetch the map for'),
45
        ]);
46
    }
47
 
48
    /**
49
     * Return a mapping of icon names to icons.
50
     *
51
     * @param   string $themename The theme to fetch icons for
52
     * @return  array the mapping
53
     */
54
    public static function execute(string $themename) {
55
        [
56
            'themename' => $themename,
57
        ] = self::validate_parameters(self::execute_parameters(), [
58
            'themename' => $themename,
59
        ]);
60
 
61
        $theme = theme_config::load($themename);
62
        $instance = icon_system_fontawesome::instance($theme->get_icon_system());
63
 
64
        $result = [];
65
        foreach ($instance->get_icon_name_map() as $from => $to) {
66
            [$component, $pix] = explode(':', $from);
67
            $result[] = [
68
                'component' => $component,
69
                'pix' => $pix,
70
                'to' => $to,
71
            ];
72
        }
73
 
74
        return $result;
75
    }
76
 
77
    /**
78
     * Description of the return value for the `execute` function.
79
     *
80
     * @return \core_external\external_description
81
     */
82
    public static function execute_returns() {
83
        return new external_multiple_structure(new external_single_structure([
84
            'component' => new external_value(PARAM_COMPONENT, 'The component for the icon.'),
85
            'pix' => new external_value(PARAM_RAW, 'Value to map the icon from.'),
86
            'to' => new external_value(PARAM_RAW, 'Value to map the icon to.'),
87
        ]));
88
    }
89
}