Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 31... Línea 31...
31
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @since Moodle 2.9
32
 * @since Moodle 2.9
33
 * @package core
33
 * @package core
34
 * @category output
34
 * @category output
35
 */
35
 */
36
class notification implements \renderable, \templatable {
36
class notification implements renderable, templatable {
37
 
-
 
38
    /**
37
    /**
39
     * A notification of level 'success'.
38
     * A notification of level 'success'.
40
     */
39
     */
41
    const NOTIFY_SUCCESS = 'success';
40
    const NOTIFY_SUCCESS = 'success';
Línea 59... Línea 58...
59
     * @var string Message payload.
58
     * @var string Message payload.
60
     */
59
     */
61
    protected $message = '';
60
    protected $message = '';
Línea 62... Línea 61...
62
 
61
 
-
 
62
    /**
-
 
63
     * @var string Title payload.
-
 
64
     */
-
 
65
    protected ?string $title = null;
-
 
66
 
-
 
67
    /**
-
 
68
     * @var string Title icon name.
-
 
69
     */
-
 
70
    protected ?string $titleicon = null;
-
 
71
 
63
    /**
72
    /**
64
     * @var string Message type.
73
     * @var string Message type.
65
     */
74
     */
Línea 66... Línea 75...
66
    protected $messagetype = self::NOTIFY_WARNING;
75
    protected $messagetype = self::NOTIFY_WARNING;
Línea 76... Línea 85...
76
    protected $closebutton = true;
85
    protected $closebutton = true;
Línea 77... Línea 86...
77
 
86
 
78
    /**
87
    /**
79
     * @var array $extraclasses A list of any extra classes that may be required.
88
     * @var array $extraclasses A list of any extra classes that may be required.
80
     */
89
     */
Línea 81... Línea 90...
81
    protected $extraclasses = array();
90
    protected $extraclasses = [];
82
 
91
 
83
    /**
92
    /**
84
     * Notification constructor.
93
     * Notification constructor.
85
     *
94
     *
86
     * @param string $message the message to print out
95
     * @param string $message the message to print out
-
 
96
     * @param ?string $messagetype one of the NOTIFY_* constants..
-
 
97
     * @param bool $closebutton Whether to show a close icon to remove the notification (default true).
-
 
98
     * @param ?string $title the title of the notification
87
     * @param ?string $messagetype one of the NOTIFY_* constants..
99
     * @param ?string $titleicon if the title should have an icon you can give the icon name with the component
88
     * @param bool $closebutton Whether to show a close icon to remove the notification (default true).
100
     *  (e.g. 'i/circleinfo, core' or 'i/circleinfo' if the icon is from core
-
 
101
     */
-
 
102
    public function __construct(
-
 
103
        $message,
-
 
104
        $messagetype = null,
-
 
105
        $closebutton = true,
-
 
106
        ?string $title = null,
89
     */
107
        ?string $titleicon = null
Línea 90... Línea 108...
90
    public function __construct($message, $messagetype = null, $closebutton = true) {
108
    ) {
91
        $this->message = $message;
109
        $this->message = $message;
92
 
110
 
Línea 93... Línea 111...
93
        if (empty($messagetype)) {
111
        if (empty($messagetype)) {
Línea 94... Línea 112...
94
            $messagetype = self::NOTIFY_ERROR;
112
            $messagetype = self::NOTIFY_ERROR;
-
 
113
        }
-
 
114
 
-
 
115
        $this->messagetype = $messagetype;
-
 
116
 
95
        }
117
        $this->closebutton = $closebutton;
Línea 96... Línea 118...
96
 
118
 
97
        $this->messagetype = $messagetype;
119
        $this->title = $title;
98
 
120
 
Línea 127... Línea 149...
127
     * Add any extra classes that this notification requires.
149
     * Add any extra classes that this notification requires.
128
     *
150
     *
129
     * @param array $classes
151
     * @param array $classes
130
     * @return $this
152
     * @return $this
131
     */
153
     */
132
    public function set_extra_classes($classes = array()) {
154
    public function set_extra_classes($classes = []) {
133
        $this->extraclasses = $classes;
155
        $this->extraclasses = $classes;
Línea 134... Línea 156...
134
 
156
 
135
        return $this;
157
        return $this;
Línea 158... Línea 180...
158
     *
180
     *
159
     * @param \renderer_base $output typically, the renderer that's calling this function
181
     * @param \renderer_base $output typically, the renderer that's calling this function
160
     * @return array data context for a mustache template
182
     * @return array data context for a mustache template
161
     */
183
     */
162
    public function export_for_template(\renderer_base $output) {
184
    public function export_for_template(\renderer_base $output) {
-
 
185
        $titleicon = null;
-
 
186
        if (!empty($this->titleicon)) {
-
 
187
            $icon = $this->titleicon;
-
 
188
            $component = 'core';
-
 
189
            if (strpos($icon, ',') !== false) {
-
 
190
                list($icon, $component) = explode(',', $icon);
-
 
191
            }
-
 
192
            $titleicon = (object) [
-
 
193
                'icon' => $icon,
-
 
194
                'component' => $component,
-
 
195
            ];
-
 
196
        }
163
        return array(
197
        return [
164
            'message'       => clean_text($this->message),
198
            'message'       => clean_text($this->message),
165
            'extraclasses'  => implode(' ', $this->extraclasses),
199
            'extraclasses'  => implode(' ', $this->extraclasses),
166
            'announce'      => $this->announce,
200
            'announce'      => $this->announce,
167
            'closebutton'   => $this->closebutton,
201
            'closebutton'   => $this->closebutton,
168
            'issuccess'         => $this->messagetype === 'success',
202
            'issuccess'         => $this->messagetype === 'success',
169
            'isinfo'            => $this->messagetype === 'info',
203
            'isinfo'            => $this->messagetype === 'info',
170
            'iswarning'         => $this->messagetype === 'warning',
204
            'iswarning'         => $this->messagetype === 'warning',
171
            'iserror'           => $this->messagetype === 'error',
205
            'iserror'           => $this->messagetype === 'error',
-
 
206
            'title'             => $this->title,
-
 
207
            'titleicon'         => $titleicon,
172
        );
208
        ];
173
    }
209
    }
Línea -... Línea 210...
-
 
210
 
-
 
211
    /**
-
 
212
     * Get the name of the template to use for this templatable.
-
 
213
     *
-
 
214
     * @return string
174
 
215
     */
175
    public function get_template_name() {
216
    public function get_template_name() {
176
        $templatemappings = [
217
        $templatemappings = [
177
            // Current types mapped to template names.
218
            // Current types mapped to template names.
178
            'success'           => 'core/notification_success',
219
            'success'           => 'core/notification_success',