Skip to content

Commit 55adc1c

Browse files
Plugin: Bbb: setting to hide conference link in course context + Add config-based control for global conference visibility by role - refs #3498
Author: @christianbeeznest
1 parent 702f24c commit 55adc1c

File tree

7 files changed

+252
-99
lines changed

7 files changed

+252
-99
lines changed

public/main/inc/ajax/plugin.ajax.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
/* For licensing terms, see /license.txt */
33

4-
use Chamilo\CoreBundle\Entity\AccessUrlRelPlugin;
54
use Chamilo\CoreBundle\Framework\Container;
65
use Michelf\MarkdownExtra;
76
use Chamilo\CoreBundle\Entity\Plugin;
@@ -79,6 +78,7 @@
7978
$appPlugin = new AppPlugin();
8079

8180
if ($action === 'install') {
81+
// Call the install logic inside the plugin itself.
8282
$appPlugin->install($pluginTitle);
8383

8484
$plugin
@@ -91,7 +91,8 @@
9191
$plugin->setSource(Plugin::SOURCE_OFFICIAL);
9292
}
9393

94-
$em->persist($plugin);
94+
// ✅ Removed: persist($plugin) here
95+
// The install() method of the plugin handles persistence already.
9596
} elseif ($plugin && $action === 'uninstall') {
9697
$appPlugin->uninstall($pluginTitle);
9798

public/plugin/Bbb/lang/english.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@
7474
$strings['RoomClosedComment'] = ' ';
7575
$strings['meeting_duration'] = 'Meeting duration (in minutes)';
7676
$strings['big_blue_button_students_start_conference_in_groups'] = 'Allow students to start conference in their groups.';
77+
$strings['hide_conference_link'] = 'Hide conference link in course tool';
78+
$strings['hide_conference_link_comment'] = 'Show or hide a block with a link to the videoconference next to the join button, to allow users to copy it and paste it in another browser window or invite others. Authentication will still be necessary to access non-public conferences.';

public/plugin/Bbb/lib/bbb.lib.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,29 +279,42 @@ public function getMaxUsersLimit()
279279
}
280280
$courseLimit = 0;
281281
$sessionLimit = 0;
282-
// Check the extra fields for this course and session
283-
// Session limit takes priority over course limit
284-
// Course limit takes priority over global limit
282+
283+
// Check course extra field
285284
if (!empty($this->courseId)) {
286285
$extraField = new ExtraField('course');
287-
$fieldId = $extraField->get_all(
286+
$fieldIdList = $extraField->get_all(
288287
array('variable = ?' => 'plugin_bbb_course_users_limit')
289288
);
290-
$extraValue = new ExtraFieldValue('course');
291-
$value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId[0]['id']);
292-
if (!empty($value['value'])) {
293-
$courseLimit = (int) $value['value'];
289+
290+
if (!empty($fieldIdList)) {
291+
$fieldId = $fieldIdList[0]['id'] ?? null;
292+
if ($fieldId) {
293+
$extraValue = new ExtraFieldValue('course');
294+
$value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId);
295+
if (!empty($value['value'])) {
296+
$courseLimit = (int) $value['value'];
297+
}
298+
}
294299
}
295300
}
301+
302+
// Check session extra field
296303
if (!empty($this->sessionId)) {
297304
$extraField = new ExtraField('session');
298-
$fieldId = $extraField->get_all(
305+
$fieldIdList = $extraField->get_all(
299306
array('variable = ?' => 'plugin_bbb_session_users_limit')
300307
);
301-
$extraValue = new ExtraFieldValue('session');
302-
$value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId[0]['id']);
303-
if (!empty($value['value'])) {
304-
$sessionLimit = (int) $value['value'];
308+
309+
if (!empty($fieldIdList)) {
310+
$fieldId = $fieldIdList[0]['id'] ?? null;
311+
if ($fieldId) {
312+
$extraValue = new ExtraFieldValue('session');
313+
$value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId);
314+
if (!empty($value['value'])) {
315+
$sessionLimit = (int) $value['value'];
316+
}
317+
}
305318
}
306319
}
307320

public/plugin/Bbb/lib/bbb_plugin.class.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
/* For licensing terms, see /license.txt */
44

5+
use Chamilo\CoreBundle\Entity\AccessUrlRelPlugin;
56
use Chamilo\CoreBundle\Entity\ConferenceMeeting;
67
use Chamilo\CoreBundle\Entity\ConferenceRecording;
8+
use Chamilo\CoreBundle\Framework\Container;
79
use Chamilo\CourseBundle\Entity\CCourseSetting;
810
use Chamilo\CoreBundle\Entity\Course;
911

@@ -63,6 +65,7 @@ protected function __construct()
6365
'disable_course_settings' => 'boolean',
6466
'meeting_duration' => 'text',
6567
'delete_recordings_on_course_delete' => 'boolean',
68+
'hide_conference_link' => 'boolean',
6669
]
6770
);
6871

@@ -284,6 +287,115 @@ private function deleteRecording(string $recordId): void
284287
@file_get_contents($url);
285288
}
286289

290+
/**
291+
* Installs the plugin
292+
*/
293+
public function install(): void
294+
{
295+
$entityManager = Database::getManager();
296+
297+
$pluginRepo = Container::getPluginRepository();
298+
$plugin = $pluginRepo->findOneByTitle($this->get_name());
299+
300+
if (!$plugin) {
301+
// Create the plugin only if it does not exist
302+
$plugin = new \Chamilo\CoreBundle\Entity\Plugin();
303+
$plugin->setTitle($this->get_name());
304+
$plugin->setInstalled(true);
305+
$plugin->setInstalledVersion($this->get_version());
306+
$plugin->setSource(\Chamilo\CoreBundle\Entity\Plugin::SOURCE_OFFICIAL);
307+
308+
$entityManager->persist($plugin);
309+
$entityManager->flush();
310+
} else {
311+
// Ensure Doctrine manages it in the current UnitOfWork
312+
$plugin = $entityManager->merge($plugin);
313+
}
314+
315+
// Check if the plugin has relations for access URLs
316+
$accessUrlRepo = Container::getAccessUrlRepository();
317+
$accessUrlRelPluginRepo = Container::getAccessUrlRelPluginRepository();
318+
319+
$accessUrls = $accessUrlRepo->findAll();
320+
321+
foreach ($accessUrls as $accessUrl) {
322+
$rel = $accessUrlRelPluginRepo->findOneBy([
323+
'plugin' => $plugin,
324+
'url' => $accessUrl,
325+
]);
326+
327+
if (!$rel) {
328+
$rel = new AccessUrlRelPlugin();
329+
$rel->setPlugin($plugin);
330+
$rel->setUrl($accessUrl);
331+
$rel->setActive(true);
332+
333+
$configuration = [];
334+
foreach ($this->fields as $name => $type) {
335+
$defaultValue = '';
336+
337+
if (is_array($type)) {
338+
$defaultValue = $type['type'] === 'boolean' ? 'false' : '';
339+
} else {
340+
switch ($type) {
341+
case 'boolean':
342+
case 'checkbox':
343+
$defaultValue = 'false';
344+
break;
345+
default:
346+
$defaultValue = '';
347+
break;
348+
}
349+
}
350+
351+
$configuration[$name] = $defaultValue;
352+
}
353+
354+
$rel->setConfiguration($configuration);
355+
356+
$entityManager->persist($rel);
357+
}
358+
}
359+
360+
$entityManager->flush();
361+
}
362+
363+
public function canCurrentUserSeeGlobalConferenceLink(): bool
364+
{
365+
$allowedStatuses = $this->get('global_conference_allow_roles') ?? [];
366+
367+
if (empty($allowedStatuses)) {
368+
return api_is_platform_admin();
369+
}
370+
371+
foreach ($allowedStatuses as $status) {
372+
switch ((int) $status) {
373+
case PLATFORM_ADMIN:
374+
if (api_is_platform_admin()) {
375+
return true;
376+
}
377+
break;
378+
case COURSEMANAGER:
379+
if (api_is_teacher()) {
380+
return true;
381+
}
382+
break;
383+
case STUDENT:
384+
if (api_is_student()) {
385+
return true;
386+
}
387+
break;
388+
case STUDENT_BOSS:
389+
if (api_is_student_boss()) {
390+
return true;
391+
}
392+
break;
393+
}
394+
}
395+
396+
return false;
397+
}
398+
287399
public function get_name(): string
288400
{
289401
return 'Bbb';

public/plugin/Bbb/listing.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require_once __DIR__.'/config.php';
2121

2222
$plugin = BbbPlugin::create();
23+
$canSeeShareableConferenceLink = $plugin->canCurrentUserSeeGlobalConferenceLink();
2324
$tool_name = $plugin->get_lang('Videoconference');
2425
$em = Database::getManager();
2526
$meetingRepository = $em->getRepository(ConferenceMeeting::class);
@@ -446,6 +447,9 @@
446447
$tpl->assign('message', $message);
447448
$tpl->assign('form', $formToString);
448449
$tpl->assign('enter_conference_links', $urlList);
450+
$tpl->assign('can_see_share_link', $canSeeShareableConferenceLink);
451+
$tpl->assign('plugin', $plugin);
452+
$tpl->assign('is_course_context', api_get_course_int_id() > 0);
449453

450454
$content = $tpl->fetch('Bbb/view/listing.tpl');
451455

0 commit comments

Comments
 (0)