Skip to content

Commit 7614239

Browse files
Merge pull request #6161 from christianbeeznest/GH-6153
Plugin: Refactor BBB to use new conference tables - refs #6153
2 parents 228bb89 + 6d51ec6 commit 7614239

16 files changed

+1181
-1041
lines changed

public/plugin/bbb/admin.php

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
}
5454
}
5555

56+
if (!isset($meeting['participants'])) {
57+
$meeting['participants'] = [];
58+
}
59+
5660
if ($action) {
5761
switch ($action) {
5862
case 'export':

public/plugin/bbb/ajax.php

+19-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
use Chamilo\CoreBundle\Component\Utils\ActionIcon;
7+
use Chamilo\CoreBundle\Entity\ConferenceMeeting;
8+
use Chamilo\CoreBundle\Repository\ConferenceMeetingRepository;
79

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

2931
if ($bbb->checkDirectMeetingVideoUrl($meetingId)) {
30-
$meetingInfo = Database::select(
31-
'*',
32-
'plugin_bbb_meeting',
33-
['where' => ['id = ?' => (int) $meetingId]],
34-
'first'
35-
);
36-
37-
$url = $meetingInfo['video_url'].'/capture.m4v';
38-
$link = Display::url(
39-
Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Download file')),
40-
$meetingInfo['video_url'].'/capture.m4v',
41-
['target' => '_blank']
42-
);
43-
44-
header('Content-Type: application/json');
45-
echo json_encode(['url' => $url, 'link' => $link]);
32+
$em = Database::getManager();
33+
/** @var ConferenceMeetingRepository $repo */
34+
$repo = $em->getRepository(ConferenceMeeting::class);
35+
36+
$meetingInfo = $repo->findOneAsArrayById($meetingId);
37+
38+
if ($meetingInfo && isset($meetingInfo['videoUrl'])) {
39+
$url = $meetingInfo['videoUrl'].'/capture.m4v';
40+
$link = Display::url(
41+
Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Download file')),
42+
$url,
43+
['target' => '_blank']
44+
);
45+
46+
header('Content-Type: application/json');
47+
echo json_encode(['url' => $url, 'link' => $link]);
48+
}
4649
}
4750
break;
4851
}

public/plugin/bbb/cron_close_meeting.php

+49-37
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
/**
44
* This script initiates a video conference session, calling the BigBlueButton API.
55
*/
6+
7+
use Chamilo\CoreBundle\Entity\ConferenceActivity;
8+
use Chamilo\CoreBundle\Repository\ConferenceActivityRepository;
9+
610
$course_plugin = 'bbb'; //needed in order to load the plugin lang variables
711
require_once __DIR__.'/config.php';
812

913
$plugin = BBBPlugin::create();
10-
$meetingTable = Database::get_main_table('plugin_bbb_meeting');
11-
$roomTable = Database::get_main_table('plugin_bbb_room');
14+
/** @var ConferenceActivityRepository $activityRepo */
15+
$em = Database::getManager();
16+
$activityRepo = $em->getRepository(ConferenceActivity::class);
1217

1318
$bbb = new bbb();
1419
if ($bbb->pluginEnabled) {
@@ -48,50 +53,57 @@
4853
$bbb->endMeeting($value['id'], $courseCode);
4954
break;
5055
case 'SUCCESS':
51-
Database::update(
52-
$roomTable,
53-
['close' => BBBPlugin::ROOM_CHECK],
54-
['meeting_id = ? AND close= ?' => [$meetingId, BBBPlugin::ROOM_OPEN]]
55-
);
56+
$activitiesToMark = $activityRepo->createQueryBuilder('a')
57+
->where('a.meeting = :meetingId')
58+
->andWhere('a.close = :open')
59+
->setParameter('meetingId', $meetingId)
60+
->setParameter('open', BBBPlugin::ROOM_OPEN)
61+
->getQuery()
62+
->getResult();
63+
64+
foreach ($activitiesToMark as $activity) {
65+
$activity->setClose(BBBPlugin::ROOM_CHECK);
66+
}
67+
$em->flush();
5668

5769
$i = 0;
5870
while ($i < $meetingBBB['participantCount']) {
5971
$participantId = $meetingBBB[$i]['userId'];
60-
$roomData = Database::select(
61-
'*',
62-
$roomTable,
63-
[
64-
'where' => [
65-
'meeting_id = ? AND participant_id = ? AND close = ?' => [
66-
$meetingId,
67-
$participantId,
68-
BBBPlugin::ROOM_CHECK,
69-
],
70-
],
71-
'order' => 'id DESC',
72-
],
73-
'first'
74-
);
75-
76-
if (!empty($roomData)) {
77-
$roomId = $roomData['id'];
78-
if (!empty($roomId)) {
79-
Database::update(
80-
$roomTable,
81-
['out_at' => api_get_utc_datetime(), 'close' => BBBPlugin::ROOM_OPEN],
82-
['id = ? ' => $roomId]
83-
);
84-
}
72+
73+
$roomData = $activityRepo->createQueryBuilder('a')
74+
->where('a.meeting = :meetingId')
75+
->andWhere('a.participant = :participantId')
76+
->andWhere('a.close = :check')
77+
->setParameter('meetingId', $meetingId)
78+
->setParameter('participantId', $participantId)
79+
->setParameter('check', BBBPlugin::ROOM_CHECK)
80+
->orderBy('a.id', 'DESC')
81+
->setMaxResults(1)
82+
->getQuery()
83+
->getOneOrNullResult();
84+
85+
if ($roomData instanceof ConferenceActivity) {
86+
$roomData->setOutAt(new \DateTime());
87+
$roomData->setClose(BBBPlugin::ROOM_OPEN);
8588
}
8689
$i++;
8790
}
91+
$em->flush();
8892

89-
Database::update(
90-
$roomTable,
91-
['out_at' => api_get_utc_datetime(), 'close' => BBBPlugin::ROOM_CLOSE],
92-
['meeting_id = ? AND close= ?' => [$meetingId, BBBPlugin::ROOM_CHECK]]
93-
);
93+
$activitiesToClose = $activityRepo->createQueryBuilder('a')
94+
->where('a.meeting = :meetingId')
95+
->andWhere('a.close = :check')
96+
->setParameter('meetingId', $meetingId)
97+
->setParameter('check', BBBPlugin::ROOM_CHECK)
98+
->getQuery()
99+
->getResult();
100+
101+
foreach ($activitiesToClose as $activity) {
102+
$activity->setOutAt(new \DateTime());
103+
$activity->setClose(BBBPlugin::ROOM_CLOSE);
104+
}
94105

106+
$em->flush();
95107
break;
96108
}
97109
}

0 commit comments

Comments
 (0)