Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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\output;
18
 
19
/**
20
 * Data structure representing an icon font.
21
 *
22
 * @copyright 2016 Damyon Wiese
23
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @package core
25
 * @category output
26
 */
27
class pix_icon_font implements templatable {
28
    /**
29
     * @var pix_icon $pixicon The original icon.
30
     */
31
    private $pixicon = null;
32
 
33
    /**
34
     * @var string $key The mapped key.
35
     */
36
    private $key;
37
 
38
    /**
39
     * @var bool $mapped The icon could not be mapped.
40
     */
41
    private $mapped;
42
 
43
    /**
44
     * Constructor
45
     *
46
     * @param pix_icon $pixicon The original icon
47
     */
48
    public function __construct(pix_icon $pixicon) {
49
        global $PAGE;
50
 
51
        $this->pixicon = $pixicon;
52
        $this->mapped = false;
53
        $iconsystem = icon_system::instance();
54
 
55
        $this->key = $iconsystem->remap_icon_name($pixicon->pix, $pixicon->component);
56
        if (!empty($this->key)) {
57
            $this->mapped = true;
58
        }
59
    }
60
 
61
    /**
62
     * Return true if this pix_icon was successfully mapped to an icon font.
63
     *
64
     * @return bool
65
     */
66
    public function is_mapped() {
67
        return $this->mapped;
68
    }
69
 
70
    /**
71
     * Export this data so it can be used as the context for a mustache template.
72
     *
73
     * @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
74
     * @return array
75
     */
76
    public function export_for_template(renderer_base $output) {
77
 
78
        $pixdata = $this->pixicon->export_for_template($output);
79
 
80
        $title = isset($this->pixicon->attributes['title']) ? $this->pixicon->attributes['title'] : '';
81
        $alt = isset($this->pixicon->attributes['alt']) ? $this->pixicon->attributes['alt'] : '';
82
        if (empty($title)) {
83
            $title = $alt;
84
        }
85
        $data = [
86
            'extraclasses' => $pixdata['extraclasses'],
87
            'title' => $title,
88
            'alt' => $alt,
89
            'key' => $this->key,
90
        ];
91
 
92
        return $data;
93
    }
94
}
95
 
96
// Alias this class to the old name.
97
// This file will be autoloaded by the legacyclasses autoload system.
98
// In future all uses of this class will be corrected and the legacy references will be removed.
99
class_alias(pix_icon_font::class, \pix_icon_font::class);