Completed
Pull Request — master (#45)
by Jesus
02:22
created

renderer::render_warning_message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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 general warning message.
142
     *
143
     * @param string    $message
144
     *
145
     * @return Object
146
     */
147
    public function render_warning_message($message, $type = 'warning') {
148
        global $OUTPUT;
149
        $output = $OUTPUT->box_start('box boxalignleft adminerror alert alert-' . $type . ' alert-block fade in',
150
            'bigbluebuttonbn_view_general_warning')."\n";
151
        $output .= '  <button type="button" class="close" data-dismiss="alert">&times;</button>' . $message . "\n";
152
        $output .= $OUTPUT->box_end() . "\n";
153
        $item = new \admin_setting_heading('bigbluebuttonbn_global_deprecated', '', $output);
154
        $this->settings->add($item);
155
        return $item;
156
    }
157
158
    /**
159
     * Validate if general section will be shown.
160
     *
161
     * @return boolean
162
     */
163
    public static function section_general_shown() {
164
        global $CFG;
165
        return (!isset($CFG->bigbluebuttonbn['server_url']) ||
166
                !isset($CFG->bigbluebuttonbn['shared_secret']));
167
    }
168
169
    /**
170
     * Validate if record meeting section  will be shown.
171
     *
172
     * @return boolean
173
     */
174
    public static function section_record_meeting_shown() {
175
        global $CFG;
176
        return (!isset($CFG->bigbluebuttonbn['recording_default']) ||
177
                !isset($CFG->bigbluebuttonbn['recording_editable']) ||
178
                !isset($CFG->bigbluebuttonbn['recording_icons_enabled']));
179
    }
180
181
    /**
182
     * Validate if import recording section will be shown.
183
     *
184
     * @return boolean
185
     */
186
    public static function section_import_recordings_shown() {
187
        global $CFG;
188
        return (!isset($CFG->bigbluebuttonbn['importrecordings_enabled']) ||
189
                !isset($CFG->bigbluebuttonbn['importrecordings_from_deleted_enabled']));
190
    }
191
192
    /**
193
     * Validate if show recording section will be shown.
194
     *
195
     * @return boolean
196
     */
197
    public static function section_show_recordings_shown() {
198
        global $CFG;
199
        return (!isset($CFG->bigbluebuttonbn['recordings_html_default']) ||
200
                !isset($CFG->bigbluebuttonbn['recordings_html_editable']) ||
201
                !isset($CFG->bigbluebuttonbn['recordings_deleted_default']) ||
202
                !isset($CFG->bigbluebuttonbn['recordings_deleted_editable']) ||
203
                !isset($CFG->bigbluebuttonbn['recordings_imported_default']) ||
204
                !isset($CFG->bigbluebuttonbn['recordings_imported_editable']));
205
    }
206
207
    /**
208
     * Validate if wait moderator section will be shown.
209
     *
210
     * @return boolean
211
     */
212
    public static function section_wait_moderator_shown() {
213
        global $CFG;
214
        return (!isset($CFG->bigbluebuttonbn['waitformoderator_default']) ||
215
                !isset($CFG->bigbluebuttonbn['waitformoderator_editable']) ||
216
                !isset($CFG->bigbluebuttonbn['waitformoderator_ping_interval']) ||
217
                !isset($CFG->bigbluebuttonbn['waitformoderator_cache_ttl']));
218
    }
219
220
    /**
221
     * Validate if static voice bridge section will be shown.
222
     *
223
     * @return boolean
224
     */
225
    public static function section_static_voice_bridge_shown() {
226
        global $CFG;
227
        return (!isset($CFG->bigbluebuttonbn['voicebridge_editable']));
228
    }
229
230
    /**
231
     * Validate if preupload presentation section will be shown.
232
     *
233
     * @return boolean
234
     */
235
    public static function section_preupload_presentation_shown() {
236
        global $CFG;
237
        return (!isset($CFG->bigbluebuttonbn['preuploadpresentation_enabled']));
238
    }
239
240
    /**
241
     * Validate if user limit section will be shown.
242
     *
243
     * @return boolean
244
     */
245
    public static function section_user_limit_shown() {
246
        global $CFG;
247
        return (!isset($CFG->bigbluebuttonbn['userlimit_default']) ||
248
                !isset($CFG->bigbluebuttonbn['userlimit_editable']));
249
    }
250
251
    /**
252
     * Validate if scheduled duration section will be shown.
253
     *
254
     * @return boolean
255
     */
256
    public static function section_scheduled_duration_shown() {
257
        global $CFG;
258
        return (!isset($CFG->bigbluebuttonbn['scheduled_duration_enabled']));
259
    }
260
261
    /**
262
     * Validate if moderator default section will be shown.
263
     *
264
     * @return boolean
265
     */
266
    public static function section_moderator_default_shown() {
267
        global $CFG;
268
        return (!isset($CFG->bigbluebuttonbn['participant_moderator_default']));
269
    }
270
271
    /**
272
     * Validate if send notification section will be shown.
273
     *
274
     * @return boolean
275
     */
276
    public static function section_send_notifications_shown() {
277
        global $CFG;
278
        return (!isset($CFG->bigbluebuttonbn['sendnotifications_enabled']));
279
    }
280
281
    /**
282
     * Validate if settings extended section will be shown.
283
     *
284
     * @return boolean
285
     */
286
    public static function section_settings_extended_shown() {
287
        global $CFG;
288
        return (!isset($CFG->bigbluebuttonbn['recordingready_enabled']) ||
289
                !isset($CFG->bigbluebuttonbn['meetingevents_enabled']));
290
    }
291
}
292