|
3 | 3 | /**
|
4 | 4 | * This script initiates a video conference session, calling the BigBlueButton API.
|
5 | 5 | */
|
| 6 | + |
| 7 | +use Chamilo\CoreBundle\Entity\ConferenceActivity; |
| 8 | +use Chamilo\CoreBundle\Repository\ConferenceActivityRepository; |
| 9 | + |
6 | 10 | $course_plugin = 'bbb'; //needed in order to load the plugin lang variables
|
7 | 11 | require_once __DIR__.'/config.php';
|
8 | 12 |
|
9 | 13 | $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); |
12 | 17 |
|
13 | 18 | $bbb = new bbb();
|
14 | 19 | if ($bbb->pluginEnabled) {
|
|
48 | 53 | $bbb->endMeeting($value['id'], $courseCode);
|
49 | 54 | break;
|
50 | 55 | 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(); |
56 | 68 |
|
57 | 69 | $i = 0;
|
58 | 70 | while ($i < $meetingBBB['participantCount']) {
|
59 | 71 | $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); |
85 | 88 | }
|
86 | 89 | $i++;
|
87 | 90 | }
|
| 91 | + $em->flush(); |
88 | 92 |
|
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 | + } |
94 | 105 |
|
| 106 | + $em->flush(); |
95 | 107 | break;
|
96 | 108 | }
|
97 | 109 | }
|
|
0 commit comments