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
|
|
|
* The mod_bigbluebuttonbn settings/renderer. |
19
|
|
|
* |
20
|
|
|
* @package mod_bigbluebuttonbn |
21
|
|
|
* @copyright 2010-2017 Blindside Networks Inc |
22
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later |
23
|
|
|
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace mod_bigbluebuttonbn\settings; |
27
|
|
|
|
28
|
|
|
defined('MOODLE_INTERNAL') || die(); |
29
|
|
|
|
30
|
|
|
require_once($CFG->dirroot . '/mod/bigbluebuttonbn/locallib.php'); |
31
|
|
|
require_once($CFG->libdir.'/adminlib.php'); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Helper class for rendering HTML for settings.php. |
35
|
|
|
* |
36
|
|
|
* @copyright 2010-2017 Blindside Networks Inc |
37
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later |
38
|
|
|
*/ |
39
|
|
|
class renderer { |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var $settings stores the settings as they come from settings.php |
43
|
|
|
*/ |
44
|
|
|
private $settings; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor. |
48
|
|
|
* |
49
|
|
|
* @param object $settings |
50
|
|
|
*/ |
51
|
|
|
public function __construct(&$settings) { |
52
|
|
|
$this->settings = $settings; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Render the header for a group. |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* @param string $itemname |
60
|
|
|
* @param string $itemdescription |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function render_group_header($name, $itemname = null, $itemdescription = null) { |
65
|
|
|
if ($itemname === null) { |
66
|
|
|
$itemname = get_string('config_' . $name, 'bigbluebuttonbn'); |
67
|
|
|
} |
68
|
|
|
if ($itemdescription === null) { |
69
|
|
|
$itemdescription = get_string('config_' .$name . '_description', 'bigbluebuttonbn'); |
70
|
|
|
} |
71
|
|
|
$item = new \admin_setting_heading('bigbluebuttonbn_config_' . $name, $itemname, $itemdescription); |
72
|
|
|
$this->settings->add($item); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Render an element in a group. |
77
|
|
|
* |
78
|
|
|
* @param string $name |
79
|
|
|
* @param object $item |
80
|
|
|
* |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function render_group_element($name, $item) { |
84
|
|
|
global $CFG; |
85
|
|
|
if (!isset($CFG->bigbluebuttonbn[$name])) { |
86
|
|
|
$this->settings->add($item); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Render a text element in a group. |
92
|
|
|
* |
93
|
|
|
* @param string $name |
94
|
|
|
* @param object $default |
95
|
|
|
* @param string $type |
96
|
|
|
* |
97
|
|
|
* @return Object |
98
|
|
|
*/ |
99
|
|
View Code Duplication |
public function render_group_element_text($name, $default = null, $type = PARAM_RAW) { |
|
|
|
|
100
|
|
|
$item = new \admin_setting_configtext('bigbluebuttonbn_' . $name, |
101
|
|
|
get_string('config_' . $name, 'bigbluebuttonbn'), |
102
|
|
|
get_string('config_' . $name . '_description', 'bigbluebuttonbn'), |
103
|
|
|
$default, $type); |
104
|
|
|
return $item; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Render a checkbox element in a group. |
109
|
|
|
* |
110
|
|
|
* @param string $name |
111
|
|
|
* @param object $default |
112
|
|
|
* |
113
|
|
|
* @return Object |
114
|
|
|
*/ |
115
|
|
View Code Duplication |
public function render_group_element_checkbox($name, $default = null) { |
|
|
|
|
116
|
|
|
$item = new \admin_setting_configcheckbox('bigbluebuttonbn_' . $name, |
117
|
|
|
get_string('config_' . $name, 'bigbluebuttonbn'), |
118
|
|
|
get_string('config_' . $name . '_description', 'bigbluebuttonbn'), |
119
|
|
|
$default); |
120
|
|
|
return $item; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Render a multiselect element in a group. |
125
|
|
|
* |
126
|
|
|
* @param string $name |
127
|
|
|
* @param object $defaultsetting |
128
|
|
|
* @param object $choices |
129
|
|
|
* |
130
|
|
|
* @return Object |
131
|
|
|
*/ |
132
|
|
View Code Duplication |
public function render_group_element_configmultiselect($name, $defaultsetting, $choices) { |
|
|
|
|
133
|
|
|
$item = new \admin_setting_configmultiselect('bigbluebuttonbn_' . $name, |
134
|
|
|
get_string('config_' . $name, 'bigbluebuttonbn'), |
135
|
|
|
get_string('config_' . $name . '_description', 'bigbluebuttonbn'), |
136
|
|
|
$defaultsetting, $choices); |
137
|
|
|
return $item; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Render a select element in a group. |
142
|
|
|
* |
143
|
|
|
* @param string $name |
144
|
|
|
* @param object $defaultsetting |
145
|
|
|
* @param object $choices |
146
|
|
|
* |
147
|
|
|
* @return Object |
148
|
|
|
*/ |
149
|
|
View Code Duplication |
public function render_group_element_configselect($name, $defaultsetting, $choices) { |
|
|
|
|
150
|
|
|
$item = new \admin_setting_configselect('bigbluebuttonbn_' . $name, |
151
|
|
|
get_string('config_' . $name, 'bigbluebuttonbn'), |
152
|
|
|
get_string('config_' . $name . '_description', 'bigbluebuttonbn'), |
153
|
|
|
$defaultsetting, $choices); |
154
|
|
|
return $item; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Render a general warning message. |
159
|
|
|
* |
160
|
|
|
* @param string $name |
161
|
|
|
* @param string $message |
162
|
|
|
* @param string $type |
163
|
|
|
* @param boolean $closable |
164
|
|
|
* |
165
|
|
|
* @return Object |
166
|
|
|
*/ |
167
|
|
|
public function render_warning_message($name, $message, $type = 'warning', $closable = true) { |
168
|
|
|
global $OUTPUT; |
169
|
|
|
$output = $OUTPUT->box_start('box boxalignleft adminerror alert alert-' . $type . ' alert-block fade in', |
170
|
|
|
'bigbluebuttonbn_' . $name)."\n"; |
171
|
|
|
if ($closable) { |
172
|
|
|
$output .= ' <button type="button" class="close" data-dismiss="alert">×</button>' . "\n"; |
173
|
|
|
} |
174
|
|
|
$output .= ' ' . $message . "\n"; |
175
|
|
|
$output .= $OUTPUT->box_end() . "\n"; |
176
|
|
|
$item = new \admin_setting_heading('bigbluebuttonbn_' . $name, '', $output); |
177
|
|
|
$this->settings->add($item); |
178
|
|
|
return $item; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Validate if general section will be shown. |
183
|
|
|
* |
184
|
|
|
* @return boolean |
185
|
|
|
*/ |
186
|
|
|
public static function section_general_shown() { |
187
|
|
|
global $CFG; |
188
|
|
|
return (!isset($CFG->bigbluebuttonbn['server_url']) || |
189
|
|
|
!isset($CFG->bigbluebuttonbn['shared_secret'])); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Validate if record meeting section will be shown. |
194
|
|
|
* |
195
|
|
|
* @return boolean |
196
|
|
|
*/ |
197
|
|
|
public static function section_record_meeting_shown() { |
198
|
|
|
global $CFG; |
199
|
|
|
return (!isset($CFG->bigbluebuttonbn['recording_default']) || |
200
|
|
|
!isset($CFG->bigbluebuttonbn['recording_editable']) || |
201
|
|
|
!isset($CFG->bigbluebuttonbn['recording_icons_enabled'])); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Validate if import recording section will be shown. |
206
|
|
|
* |
207
|
|
|
* @return boolean |
208
|
|
|
*/ |
209
|
|
|
public static function section_import_recordings_shown() { |
210
|
|
|
global $CFG; |
211
|
|
|
return (!isset($CFG->bigbluebuttonbn['importrecordings_enabled']) || |
212
|
|
|
!isset($CFG->bigbluebuttonbn['importrecordings_from_deleted_enabled'])); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Validate if show recording section will be shown. |
217
|
|
|
* |
218
|
|
|
* @return boolean |
219
|
|
|
*/ |
220
|
|
|
public static function section_show_recordings_shown() { |
221
|
|
|
global $CFG; |
222
|
|
|
return (!isset($CFG->bigbluebuttonbn['recordings_html_default']) || |
223
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_html_editable']) || |
224
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_deleted_default']) || |
225
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_deleted_editable']) || |
226
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_imported_default']) || |
227
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_imported_editable']) || |
228
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_preview_default']) || |
229
|
|
|
!isset($CFG->bigbluebuttonbn['recordings_preview_editable']) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Validate if wait moderator section will be shown. |
235
|
|
|
* |
236
|
|
|
* @return boolean |
237
|
|
|
*/ |
238
|
|
|
public static function section_wait_moderator_shown() { |
239
|
|
|
global $CFG; |
240
|
|
|
return (!isset($CFG->bigbluebuttonbn['waitformoderator_default']) || |
241
|
|
|
!isset($CFG->bigbluebuttonbn['waitformoderator_editable']) || |
242
|
|
|
!isset($CFG->bigbluebuttonbn['waitformoderator_ping_interval']) || |
243
|
|
|
!isset($CFG->bigbluebuttonbn['waitformoderator_cache_ttl'])); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Validate if static voice bridge section will be shown. |
248
|
|
|
* |
249
|
|
|
* @return boolean |
250
|
|
|
*/ |
251
|
|
|
public static function section_static_voice_bridge_shown() { |
252
|
|
|
global $CFG; |
253
|
|
|
return (!isset($CFG->bigbluebuttonbn['voicebridge_editable'])); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Validate if preupload presentation section will be shown. |
258
|
|
|
* |
259
|
|
|
* @return boolean |
260
|
|
|
*/ |
261
|
|
|
public static function section_preupload_presentation_shown() { |
262
|
|
|
global $CFG; |
263
|
|
|
return (!isset($CFG->bigbluebuttonbn['preuploadpresentation_enabled'])); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Validate if user limit section will be shown. |
268
|
|
|
* |
269
|
|
|
* @return boolean |
270
|
|
|
*/ |
271
|
|
|
public static function section_user_limit_shown() { |
272
|
|
|
global $CFG; |
273
|
|
|
return (!isset($CFG->bigbluebuttonbn['userlimit_default']) || |
274
|
|
|
!isset($CFG->bigbluebuttonbn['userlimit_editable'])); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Validate if scheduled duration section will be shown. |
279
|
|
|
* |
280
|
|
|
* @return boolean |
281
|
|
|
*/ |
282
|
|
|
public static function section_scheduled_duration_shown() { |
283
|
|
|
global $CFG; |
284
|
|
|
return (!isset($CFG->bigbluebuttonbn['scheduled_duration_enabled'])); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Validate if moderator default section will be shown. |
289
|
|
|
* |
290
|
|
|
* @return boolean |
291
|
|
|
*/ |
292
|
|
|
public static function section_moderator_default_shown() { |
293
|
|
|
global $CFG; |
294
|
|
|
return (!isset($CFG->bigbluebuttonbn['participant_moderator_default'])); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Validate if send notification section will be shown. |
299
|
|
|
* |
300
|
|
|
* @return boolean |
301
|
|
|
*/ |
302
|
|
|
public static function section_send_notifications_shown() { |
303
|
|
|
global $CFG; |
304
|
|
|
return (!isset($CFG->bigbluebuttonbn['sendnotifications_enabled'])); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Validate if clienttype section will be shown. |
309
|
|
|
* |
310
|
|
|
* @return boolean |
311
|
|
|
*/ |
312
|
|
|
public static function section_clienttype_shown() { |
313
|
|
|
global $CFG; |
314
|
|
|
if (!isset($CFG->bigbluebuttonbn['clienttype_enabled']) || |
315
|
|
|
!$CFG->bigbluebuttonbn['clienttype_enabled']) { |
316
|
|
|
return false; |
317
|
|
|
} |
318
|
|
|
if (!bigbluebuttonbn_has_html5_client()) { |
319
|
|
|
return false; |
320
|
|
|
} |
321
|
|
|
return (!isset($CFG->bigbluebuttonbn['clienttype_default']) || |
322
|
|
|
!isset($CFG->bigbluebuttonbn['clienttype_editable'])); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Validate if settings extended section will be shown. |
327
|
|
|
* |
328
|
|
|
* @return boolean |
329
|
|
|
*/ |
330
|
|
|
public static function section_settings_extended_shown() { |
331
|
|
|
global $CFG; |
332
|
|
|
return (!isset($CFG->bigbluebuttonbn['recordingready_enabled']) || |
333
|
|
|
!isset($CFG->bigbluebuttonbn['meetingevents_enabled'])); |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.