Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin: Refactor BBB to use new conference tables - refs #6153 #6161

Merged
merged 8 commits into from
Mar 25, 2025
4 changes: 4 additions & 0 deletions public/plugin/bbb/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
}
}

if (!isset($meeting['participants'])) {
$meeting['participants'] = [];
}

if ($action) {
switch ($action) {
case 'export':
Expand Down
35 changes: 19 additions & 16 deletions public/plugin/bbb/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

use Chamilo\CoreBundle\Component\Utils\ActionIcon;
use Chamilo\CoreBundle\Entity\ConferenceMeeting;
use Chamilo\CoreBundle\Repository\ConferenceMeetingRepository;

$course_plugin = 'bbb'; //needed in order to load the plugin lang variables
$cidReset = true;
Expand All @@ -27,22 +29,23 @@
}

if ($bbb->checkDirectMeetingVideoUrl($meetingId)) {
$meetingInfo = Database::select(
'*',
'plugin_bbb_meeting',
['where' => ['id = ?' => (int) $meetingId]],
'first'
);

$url = $meetingInfo['video_url'].'/capture.m4v';
$link = Display::url(
Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Download file')),
$meetingInfo['video_url'].'/capture.m4v',
['target' => '_blank']
);

header('Content-Type: application/json');
echo json_encode(['url' => $url, 'link' => $link]);
$em = Database::getManager();
/** @var ConferenceMeetingRepository $repo */
$repo = $em->getRepository(ConferenceMeeting::class);

$meetingInfo = $repo->findOneAsArrayById($meetingId);

if ($meetingInfo && isset($meetingInfo['videoUrl'])) {
$url = $meetingInfo['videoUrl'].'/capture.m4v';
$link = Display::url(
Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Download file')),
$url,
['target' => '_blank']
);

header('Content-Type: application/json');
echo json_encode(['url' => $url, 'link' => $link]);
}
}
break;
}
86 changes: 49 additions & 37 deletions public/plugin/bbb/cron_close_meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
/**
* This script initiates a video conference session, calling the BigBlueButton API.
*/

use Chamilo\CoreBundle\Entity\ConferenceActivity;
use Chamilo\CoreBundle\Repository\ConferenceActivityRepository;

$course_plugin = 'bbb'; //needed in order to load the plugin lang variables
require_once __DIR__.'/config.php';

$plugin = BBBPlugin::create();
$meetingTable = Database::get_main_table('plugin_bbb_meeting');
$roomTable = Database::get_main_table('plugin_bbb_room');
/** @var ConferenceActivityRepository $activityRepo */
$em = Database::getManager();
$activityRepo = $em->getRepository(ConferenceActivity::class);

$bbb = new bbb();
if ($bbb->pluginEnabled) {
Expand Down Expand Up @@ -48,50 +53,57 @@
$bbb->endMeeting($value['id'], $courseCode);
break;
case 'SUCCESS':
Database::update(
$roomTable,
['close' => BBBPlugin::ROOM_CHECK],
['meeting_id = ? AND close= ?' => [$meetingId, BBBPlugin::ROOM_OPEN]]
);
$activitiesToMark = $activityRepo->createQueryBuilder('a')
->where('a.meeting = :meetingId')
->andWhere('a.close = :open')
->setParameter('meetingId', $meetingId)
->setParameter('open', BBBPlugin::ROOM_OPEN)
->getQuery()
->getResult();

foreach ($activitiesToMark as $activity) {
$activity->setClose(BBBPlugin::ROOM_CHECK);
}
$em->flush();

$i = 0;
while ($i < $meetingBBB['participantCount']) {
$participantId = $meetingBBB[$i]['userId'];
$roomData = Database::select(
'*',
$roomTable,
[
'where' => [
'meeting_id = ? AND participant_id = ? AND close = ?' => [
$meetingId,
$participantId,
BBBPlugin::ROOM_CHECK,
],
],
'order' => 'id DESC',
],
'first'
);

if (!empty($roomData)) {
$roomId = $roomData['id'];
if (!empty($roomId)) {
Database::update(
$roomTable,
['out_at' => api_get_utc_datetime(), 'close' => BBBPlugin::ROOM_OPEN],
['id = ? ' => $roomId]
);
}

$roomData = $activityRepo->createQueryBuilder('a')
->where('a.meeting = :meetingId')
->andWhere('a.participant = :participantId')
->andWhere('a.close = :check')
->setParameter('meetingId', $meetingId)
->setParameter('participantId', $participantId)
->setParameter('check', BBBPlugin::ROOM_CHECK)
->orderBy('a.id', 'DESC')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();

if ($roomData instanceof ConferenceActivity) {
$roomData->setOutAt(new \DateTime());
$roomData->setClose(BBBPlugin::ROOM_OPEN);
}
$i++;
}
$em->flush();

Database::update(
$roomTable,
['out_at' => api_get_utc_datetime(), 'close' => BBBPlugin::ROOM_CLOSE],
['meeting_id = ? AND close= ?' => [$meetingId, BBBPlugin::ROOM_CHECK]]
);
$activitiesToClose = $activityRepo->createQueryBuilder('a')
->where('a.meeting = :meetingId')
->andWhere('a.close = :check')
->setParameter('meetingId', $meetingId)
->setParameter('check', BBBPlugin::ROOM_CHECK)
->getQuery()
->getResult();

foreach ($activitiesToClose as $activity) {
$activity->setOutAt(new \DateTime());
$activity->setClose(BBBPlugin::ROOM_CLOSE);
}

$em->flush();
break;
}
}
Expand Down
Loading
Loading