Completed
Pull Request — master (#259)
by
unknown
02:07
created

renderer::render_group_element_configmultiselect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 7
loc 7
rs 10
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 onwards, Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 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 onwards, Blindside Networks Inc
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 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 html editor element in a group.
109
     *
110
     * @param string    $name
111
     * @param object    $default
112
     * @param string    $type
113
     *
114
     * @return Object
115
     */
116 View Code Duplication
    public function render_group_element_textarea($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...
117
        $item = new \admin_setting_configtextarea('bigbluebuttonbn_' . $name,
118
                get_string('config_' . $name, 'bigbluebuttonbn'),
119
                get_string('config_' . $name . '_description', 'bigbluebuttonbn'),
120
                $default, $type);
121
        return $item;
122
    }
123
124
    /**
125
     * Render a checkbox element in a group.
126
     *
127
     * @param string    $name
128
     * @param object    $default
129
     *
130
     * @return Object
131
     */
132 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...
133
        $item = new \admin_setting_configcheckbox('bigbluebuttonbn_' . $name,
134
                get_string('config_' . $name, 'bigbluebuttonbn'),
135
                get_string('config_' . $name . '_description', 'bigbluebuttonbn'),
136
                $default);
137
        return $item;
138
    }
139
140
    /**
141
     * Render a multiselect 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_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...
150
        $item = new \admin_setting_configmultiselect('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 select element in a group.
159
     *
160
     * @param string    $name
161
     * @param object    $defaultsetting
162
     * @param object    $choices
163
     *
164
     * @return Object
165
     */
166 View Code Duplication
    public function render_group_element_configselect($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...
167
        $item = new \admin_setting_configselect('bigbluebuttonbn_' . $name,
168
                get_string('config_' . $name, 'bigbluebuttonbn'),
169
                get_string('config_' . $name . '_description', 'bigbluebuttonbn'),
170
                $defaultsetting, $choices);
171
        return $item;
172
    }
173
174
    /**
175
     * Render a general warning message.
176
     *
177
     * @param string    $name
178
     * @param string    $message
179
     * @param string    $type
180
     * @param boolean   $closable
181
     *
182
     * @return Object
183
     */
184
    public function render_warning_message($name, $message, $type = 'warning', $closable = true) {
185
        global $OUTPUT;
186
        $output = $OUTPUT->box_start('box boxalignleft adminerror alert alert-' . $type . ' alert-block fade in',
187
            'bigbluebuttonbn_' . $name)."\n";
188
        if ($closable) {
189
            $output .= '  <button type="button" class="close" data-dismiss="alert">&times;</button>' . "\n";
190
        }
191
        $output .= '  ' . $message . "\n";
192
        $output .= $OUTPUT->box_end() . "\n";
193
        $item = new \admin_setting_heading('bigbluebuttonbn_' . $name, '', $output);
194
        $this->settings->add($item);
195
        return $item;
196
    }
197
198
    /**
199
     * Render a general manage file for use as default presentation.
200
     *
201
     * @param string    $name
202
     *
203
     * @return Object
204
     */
205
    public function render_filemanager_default_file_presentation($name) {
206
207
        $filemanageroptions = array();
208
        $filemanageroptions['accepted_types'] = '*';
209
        $filemanageroptions['maxbytes'] = 0;
210
        $filemanageroptions['subdirs'] = 0;
211
        $filemanageroptions['maxfiles'] = 1;
212
        $filemanageroptions['mainfile'] = true;
213
214
        $filemanager = new \admin_setting_configstoredfile('mod_bigbluebuttonbn/presentationdefault',
215
            get_string('config_' . $name, 'bigbluebuttonbn'),
216
            get_string('config_' . $name . '_description', 'bigbluebuttonbn'),
217
            'presentationdefault',
218
            0,
219
            $filemanageroptions);
220
221
        $this->settings->add($filemanager);
222
        return $filemanager;
223
    }
224
}
225