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
/**
18
 * Icon handling abstraction.
19
 *
20
 * @package   block_multiblock
21
 * @copyright 2020 Peter Spicer <peter.spicer@catalyst-eu.net>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace block_multiblock;
26
 
27
use core\output\flex_icon;
28
use pix_icon;
29
 
30
/**
31
 * Icon handling abstraction.
32
 *
33
 * Intended to abstract away Moodle 3.5+ vs Totara 12+.
34
 *
35
 * @package   block_multiblock
36
 * @copyright 2020 Peter Spicer <peter.spicer@catalyst-eu.net>
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class icon_helper {
40
 
41
    /**
42
     * Returns an icon.
43
     *
44
     * For cases where the icon identifier is the same in both Totara and Moodle,
45
     * this function takes care of the general setup.
46
     *
47
     * @param string $icon The icon identifier, e.g. "t/preferences".
48
     * @param string $str The alt text for this icon.
49
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
50
     */
51
    protected static function general_icon(string $icon, string $str) {
52
        if (class_exists('\\core\\output\\flex_icon')) {
53
            return flex_icon::get_icon($icon, 'moodle', ['class' => 'iconsmall', 'alt' => $str]);
54
        } else {
55
            return new pix_icon($icon, $str, 'moodle', ['class' => 'iconsmall']);
56
        }
57
    }
58
 
59
    /**
60
     * Returns a arrow up icon.
61
     *
62
     * @param string $str The alt text for this icon.
63
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
64
     */
65
    public static function arrow_up(string $str) {
66
        return static::general_icon('t/up', $str);
67
    }
68
 
69
    /**
70
     * Returns a arrow down icon.
71
     *
72
     * @param string $str The alt text for this icon.
73
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
74
     */
75
    public static function arrow_down(string $str) {
76
        return static::general_icon('t/down', $str);
77
    }
78
 
79
    /**
80
     * Returns a settings icon.
81
     *
82
     * @param string $str The alt text for this icon.
83
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
84
     */
85
    public static function settings(string $str) {
86
        return static::general_icon('i/settings', $str);
87
    }
88
 
89
    /**
90
     * Returns a preferences icon.
91
     *
92
     * @param string $str The alt text for this icon.
93
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
94
     */
95
    public static function preferences(string $str) {
96
        return static::general_icon('t/preferences', $str);
97
    }
98
 
99
    /**
100
     * Returns a trashcan icon.
101
     *
102
     * @param string $str The alt text for this icon.
103
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
104
     */
105
    public static function delete(string $str) {
106
        if (class_exists('\\core\\output\\flex_icon')) {
107
            return flex_icon::get_icon('i/delete', 'moodle', ['class' => 'iconsmall', 'alt' => $str]);
108
        } else {
109
            return new pix_icon('t/delete', $str, 'moodle', ['class' => 'iconsmall']);
110
        }
111
    }
112
 
113
    /**
114
     * Returns an icon to split a subblock up a level.
115
     *
116
     * @param string $str The alt text for this icon.
117
     * @return mixed An icon object for rendering. Type dependent whether using Moodle or Totara.
118
     */
119
    public static function level_up(string $str) {
120
        if (class_exists('\\core\\output\\flex_icon')) {
121
            return flex_icon::get_icon('level-up', 'moodle', ['class' => 'iconsmall', 'alt' => $str]);
122
        } else {
123
            return new pix_icon('i/import', $str, 'moodle', ['class' => 'iconsmall', 'alt' => $str]);
124
        }
125
    }
126
 
127
    /**
128
     * Returns a spacer icon to align action icon sets.
129
     *
130
     * @return string The rendered HTML for a spacer icon.
131
     */
132
    public static function space() : string {
133
        global $OUTPUT;
134
 
135
        if (class_exists('\\core\\output\\flex_icon')) {
136
            return $OUTPUT->flex_icon('spacer');
137
        } else {
138
            return $OUTPUT->pix_icon('i/empty', '');
139
        }
140
    }
141
}