forked from tigusigalpa/moodle-tool_imageoptimize
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnotification.php
More file actions
105 lines (97 loc) · 3.07 KB
/
Copy pathnotification.php
File metadata and controls
105 lines (97 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Admin setting notification
*
* @package tool_imageoptimize
* @copyright 2020 Igor Sazonov <sovletig@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/adminlib.php');
/**
* Notification panel
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_imageoptimize_notification extends admin_setting {
/**
* Notification type
*
* @var string
*/
protected $type = 'info';
/**
* not a setting, just text
*
* @param string $name unique ascii name, either 'mysetting' for settings that in config,
* or 'myplugin/mysetting' for ones in config_plugins.
* @param string $visiblename heading
* @param string $text text in box
* @param string $type box type error|info|success|warning
*/
public function __construct($name, $visiblename, $text, $type = 'info') {
$this->nosave = true;
if (in_array($type, ['error', 'info', 'success', 'warning'])) {
$this->type = $type;
}
parent::__construct($name, $visiblename, $text, '');
}
/**
* Always returns true
* @return bool Always returns true
*/
public function get_setting() {
return true;
}
/**
* Never write settings
* @return string Always returns an empty string
*/
public function write_setting($data) {
// do not write any setting
return '';
}
/**
* Returns an HTML string
*
* @param string $data
* @param string $query
* @return string Returns an HTML string
*/
public function output_html($data, $query = '') {
global $OUTPUT;
$context = [
'message' => $this->description
];
switch ($this->type) {
case 'error':
$context['extraclasses'] = 'alert-danger';
break;
case 'info':
$context['extraclasses'] = 'alert-info';
break;
case 'success':
$context['extraclasses'] = 'alert-success';
break;
case 'warning':
$context['extraclasses'] = 'alert-warning';
break;
}
return $OUTPUT->render_from_template('tool_imageoptimize/notification', $context);
}
}