1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | /* To show the plugin course icons you need to add these icons: |
||
6 | * main/img/icons/22/plugin_name.png |
||
7 | * main/img/icons/64/plugin_name.png |
||
8 | * main/img/icons/64/plugin_name_na.png |
||
9 | */ |
||
10 | |||
11 | /** |
||
12 | * Videoconference plugin with BBB |
||
13 | */ |
||
14 | class BBBPlugin extends Plugin |
||
15 | { |
||
16 | const ROOM_OPEN = 0; |
||
17 | const ROOM_CLOSE = 1; |
||
18 | const ROOM_CHECK = 2; |
||
19 | |||
20 | public $isCoursePlugin = true; |
||
21 | |||
22 | // When creating a new course this settings are added to the course |
||
23 | public $course_settings = [ |
||
24 | [ |
||
25 | 'name' => 'big_blue_button_record_and_store', |
||
26 | 'type' => 'checkbox', |
||
27 | ], |
||
28 | [ |
||
29 | 'name' => 'bbb_enable_conference_in_groups', |
||
30 | 'type' => 'checkbox', |
||
31 | ], |
||
32 | [ |
||
33 | 'name' => 'bbb_force_record_generation', |
||
34 | 'type' => 'checkbox', |
||
35 | ], |
||
36 | [ |
||
37 | 'name' => 'big_blue_button_students_start_conference_in_groups', |
||
38 | 'type' => 'checkbox', |
||
39 | ], |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * BBBPlugin constructor. |
||
44 | */ |
||
45 | protected function __construct() |
||
46 | { |
||
47 | parent::__construct( |
||
48 | '2.9', |
||
49 | 'Julio Montoya, Yannick Warnier, Angel Fernando Quiroz Campos, Jose Angel Ruiz', |
||
50 | [ |
||
51 | 'tool_enable' => 'boolean', |
||
52 | 'host' => 'text', |
||
53 | 'salt' => 'text', |
||
54 | 'enable_global_conference' => 'boolean', |
||
55 | 'enable_global_conference_per_user' => 'boolean', |
||
56 | 'enable_conference_in_course_groups' => 'boolean', |
||
57 | 'enable_global_conference_link' => 'boolean', |
||
58 | 'disable_download_conference_link' => 'boolean', |
||
59 | 'max_users_limit' => 'text', |
||
60 | 'global_conference_allow_roles' => [ |
||
61 | 'type' => 'select', |
||
62 | 'options' => [ |
||
63 | PLATFORM_ADMIN => get_lang('Administrator'), |
||
64 | COURSEMANAGER => get_lang('Teacher'), |
||
65 | STUDENT => get_lang('Student'), |
||
66 | STUDENT_BOSS => get_lang('StudentBoss'), |
||
67 | ], |
||
68 | 'attributes' => ['multiple' => 'multiple'], |
||
69 | ], |
||
70 | 'allow_regenerate_recording' => 'boolean', |
||
71 | // Default course settings, must be the same as $course_settings |
||
72 | 'big_blue_button_record_and_store' => 'checkbox', |
||
73 | 'bbb_enable_conference_in_groups' => 'checkbox', |
||
74 | 'bbb_force_record_generation' => 'checkbox', |
||
75 | 'disable_course_settings' => 'boolean', |
||
76 | 'meeting_duration' => 'text', |
||
77 | ] |
||
78 | ); |
||
79 | |||
80 | $this->isAdminPlugin = true; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return BBBPlugin|null |
||
85 | */ |
||
86 | public static function create() |
||
87 | { |
||
88 | static $result = null; |
||
89 | |||
90 | return $result ? $result : $result = new self(); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param string $variable |
||
95 | * |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function validateCourseSetting($variable) |
||
99 | { |
||
100 | if ($this->get('disable_course_settings') === 'true') { |
||
101 | return false; |
||
102 | } |
||
103 | |||
104 | $result = true; |
||
105 | switch ($variable) { |
||
106 | case 'bbb_enable_conference_in_groups': |
||
107 | $result = $this->get('enable_conference_in_course_groups') === 'true'; |
||
108 | break; |
||
109 | case 'bbb_force_record_generation': |
||
110 | $result = $this->get('allow_regenerate_recording') === 'true'; |
||
111 | break; |
||
112 | case 'big_blue_button_record_and_store': |
||
113 | } |
||
114 | |||
115 | return $result; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function getCourseSettings() |
||
123 | { |
||
124 | $settings = []; |
||
125 | if ($this->get('disable_course_settings') !== 'true') { |
||
126 | $settings = parent::getCourseSettings(); |
||
127 | } |
||
128 | |||
129 | return $settings; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * |
||
134 | * @return \Plugin |
||
135 | */ |
||
136 | public function performActionsAfterConfigure() |
||
137 | { |
||
138 | $result = $this->get('disable_course_settings') === 'true'; |
||
139 | if ($result) { |
||
140 | $valueConference = $this->get('bbb_enable_conference_in_groups') === 'true' ? 1 : 0; |
||
141 | self::update_course_field_in_all_courses('bbb_enable_conference_in_groups', $valueConference); |
||
142 | |||
143 | $valueForceRecordGeneration = $this->get('bbb_force_record_generation') === 'true' ? 1 : 0; |
||
144 | self::update_course_field_in_all_courses('bbb_force_record_generation', $valueForceRecordGeneration); |
||
145 | |||
146 | $valueForceRecordStore = $this->get('big_blue_button_record_and_store') === 'true' ? 1 : 0; |
||
147 | self::update_course_field_in_all_courses('big_blue_button_record_and_store', $valueForceRecordStore); |
||
148 | } |
||
149 | |||
150 | return $this; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Install |
||
155 | */ |
||
156 | public function install() |
||
157 | { |
||
158 | $sql = "CREATE TABLE IF NOT EXISTS plugin_bbb_meeting ( |
||
159 | id INT unsigned NOT NULL auto_increment PRIMARY KEY, |
||
160 | c_id INT unsigned NOT NULL DEFAULT 0, |
||
161 | group_id INT unsigned NOT NULL DEFAULT 0, |
||
162 | user_id INT unsigned NOT NULL DEFAULT 0, |
||
163 | meeting_name VARCHAR(255) NOT NULL DEFAULT '', |
||
164 | attendee_pw VARCHAR(255) NOT NULL DEFAULT '', |
||
165 | moderator_pw VARCHAR(255) NOT NULL DEFAULT '', |
||
166 | record INT NOT NULL DEFAULT 0, |
||
167 | status INT NOT NULL DEFAULT 0, |
||
168 | created_at VARCHAR(255) NOT NULL, |
||
169 | closed_at VARCHAR(255) NOT NULL, |
||
170 | calendar_id INT DEFAULT 0, |
||
171 | welcome_msg VARCHAR(255) NOT NULL DEFAULT '', |
||
172 | session_id INT unsigned DEFAULT 0, |
||
173 | remote_id CHAR(30), |
||
174 | internal_meeting_id VARCHAR(255) DEFAULT NULL, |
||
175 | visibility TINYINT NOT NULL DEFAULT 1, |
||
176 | voice_bridge INT NOT NULL DEFAULT 1, |
||
177 | access_url INT NOT NULL DEFAULT 1, |
||
178 | video_url TEXT NULL, |
||
179 | has_video_m4v TINYINT NOT NULL DEFAULT 0 |
||
180 | )"; |
||
181 | Database::query($sql); |
||
182 | |||
183 | Database::query( |
||
184 | "CREATE TABLE IF NOT EXISTS plugin_bbb_room ( |
||
185 | id int NOT NULL AUTO_INCREMENT PRIMARY KEY, |
||
186 | meeting_id int NOT NULL, |
||
187 | participant_id int(11) NOT NULL, |
||
188 | in_at datetime, |
||
189 | out_at datetime, |
||
190 | close INT NOT NULL DEFAULT 0 |
||
191 | );" |
||
192 | ); |
||
193 | $fieldLabel = 'plugin_bbb_course_users_limit'; |
||
194 | $fieldType = ExtraField::FIELD_TYPE_INTEGER; |
||
195 | $fieldTitle = $this->get_lang('MaxUsersInConferenceRoom'); |
||
196 | $fieldDefault = '0'; |
||
197 | $extraField = new ExtraField('course'); |
||
198 | $fieldId = CourseManager::create_course_extra_field( |
||
199 | $fieldLabel, |
||
200 | $fieldType, |
||
201 | $fieldTitle, |
||
202 | $fieldDefault |
||
203 | ); |
||
204 | $extraField->find($fieldId); |
||
205 | $extraField->update( |
||
206 | [ |
||
207 | 'id' => $fieldId, |
||
208 | 'variable' => 'plugin_bbb_course_users_limit', |
||
209 | 'changeable' => 1, |
||
210 | 'visible_to_self' => 1, |
||
211 | 'visible_to_others' => 0, |
||
212 | ] |
||
213 | ); |
||
214 | $fieldLabel = 'plugin_bbb_session_users_limit'; |
||
215 | $extraField = new ExtraField('session'); |
||
216 | $fieldId = SessionManager::create_session_extra_field( |
||
217 | $fieldLabel, |
||
218 | $fieldType, |
||
219 | $fieldTitle, |
||
220 | $fieldDefault |
||
221 | ); |
||
222 | $extraField->find($fieldId); |
||
223 | $extraField->update( |
||
224 | [ |
||
225 | 'id' => $fieldId, |
||
226 | 'variable' => 'plugin_bbb_session_users_limit', |
||
227 | 'changeable' => 1, |
||
228 | 'visible_to_self' => 1, |
||
229 | 'visible_to_others' => 0, |
||
230 | ] |
||
231 | ); |
||
232 | |||
233 | // Copy icons into the main/img/icons folder |
||
234 | $iconName = 'bigbluebutton'; |
||
235 | $iconsList = [ |
||
236 | '64/'.$iconName.'.png', |
||
237 | '64/'.$iconName.'_na.png', |
||
238 | '32/'.$iconName.'.png', |
||
239 | '32/'.$iconName.'_na.png', |
||
240 | '22/'.$iconName.'.png', |
||
241 | '22/'.$iconName.'_na.png', |
||
242 | ]; |
||
243 | $sourceDir = api_get_path(SYS_PLUGIN_PATH).'bbb/resources/img/'; |
||
244 | $destinationDir = api_get_path(SYS_CODE_PATH).'img/icons/'; |
||
245 | foreach ($iconsList as $icon) { |
||
246 | $src = $sourceDir.$icon; |
||
247 | $dest = $destinationDir.$icon; |
||
248 | copy($src, $dest); |
||
249 | } |
||
250 | // Installing course settings |
||
251 | $this->install_course_fields_in_all_courses(true, 'bigbluebutton.png'); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * Uninstall |
||
256 | */ |
||
257 | public function uninstall() |
||
258 | { |
||
259 | $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); |
||
260 | $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS); |
||
261 | $t_tool = Database::get_course_table(TABLE_TOOL_LIST); |
||
262 | |||
263 | $variables = [ |
||
264 | 'bbb_salt', |
||
265 | 'bbb_host', |
||
266 | 'bbb_tool_enable', |
||
267 | 'enable_global_conference', |
||
268 | 'enable_global_conference_per_user', |
||
269 | 'enable_global_conference_link', |
||
270 | 'disable_download_conference_link', |
||
271 | 'enable_conference_in_course_groups', |
||
272 | 'bbb_plugin', |
||
273 | 'bbb_plugin_host', |
||
274 | 'bbb_plugin_salt', |
||
275 | 'max_users_limit', |
||
276 | 'global_conference_allow_roles' |
||
277 | ]; |
||
278 | |||
279 | $urlId = api_get_current_access_url_id(); |
||
280 | |||
281 | foreach ($variables as $variable) { |
||
282 | $sql = "DELETE FROM $t_settings WHERE variable = '$variable' AND access_url = $urlId"; |
||
283 | Database::query($sql); |
||
284 | } |
||
285 | |||
286 | $em = Database::getManager(); |
||
287 | $sm = $em->getConnection()->getSchemaManager(); |
||
288 | if ($sm->tablesExist('plugin_bbb_meeting')) { |
||
289 | Database::query("DELETE FROM plugin_bbb_meeting WHERE access_url = $urlId"); |
||
290 | } |
||
291 | |||
292 | // Only delete tables if it's uninstalled from main url. |
||
293 | if (1 == $urlId) { |
||
294 | $extraField = new ExtraField('course'); |
||
295 | $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable( |
||
296 | 'plugin_bbb_course_users_limit' |
||
297 | ); |
||
298 | if (!empty($extraFieldInfo)) { |
||
299 | $extraField->delete($extraFieldInfo['id']); |
||
300 | } |
||
301 | $extraField = new ExtraField('session'); |
||
302 | $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable( |
||
303 | 'plugin_bbb_session_users_limit' |
||
304 | ); |
||
305 | if (!empty($extraFieldInfo)) { |
||
306 | $extraField->delete($extraFieldInfo['id']); |
||
307 | } |
||
308 | |||
309 | $sql = "DELETE FROM $t_options WHERE variable = 'bbb_plugin'"; |
||
310 | Database::query($sql); |
||
311 | |||
312 | // hack to get rid of Database::query warning (please add c_id...) |
||
313 | $sql = "DELETE FROM $t_tool WHERE name = 'bbb' AND c_id != 0"; |
||
314 | Database::query($sql); |
||
315 | |||
316 | if ($sm->tablesExist('plugin_bbb_room')) { |
||
317 | Database::query('DROP TABLE IF EXISTS plugin_bbb_room'); |
||
318 | } |
||
319 | if ($sm->tablesExist('plugin_bbb_meeting')) { |
||
320 | Database::query('DROP TABLE IF EXISTS plugin_bbb_meeting'); |
||
321 | } |
||
322 | |||
323 | // Deleting course settings |
||
324 | $this->uninstall_course_fields_in_all_courses($this->course_settings); |
||
325 | |||
326 | // Remove icons from the main/img/icons folder |
||
327 | $iconName = 'bigbluebutton'; |
||
328 | $iconsList = [ |
||
329 | '64/'.$iconName.'.png', |
||
330 | '64/'.$iconName.'_na.png', |
||
331 | '32/'.$iconName.'.png', |
||
332 | '32/'.$iconName.'_na.png', |
||
333 | '22/'.$iconName.'.png', |
||
334 | '22/'.$iconName.'_na.png', |
||
335 | ]; |
||
336 | $destinationDir = api_get_path(SYS_CODE_PATH).'img/icons/'; |
||
337 | foreach ($iconsList as $icon) { |
||
338 | $dest = $destinationDir.$icon; |
||
339 | if (is_file($dest)) { |
||
340 | @unlink($dest); |
||
341 | } |
||
342 | } |
||
343 | } |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * Update |
||
348 | */ |
||
349 | public function update() |
||
350 | { |
||
351 | $sql = "SHOW COLUMNS FROM plugin_bbb_room WHERE Field = 'close'"; |
||
352 | $res = Database::query($sql); |
||
353 | |||
354 | if (Database::num_rows($res) === 0) { |
||
355 | $sql = "ALTER TABLE plugin_bbb_room ADD close int unsigned NULL"; |
||
356 | $res = Database::query($sql); |
||
357 | if (!$res) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
358 | echo Display::return_message($this->get_lang('ErrorUpdateFieldDB'), 'warning'); |
||
359 | } |
||
360 | |||
361 | Database::update( |
||
362 | 'plugin_bbb_room', |
||
363 | ['close' => BBBPlugin::ROOM_CLOSE] |
||
364 | ); |
||
365 | } |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Set the course setting in all courses |
||
370 | * |
||
371 | * @param bool $variable Course setting to update |
||
372 | * @param bool $value New values of the course setting |
||
373 | */ |
||
374 | public function update_course_field_in_all_courses($variable, $value) |
||
375 | { |
||
376 | // Update existing courses to add the new course setting value |
||
377 | $table = Database::get_main_table(TABLE_MAIN_COURSE); |
||
378 | $sql = "SELECT id FROM $table ORDER BY id"; |
||
379 | $res = Database::query($sql); |
||
380 | $courseSettingTable = Database::get_course_table(TABLE_COURSE_SETTING); |
||
381 | while ($row = Database::fetch_assoc($res)) { |
||
382 | Database::update( |
||
383 | $courseSettingTable, |
||
384 | ['value' => $value], |
||
385 | ['variable = ? AND c_id = ?' => [$variable, $row['id']]] |
||
386 | ); |
||
387 | } |
||
388 | } |
||
389 | } |
||
390 |