Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions public/main/gradebook/lib/be/category.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2008,8 +2008,8 @@ public function lockAllItems($locked)
*/
public static function generateUserCertificate(
GradebookCategory $category,
int $user_id,
bool $sendNotification = false,
int $user_id,
bool $sendNotification = false,
bool $skipGenerationIfExists = false
) {
$user_id = (int) $user_id;
Expand Down Expand Up @@ -2096,7 +2096,13 @@ public static function generateUserCertificate(
}
}

if (!empty($fileWasGenerated) && !empty($my_certificate['publish'])) {
$isOwner = api_get_user_id() == $user_id;
$isPlatformAdmin = api_is_platform_admin();
$isCourseAdmin = api_is_course_admin($courseId);

$canViewCertificate = $isOwner || $isPlatformAdmin || $isCourseAdmin || !empty($my_certificate['publish']);

if (!empty($fileWasGenerated) && $canViewCertificate) {
$certificates = '';
$exportToPDF = null;
$pdfUrl = null;
Expand Down
5 changes: 3 additions & 2 deletions public/main/inc/ajax/plugin.ajax.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
/* For licensing terms, see /license.txt */

use Chamilo\CoreBundle\Entity\AccessUrlRelPlugin;
use Chamilo\CoreBundle\Framework\Container;
use Michelf\MarkdownExtra;
use Chamilo\CoreBundle\Entity\Plugin;
Expand Down Expand Up @@ -79,6 +78,7 @@
$appPlugin = new AppPlugin();

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

$plugin
Expand All @@ -91,7 +91,8 @@
$plugin->setSource(Plugin::SOURCE_OFFICIAL);
}

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

Expand Down
2 changes: 2 additions & 0 deletions public/plugin/Bbb/lang/english.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@
$strings['RoomClosedComment'] = ' ';
$strings['meeting_duration'] = 'Meeting duration (in minutes)';
$strings['big_blue_button_students_start_conference_in_groups'] = 'Allow students to start conference in their groups.';
$strings['hide_conference_link'] = 'Hide conference link in course tool';
$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.';
39 changes: 26 additions & 13 deletions public/plugin/Bbb/lib/bbb.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,29 +279,42 @@ public function getMaxUsersLimit()
}
$courseLimit = 0;
$sessionLimit = 0;
// Check the extra fields for this course and session
// Session limit takes priority over course limit
// Course limit takes priority over global limit

// Check course extra field
if (!empty($this->courseId)) {
$extraField = new ExtraField('course');
$fieldId = $extraField->get_all(
$fieldIdList = $extraField->get_all(
array('variable = ?' => 'plugin_bbb_course_users_limit')
);
$extraValue = new ExtraFieldValue('course');
$value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId[0]['id']);
if (!empty($value['value'])) {
$courseLimit = (int) $value['value'];

if (!empty($fieldIdList)) {
$fieldId = $fieldIdList[0]['id'] ?? null;
if ($fieldId) {
$extraValue = new ExtraFieldValue('course');
$value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId);
if (!empty($value['value'])) {
$courseLimit = (int) $value['value'];
}
}
}
}

// Check session extra field
if (!empty($this->sessionId)) {
$extraField = new ExtraField('session');
$fieldId = $extraField->get_all(
$fieldIdList = $extraField->get_all(
array('variable = ?' => 'plugin_bbb_session_users_limit')
);
$extraValue = new ExtraFieldValue('session');
$value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId[0]['id']);
if (!empty($value['value'])) {
$sessionLimit = (int) $value['value'];

if (!empty($fieldIdList)) {
$fieldId = $fieldIdList[0]['id'] ?? null;
if ($fieldId) {
$extraValue = new ExtraFieldValue('session');
$value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId);
if (!empty($value['value'])) {
$sessionLimit = (int) $value['value'];
}
}
}
}

Expand Down
112 changes: 112 additions & 0 deletions public/plugin/Bbb/lib/bbb_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

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

use Chamilo\CoreBundle\Entity\AccessUrlRelPlugin;
use Chamilo\CoreBundle\Entity\ConferenceMeeting;
use Chamilo\CoreBundle\Entity\ConferenceRecording;
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CCourseSetting;
use Chamilo\CoreBundle\Entity\Course;

Expand Down Expand Up @@ -63,6 +65,7 @@ protected function __construct()
'disable_course_settings' => 'boolean',
'meeting_duration' => 'text',
'delete_recordings_on_course_delete' => 'boolean',
'hide_conference_link' => 'boolean',
]
);

Expand Down Expand Up @@ -284,6 +287,115 @@ private function deleteRecording(string $recordId): void
@file_get_contents($url);
}

/**
* Installs the plugin
*/
public function install(): void

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function install has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method install has 50 lines of code (exceeds 25 allowed). Consider refactoring.

{
$entityManager = Database::getManager();

$pluginRepo = Container::getPluginRepository();
$plugin = $pluginRepo->findOneByTitle($this->get_name());

if (!$plugin) {
// Create the plugin only if it does not exist
$plugin = new \Chamilo\CoreBundle\Entity\Plugin();
$plugin->setTitle($this->get_name());
$plugin->setInstalled(true);
$plugin->setInstalledVersion($this->get_version());
$plugin->setSource(\Chamilo\CoreBundle\Entity\Plugin::SOURCE_OFFICIAL);

$entityManager->persist($plugin);
$entityManager->flush();
} else {
// Ensure Doctrine manages it in the current UnitOfWork
$plugin = $entityManager->merge($plugin);
}

// Check if the plugin has relations for access URLs
$accessUrlRepo = Container::getAccessUrlRepository();
$accessUrlRelPluginRepo = Container::getAccessUrlRelPluginRepository();

$accessUrls = $accessUrlRepo->findAll();

foreach ($accessUrls as $accessUrl) {
$rel = $accessUrlRelPluginRepo->findOneBy([
'plugin' => $plugin,
'url' => $accessUrl,
]);

if (!$rel) {
$rel = new AccessUrlRelPlugin();
$rel->setPlugin($plugin);
$rel->setUrl($accessUrl);
$rel->setActive(true);

$configuration = [];
foreach ($this->fields as $name => $type) {
$defaultValue = '';

if (is_array($type)) {
$defaultValue = $type['type'] === 'boolean' ? 'false' : '';
} else {
switch ($type) {
case 'boolean':
case 'checkbox':
$defaultValue = 'false';
break;
default:
$defaultValue = '';
break;
}
}

$configuration[$name] = $defaultValue;
}

$rel->setConfiguration($configuration);

$entityManager->persist($rel);
}
}

$entityManager->flush();
}

public function canCurrentUserSeeGlobalConferenceLink(): bool

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method canCurrentUserSeeGlobalConferenceLink has 29 lines of code (exceeds 25 allowed). Consider refactoring.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function canCurrentUserSeeGlobalConferenceLink has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.

{
$allowedStatuses = $this->get('global_conference_allow_roles') ?? [];

if (empty($allowedStatuses)) {
return api_is_platform_admin();
}

foreach ($allowedStatuses as $status) {
switch ((int) $status) {
case PLATFORM_ADMIN:
if (api_is_platform_admin()) {
return true;
}
break;
case COURSEMANAGER:
if (api_is_teacher()) {
return true;
}
break;
case STUDENT:
if (api_is_student()) {
return true;
}
break;
case STUDENT_BOSS:
if (api_is_student_boss()) {
return true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

}
break;
}
}

return false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid too many return statements within this method.

}

public function get_name(): string
{
return 'Bbb';
Expand Down
4 changes: 4 additions & 0 deletions public/plugin/Bbb/listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
require_once __DIR__.'/config.php';

$plugin = BbbPlugin::create();
$canSeeShareableConferenceLink = $plugin->canCurrentUserSeeGlobalConferenceLink();
$tool_name = $plugin->get_lang('Videoconference');
$em = Database::getManager();
$meetingRepository = $em->getRepository(ConferenceMeeting::class);
Expand Down Expand Up @@ -446,6 +447,9 @@
$tpl->assign('message', $message);
$tpl->assign('form', $formToString);
$tpl->assign('enter_conference_links', $urlList);
$tpl->assign('can_see_share_link', $canSeeShareableConferenceLink);
$tpl->assign('plugin', $plugin);
$tpl->assign('is_course_context', api_get_course_int_id() > 0);

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

Expand Down
Loading
Loading