-
Notifications
You must be signed in to change notification settings - Fork 8
/
renderer.php
243 lines (231 loc) · 14 KB
/
renderer.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?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/>.
/**
* Advanced Notifications renderer - what gets displayed
*
* @package block_advnotifications
* @copyright 2016 onwards LearningWorks Ltd {@link https://learningworks.co.nz/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Zander Potgieter <zander.potgieter@learningworks.co.nz>
*/
defined('MOODLE_INTERNAL') || die;
/**
* Renders notifications.
*
* @copyright 2016 onwards LearningWorks Ltd {@link https://learningworks.co.nz/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_advnotifications_renderer extends plugin_renderer_base
{
/**
* Renders notification on page.
*
* @param array $notifications Attributes about notifications to render.
* @return string Returns HTML to render notification.
*/
public function render_notification($notifications) {
$html = '';
// Render all the appropriate notifications.
foreach ($notifications as $notification) {
// Open notification block.
$html .= '<div class="notification-block-wrapper' . $notification['extraclasses'] .
'" data-dismiss="' . $notification['notifid'] .
'"><div class="alert alert-' . $notification['alerttype'] . '">';
if (!empty($notification['aiconflag']) && $notification['aiconflag'] == 1) {
$html .= '<img class="notification_aicon" src="' .
$this->image_url($notification['aicon'], 'block_advnotifications') . '"/>';
}
if (!empty($notification['title'])) {
$html .= '<strong>' . $notification['title'] . '</strong> ';
}
if (!empty($notification['message'])) {
$html .= $notification['message'];
}
// If dismissible, add close button.
if ($notification['dismissible'] == 1) {
$html .= '<div class="notification-block-close"><strong>×</strong></div>';
}
// Close notification block.
$html .= '</div></div>';
}
return $html;
}
/**
* Render interface to add a notification.
*
* @param array $params - passes information such whether notification is new or the block's instance id.
* @return string - returns HTML to render (add notification form HTML).
* @throws coding_exception
*/
public function add_notification($params) {
global $CFG;
$html = '';
// New Notification Form.
$html .= '<div id="add_notification_wrapper_id" class="add_notification_wrapper">
<div class="add_notification_header"><h2>' .
get_string('advnotifications_add_heading', 'block_advnotifications') .
'</h2>
</div>
<div class="add_notification_form_wrapper">
<form id="add_notification_form" action="' . $CFG->wwwroot .
'/blocks/advnotifications/pages/process.php" method="POST">
<div class="form-check">
<input type="checkbox" id="add_notification_enabled" class="form-check-input" name="enabled"/>
<label for="add_notification_enabled" class="form-check-label">' .
get_string('advnotifications_enabled', 'block_advnotifications') .
'</label>
</div>' .
((array_key_exists('blockid', $params) &&
array_key_exists('global', $params) &&
$params['global'] === true) ?
'<div class="form-check">
<input type="checkbox" id="add_notification_global" class="form-check-input" name="global"/>
<label for="add_notification_global" class="form-check-label">' .
get_string('advnotifications_global', 'block_advnotifications') .
'</label>
<input type="hidden" id="add_notification_blockid" name="blockid" value="' . $params['blockid'] .
'"/>
</div>' :
((array_key_exists('global', $params) &&
$params['global'] === true) ?
'<div class="form-group">
<strong>
<em>' . get_string('add_notification_global_notice', 'block_advnotifications') . '</em>
</strong>
<input type="hidden" id="add_notification_global" name="global" value="1"/>
</div>' :
'<div class="form-group">
<strong>' . get_string('add_notif_local_notice', 'block_advnotifications') . '</strong>
<input type="hidden" id="add_notification_global" name="global" value="0"/>
</div>')) .
'<div class="form-group row">
<input type="text" id="add_notification_title" class="form-control" name="title" placeholder="' .
get_string('advnotifications_title', 'block_advnotifications') . '"/>
<textarea id="add_notification_message" class="form-control" name="message" placeholder="' .
get_string('advnotifications_message', 'block_advnotifications') . '"></textarea>
</div>
<div class="form-group row">
<select id="add_notification_type" class="form-control col-7" name="type" required>
<option selected disabled>' .
get_string('advnotifications_type', 'block_advnotifications') .
'</option>
<option value="info">' .
get_string('advnotifications_add_option_info', 'block_advnotifications') .
'</option>
<option value="success">' .
get_string('advnotifications_add_option_success', 'block_advnotifications') .
'</option>
<option value="warning">' .
get_string('advnotifications_add_option_warning', 'block_advnotifications') .
'</option>
<option value="danger">' .
get_string('advnotifications_add_option_danger', 'block_advnotifications') .
'</option>
<option value="announcement">' .
get_string('advnotifications_add_option_announcement', 'block_advnotifications') .
'</option>
</select>
<label for="add_notification_type" class="col">
<strong class="required">*</strong>
</label>
</div>
<div class="form-group row">
<select id="add_notification_times" class="form-control col-7" name="times" required>
<option selected disabled>' .
get_string('advnotifications_times', 'block_advnotifications') . '</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<label for="add_notification_times" class="col">
<strong class="required col">*</strong>
</label>
<small class="form-text text-muted">' .
get_string('advnotifications_times_label', 'block_advnotifications') . '</small>
</div>
<div class="form-group">
<div class="form-check">
<input type="checkbox" id="add_notification_aicon" class="form-check-input" name="aicon"/>
<label for="add_notification_aicon" class="form-check-label">' .
get_string('advnotifications_aicon', 'block_advnotifications') . '</label>
</div>
<div class="form-check">
<input type="checkbox"
id="add_notification_dismissible"
class="form-check-input"
name="dismissible"/>
<label for="add_notification_dismissible" class="form-check-label">' .
get_string('advnotifications_dismissible', 'block_advnotifications') . '</label>
</div>
</div>
<div class="form-group">
<label for="add_notification_date_from" class="form-text">' .
get_string('advnotifications_date_from', 'block_advnotifications') . '</label>
<input type="date"
id="add_notification_date_from"
class="form-control"
name="date_from"
placeholder="yyyy-mm-dd"/>
<label for="add_notification_date_to" class="form-text">' .
get_string('advnotifications_date_to', 'block_advnotifications') . '</label>
<input type="date"
id="add_notification_date_to"
class="form-control"
name="date_to"
placeholder="yyyy-mm-dd"/>
<small class="form-text text-muted">' .
get_string('advnotifications_date_info', 'block_advnotifications') . '</small>
</div>
<input type="hidden" id="add_notification_sesskey" name="sesskey" value="' . sesskey() . '"/>
<input type="hidden" id="add_notification_purpose" name="purpose" value="add"/>
<input type="hidden" id="add_notification_blockid" name="blockid" value="' .
(array_key_exists('blockid', $params) ?
$params['blockid'] :
'-1') . '"/>
<div class="form-group">
<input type="submit"
id="add_notification_save"
class="btn btn-primary"
role="button"
name="save"
value="' . get_string('advnotifications_save', 'block_advnotifications') . '"/>
<a href="' . $CFG->wwwroot . '/blocks/advnotifications/pages/notifications.php"
id="add_notification_cancel" class="btn btn-danger">' .
get_string('advnotifications_cancel', 'block_advnotifications') . '</a>
</div>
<div id="add_notification_status">
<div class="signal"></div>
<div class="saving">' .
get_string('advnotifications_add_saving', 'block_advnotifications') .
'</div>
<div class="done" style="display: none;">' .
get_string('advnotifications_add_done', 'block_advnotifications') .
'</div>
</div>
</form>
</div>
</div>';
return $html;
}
}