Total Complexity | 280 |
Total Lines | 2215 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like bbb often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use bbb, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class bbb |
||
11 | { |
||
12 | public $url; |
||
13 | public $salt; |
||
14 | public $api; |
||
15 | public $userCompleteName = ''; |
||
16 | public $protocol = 'http://'; |
||
17 | public $debug = false; |
||
18 | public $logoutUrl = ''; |
||
19 | public $pluginEnabled = false; |
||
20 | public $enableGlobalConference = false; |
||
21 | public $enableGlobalConferencePerUser = false; |
||
22 | public $isGlobalConference = false; |
||
23 | public $groupSupport = false; |
||
24 | public $userSupport = false; |
||
25 | public $accessUrl = 1; |
||
26 | public $userId = 0; |
||
27 | public $plugin; |
||
28 | private $courseCode; |
||
29 | private $courseId; |
||
30 | private $sessionId; |
||
31 | private $groupId; |
||
32 | private $maxUsersLimit; |
||
33 | |||
34 | /** |
||
35 | * Constructor (generates a connection to the API and the Chamilo settings |
||
36 | * required for the connection to the video conference server) |
||
37 | * |
||
38 | * @param string $host |
||
39 | * @param string $salt |
||
40 | * @param bool $isGlobalConference |
||
41 | * @param int $isGlobalPerUser |
||
42 | */ |
||
43 | public function __construct( |
||
44 | $host = '', |
||
45 | $salt = '', |
||
46 | $isGlobalConference = false, |
||
47 | $isGlobalPerUser = 0 |
||
48 | ) { |
||
49 | $this->courseCode = api_get_course_id(); |
||
50 | $this->courseId = api_get_course_int_id(); |
||
51 | $this->sessionId = api_get_session_id(); |
||
52 | $this->groupId = api_get_group_id(); |
||
53 | |||
54 | // Initialize video server settings from global settings |
||
55 | $this->plugin = BBBPlugin::create(); |
||
56 | $bbbPluginEnabled = $this->plugin->get('tool_enable'); |
||
|
|||
57 | |||
58 | $bbb_host = !empty($host) ? $host : $this->plugin->get('host'); |
||
59 | $bbb_salt = !empty($salt) ? $salt : $this->plugin->get('salt'); |
||
60 | |||
61 | $this->table = Database::get_main_table('plugin_bbb_meeting'); |
||
62 | $this->enableGlobalConference = $this->plugin->get('enable_global_conference') === 'true'; |
||
63 | $this->isGlobalConference = (bool) $isGlobalConference; |
||
64 | |||
65 | $columns = Database::listTableColumns($this->table); |
||
66 | $this->groupSupport = isset($columns['group_id']) ? true : false; |
||
67 | $this->userSupport = isset($columns['user_id']) ? true : false; |
||
68 | $this->accessUrl = api_get_current_access_url_id(); |
||
69 | |||
70 | $this->enableGlobalConferencePerUser = false; |
||
71 | if ($this->userSupport && !empty($isGlobalPerUser)) { |
||
72 | $this->enableGlobalConferencePerUser = $this->plugin->get('enable_global_conference_per_user') === 'true'; |
||
73 | $this->userId = $isGlobalPerUser; |
||
74 | } |
||
75 | |||
76 | if ($this->groupSupport) { |
||
77 | // Plugin check |
||
78 | $this->groupSupport = $this->plugin->get('enable_conference_in_course_groups') === 'true' ? true : false; |
||
79 | if ($this->groupSupport) { |
||
80 | // Platform check |
||
81 | $bbbSetting = api_get_setting('bbb_enable_conference_in_course_groups'); |
||
82 | $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false; |
||
83 | |||
84 | if ($bbbSetting) { |
||
85 | // Course check |
||
86 | $courseInfo = api_get_course_info(); |
||
87 | if ($courseInfo) { |
||
88 | $this->groupSupport = api_get_course_plugin_setting( |
||
89 | 'bbb', |
||
90 | 'bbb_enable_conference_in_groups', |
||
91 | $courseInfo |
||
92 | ) === '1'; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | $this->maxUsersLimit = $this->plugin->get('max_users_limit'); |
||
98 | |||
99 | if ($bbbPluginEnabled === 'true') { |
||
100 | $userInfo = api_get_user_info(); |
||
101 | if (empty($userInfo) && !empty($isGlobalPerUser)) { |
||
102 | // If we are following a link to a global "per user" conference |
||
103 | // then generate a random guest name to join the conference |
||
104 | // because there is no part of the process where we give a name |
||
105 | //$this->userCompleteName = 'Guest'.rand(1000, 9999); |
||
106 | } else { |
||
107 | $this->userCompleteName = $userInfo['complete_name']; |
||
108 | } |
||
109 | |||
110 | if (api_is_anonymous()) { |
||
111 | $this->userCompleteName = get_lang('Guest').'_'.rand(1000, 9999); |
||
112 | } |
||
113 | |||
114 | $this->salt = $bbb_salt; |
||
115 | if (!empty($bbb_host)) { |
||
116 | if (substr($bbb_host, -1, 1) !== '/') { |
||
117 | $bbb_host .= '/'; |
||
118 | } |
||
119 | $this->url = $bbb_host; |
||
120 | if (!preg_match('#/bigbluebutton/$#', $bbb_host)) { |
||
121 | $this->url = $bbb_host.'bigbluebutton/'; |
||
122 | } |
||
123 | } |
||
124 | $info = parse_url($bbb_host); |
||
125 | |||
126 | if (isset($info['scheme'])) { |
||
127 | $this->protocol = $info['scheme'].'://'; |
||
128 | $this->url = str_replace($this->protocol, '', $this->url); |
||
129 | $urlWithProtocol = $bbb_host; |
||
130 | } else { |
||
131 | // We assume it's an http, if user wants to use https, the host *must* include the protocol. |
||
132 | $this->protocol = 'http://'; |
||
133 | $urlWithProtocol = $this->protocol.$bbb_host; |
||
134 | } |
||
135 | |||
136 | // Setting BBB api |
||
137 | define('CONFIG_SECURITY_SALT', $this->salt); |
||
138 | define('CONFIG_SERVER_URL_WITH_PROTOCOL', $urlWithProtocol); |
||
139 | define('CONFIG_SERVER_BASE_URL', $this->url); |
||
140 | define('CONFIG_SERVER_PROTOCOL', $this->protocol); |
||
141 | |||
142 | $this->api = new BigBlueButtonBN(); |
||
143 | $this->pluginEnabled = true; |
||
144 | $this->logoutUrl = $this->getListingUrl(); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @param int $courseId Optional. Course ID. |
||
150 | * @param int $sessionId Optional. Session ID. |
||
151 | * @param int $groupId Optional. Group ID. |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getListingUrl($courseId = 0, $sessionId = 0, $groupId = 0) |
||
156 | { |
||
157 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?' |
||
158 | .$this->getUrlParams($courseId, $sessionId, $groupId); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @param int $courseId Optional. Course ID. |
||
163 | * @param int $sessionId Optional. Session ID. |
||
164 | * @param int $groupId Optional. Group ID. |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getUrlParams($courseId = 0, $sessionId = 0, $groupId = 0) |
||
169 | { |
||
170 | if (empty($this->courseCode) && !$courseId) { |
||
171 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
172 | return 'global=1&user_id='.$this->userId; |
||
173 | } |
||
174 | |||
175 | if ($this->isGlobalConference()) { |
||
176 | return 'global=1'; |
||
177 | } |
||
178 | |||
179 | return ''; |
||
180 | } |
||
181 | |||
182 | $courseCode = $this->courseCode; |
||
183 | if (!empty($courseId)) { |
||
184 | $course = api_get_course_info_by_id($courseId); |
||
185 | if ($course) { |
||
186 | $courseCode = $course['code']; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | return http_build_query( |
||
191 | [ |
||
192 | 'cidReq' => $courseCode, |
||
193 | 'id_session' => $sessionId ?: $this->sessionId, |
||
194 | 'gidReq' => $groupId ?: $this->groupId, |
||
195 | ] |
||
196 | ); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function isGlobalConferencePerUserEnabled() |
||
203 | { |
||
204 | return $this->enableGlobalConferencePerUser; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function isGlobalConference() |
||
211 | { |
||
212 | if ($this->isGlobalConferenceEnabled() === false) { |
||
213 | return false; |
||
214 | } |
||
215 | |||
216 | return (bool) $this->isGlobalConference; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @return bool |
||
221 | */ |
||
222 | public function isGlobalConferenceEnabled() |
||
223 | { |
||
224 | return $this->enableGlobalConference; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @param array $userInfo |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public static function showGlobalConferenceLink($userInfo) |
||
233 | { |
||
234 | if (empty($userInfo)) { |
||
235 | return false; |
||
236 | } |
||
237 | $setting = api_get_plugin_setting('bbb', 'enable_global_conference'); |
||
238 | $settingLink = api_get_plugin_setting('bbb', 'enable_global_conference_link'); |
||
239 | if ($setting === 'true' && $settingLink === 'true') { |
||
240 | //$content = Display::url(get_lang('LaunchVideoConferenceRoom'), $url); |
||
241 | $allowedRoles = api_get_plugin_setting( |
||
242 | 'bbb', |
||
243 | 'global_conference_allow_roles' |
||
244 | ); |
||
245 | |||
246 | if (api_is_platform_admin()) { |
||
247 | $userInfo['status'] = PLATFORM_ADMIN; |
||
248 | } |
||
249 | |||
250 | $showGlobalLink = true; |
||
251 | if (!empty($allowedRoles)) { |
||
252 | if (!in_array($userInfo['status'], $allowedRoles)) { |
||
253 | $showGlobalLink = false; |
||
254 | } |
||
255 | } |
||
256 | |||
257 | return $showGlobalLink; |
||
258 | } |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Gets the global limit of users in a video-conference room. |
||
263 | * This value can be overridden by course-specific values |
||
264 | * @return int Maximum number of users set globally |
||
265 | */ |
||
266 | public function getMaxUsersLimit() |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * Sets the global limit of users in a video-conference room. |
||
311 | * |
||
312 | * @param int Maximum number of users (globally) |
||
313 | */ |
||
314 | public function setMaxUsersLimit($max) |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * See this file in you BBB to set up default values |
||
324 | * |
||
325 | * @param array $params Array of parameters that will be completed if not containing all expected variables |
||
326 | * |
||
327 | * /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties |
||
328 | * |
||
329 | * More record information: |
||
330 | * http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification |
||
331 | * |
||
332 | * Default maximum number of users a meeting can have. |
||
333 | * Doesn't get enforced yet but is the default value when the create |
||
334 | * API doesn't pass a value. |
||
335 | * defaultMaxUsers=20 |
||
336 | * |
||
337 | * Default duration of the meeting in minutes. |
||
338 | * Current default is 0 (meeting doesn't end). |
||
339 | * defaultMeetingDuration=0 |
||
340 | * |
||
341 | * Remove the meeting from memory when the end API is called. |
||
342 | * This allows 3rd-party apps to recycle the meeting right-away |
||
343 | * instead of waiting for the meeting to expire (see below). |
||
344 | * removeMeetingWhenEnded=false |
||
345 | * |
||
346 | * The number of minutes before the system removes the meeting from memory. |
||
347 | * defaultMeetingExpireDuration=1 |
||
348 | * |
||
349 | * The number of minutes the system waits when a meeting is created and when |
||
350 | * a user joins. If after this period, a user hasn't joined, the meeting is |
||
351 | * removed from memory. |
||
352 | * defaultMeetingCreateJoinDuration=5 |
||
353 | * |
||
354 | * @return mixed |
||
355 | */ |
||
356 | public function createMeeting($params) |
||
357 | { |
||
358 | $params['c_id'] = api_get_course_int_id(); |
||
359 | $params['session_id'] = api_get_session_id(); |
||
360 | |||
361 | if ($this->hasGroupSupport()) { |
||
362 | $params['group_id'] = api_get_group_id(); |
||
363 | } |
||
364 | |||
365 | if ($this->isGlobalConferencePerUserEnabled() && !empty($this->userId)) { |
||
366 | $params['user_id'] = (int) $this->userId; |
||
367 | } |
||
368 | |||
369 | $params['attendee_pw'] = isset($params['attendee_pw']) ? $params['attendee_pw'] : $this->getUserMeetingPassword(); |
||
370 | $attendeePassword = $params['attendee_pw']; |
||
371 | $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword(); |
||
372 | $moderatorPassword = $params['moderator_pw']; |
||
373 | |||
374 | $params['record'] = api_get_course_plugin_setting('bbb', 'big_blue_button_record_and_store') == 1; |
||
375 | $max = api_get_course_plugin_setting('bbb', 'max_users_limit'); |
||
376 | $max = isset($max) ? $max : -1; |
||
377 | |||
378 | $params['status'] = 1; |
||
379 | // Generate a pseudo-global-unique-id to avoid clash of conferences on |
||
380 | // the same BBB server with several Chamilo portals |
||
381 | $params['remote_id'] = uniqid(true, true); |
||
382 | // Each simultaneous conference room needs to have a different |
||
383 | // voice_bridge composed of a 5 digits number, so generating a random one |
||
384 | $params['voice_bridge'] = rand(10000, 99999); |
||
385 | $params['created_at'] = api_get_utc_datetime(); |
||
386 | $params['access_url'] = $this->accessUrl; |
||
387 | |||
388 | $id = Database::insert($this->table, $params); |
||
389 | |||
390 | if ($id) { |
||
391 | Event::addEvent( |
||
392 | 'bbb_create_meeting', |
||
393 | 'meeting_id', |
||
394 | (int) $id, |
||
395 | null, |
||
396 | api_get_user_id(), |
||
397 | api_get_course_int_id(), |
||
398 | api_get_session_id() |
||
399 | ); |
||
400 | |||
401 | $meetingName = $params['meeting_name'] ?? $this->generateVideoConferenceName(); |
||
402 | $welcomeMessage = $params['welcome_msg'] ?? null; |
||
403 | $record = $params['record'] ? 'true' : 'false'; |
||
404 | //$duration = isset($params['duration']) ? intval($params['duration']) : 0; |
||
405 | // This setting currently limits the maximum conference duration, |
||
406 | // to avoid lingering sessions on the video-conference server #6261 |
||
407 | $duration = 300; |
||
408 | $meetingDuration = (int) $this->plugin->get('meeting_duration'); |
||
409 | if (!empty($meetingDuration)) { |
||
410 | $duration = $meetingDuration; |
||
411 | } |
||
412 | $bbbParams = array( |
||
413 | 'meetingId' => $params['remote_id'], // REQUIRED |
||
414 | 'meetingName' => $meetingName, // REQUIRED |
||
415 | 'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee. |
||
416 | 'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator. |
||
417 | 'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize. |
||
418 | 'dialNumber' => '', // The main number to call into. Optional. |
||
419 | 'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required. |
||
420 | 'webVoice' => '', // Alphanumeric to join voice. Optional. |
||
421 | 'logoutUrl' => $this->logoutUrl.'&action=logout&remote_id='.$params['remote_id'], |
||
422 | 'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number] |
||
423 | 'record' => $record, // New. 'true' will tell BBB to record the meeting. |
||
424 | 'duration' => $duration, // Default = 0 which means no set duration in minutes. [number] |
||
425 | //'meta_category' => '', // Use to pass additional info to BBB server. See API docs. |
||
426 | ); |
||
427 | |||
428 | $status = false; |
||
429 | $meeting = null; |
||
430 | while ($status === false) { |
||
431 | $result = $this->api->createMeetingWithXmlResponseArray($bbbParams); |
||
432 | if (isset($result) && strval($result['returncode']) == 'SUCCESS') { |
||
433 | if ($this->plugin->get('allow_regenerate_recording') === 'true') { |
||
434 | $internalId = Database::escape_string($result['internalMeetingID']); |
||
435 | $sql = "UPDATE $this->table SET internal_meeting_id = '".$internalId."' |
||
436 | WHERE id = $id"; |
||
437 | Database::query($sql); |
||
438 | } |
||
439 | $meeting = $this->joinMeeting($meetingName, true); |
||
440 | |||
441 | return $meeting; |
||
442 | } |
||
443 | } |
||
444 | } |
||
445 | |||
446 | return false; |
||
447 | } |
||
448 | |||
449 | /** |
||
450 | * @return bool |
||
451 | */ |
||
452 | public function hasGroupSupport() |
||
453 | { |
||
454 | return $this->groupSupport; |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * Gets the password for a specific meeting for the current user |
||
459 | * |
||
460 | * @param string $courseCode |
||
461 | * |
||
462 | * @return string A moderator password if user is teacher, or the course code otherwise |
||
463 | * |
||
464 | */ |
||
465 | public function getUserMeetingPassword($courseCode = null) |
||
466 | { |
||
467 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
468 | return 'url_'.$this->userId.'_'.api_get_current_access_url_id(); |
||
469 | } |
||
470 | |||
471 | if ($this->isGlobalConference()) { |
||
472 | return 'url_'.api_get_current_access_url_id(); |
||
473 | } |
||
474 | $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode; |
||
475 | |||
476 | return $courseCode; |
||
477 | } |
||
478 | |||
479 | /** |
||
480 | * Generated a moderator password for the meeting. |
||
481 | * |
||
482 | * @param string $courseCode |
||
483 | * |
||
484 | * @return string A password for the moderation of the videoconference |
||
485 | */ |
||
486 | public function getModMeetingPassword($courseCode = null) |
||
499 | } |
||
500 | |||
501 | /** |
||
502 | * Get the info from the current open videoconference. |
||
503 | * Otherwise, return false. |
||
504 | * |
||
505 | * @return array|bool |
||
506 | */ |
||
507 | public function getCurrentVideoConference() |
||
508 | { |
||
509 | $whereConditions = [ |
||
510 | 'status = ?' => 1, |
||
511 | ]; |
||
512 | |||
513 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
514 | $whereConditions[' AND user_id = ?'] = $this->userId; |
||
515 | } |
||
516 | |||
517 | if ($this->isGlobalConference()) { |
||
518 | $whereConditions[' AND access_url = ?'] = api_get_current_access_url_id(); |
||
519 | } |
||
520 | |||
521 | if ($this->hasGroupSupport()) { |
||
522 | $whereConditions[' AND group_id = ?'] = api_get_group_id(); |
||
523 | } |
||
524 | |||
525 | $cId = api_get_course_int_id(); |
||
526 | $sessionId = api_get_session_id(); |
||
527 | |||
528 | if ($cId) { |
||
529 | $whereConditions[' AND c_id = ?'] = api_get_course_int_id(); |
||
530 | } |
||
531 | |||
532 | if ($sessionId) { |
||
533 | $whereConditions[' AND session_id = ?'] = api_get_session_id(); |
||
534 | } |
||
535 | |||
536 | return Database::select( |
||
537 | '*', |
||
538 | $this->table, |
||
539 | [ |
||
540 | 'where' => $whereConditions, |
||
541 | 'order' => 'created_at DESC', |
||
542 | ], |
||
543 | 'first' |
||
544 | ); |
||
545 | } |
||
546 | |||
547 | public function generateVideoConferenceName(string $defaultName = null): string |
||
548 | { |
||
549 | $nameFilter = function ($name) { |
||
550 | return URLify::filter( |
||
551 | $name, |
||
552 | 64, |
||
553 | '', |
||
554 | true, |
||
555 | true, |
||
556 | true, |
||
557 | false |
||
558 | ); |
||
559 | }; |
||
560 | |||
561 | if (!empty($defaultName)) { |
||
562 | $name = $nameFilter($defaultName); |
||
563 | |||
564 | if (!empty($name)) { |
||
565 | return $name; |
||
566 | } |
||
567 | } |
||
568 | |||
569 | $urlId = api_get_current_access_url_id(); |
||
570 | |||
571 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
572 | return $nameFilter("url_{$this->userId}_$urlId"); |
||
573 | } |
||
574 | |||
575 | if ($this->isGlobalConference()) { |
||
576 | return $nameFilter("url_$urlId"); |
||
577 | } |
||
578 | |||
579 | $course = api_get_course_entity(); |
||
580 | $session = api_get_session_entity(); |
||
581 | $group = api_get_group_entity(); |
||
582 | |||
583 | if ($this->hasGroupSupport()) { |
||
584 | $name = implode( |
||
585 | '-', |
||
586 | [ |
||
587 | $course->getCode(), |
||
588 | $session ? $session->getName() : '', |
||
589 | $group ? $group->getName() : '', |
||
590 | ] |
||
591 | ); |
||
592 | |||
593 | return $nameFilter($name); |
||
594 | } |
||
595 | |||
596 | $name = implode( |
||
597 | '-', |
||
598 | [ |
||
599 | $course->getCode(), |
||
600 | $session ? $session->getName() : '', |
||
601 | ] |
||
602 | ); |
||
603 | |||
604 | return $nameFilter($name); |
||
605 | } |
||
606 | |||
607 | /** |
||
608 | * Returns a meeting "join" URL |
||
609 | * |
||
610 | * @param string The name of the meeting (usually the course code) |
||
611 | * |
||
612 | * @return mixed The URL to join the meeting, or false on error |
||
613 | * @todo implement moderator pass |
||
614 | * @assert ('') === false |
||
615 | * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false |
||
616 | */ |
||
617 | public function joinMeeting($meetingName) |
||
618 | { |
||
619 | if ($this->debug) { |
||
620 | error_log("joinMeeting: $meetingName"); |
||
621 | } |
||
622 | |||
623 | if (empty($meetingName)) { |
||
624 | return false; |
||
625 | } |
||
626 | |||
627 | $manager = $this->isConferenceManager(); |
||
628 | if ($manager) { |
||
629 | $pass = $this->getModMeetingPassword(); |
||
630 | } else { |
||
631 | $pass = $this->getUserMeetingPassword(); |
||
632 | } |
||
633 | |||
634 | $meetingData = Database::select( |
||
635 | '*', |
||
636 | $this->table, |
||
637 | array( |
||
638 | 'where' => array( |
||
639 | 'meeting_name = ? AND status = 1 AND access_url = ?' => array( |
||
640 | $meetingName, |
||
641 | $this->accessUrl, |
||
642 | ), |
||
643 | ), |
||
644 | ), |
||
645 | 'first' |
||
646 | ); |
||
647 | |||
648 | if (empty($meetingData) || !is_array($meetingData)) { |
||
649 | if ($this->debug) { |
||
650 | error_log("meeting does not exist: $meetingName"); |
||
651 | } |
||
652 | |||
653 | return false; |
||
654 | } |
||
655 | |||
656 | $params = array( |
||
657 | 'meetingId' => $meetingData['remote_id'], |
||
658 | // -- REQUIRED - The unique id for the meeting |
||
659 | 'password' => $this->getModMeetingPassword() |
||
660 | // -- REQUIRED - The moderator password for the meeting |
||
661 | ); |
||
662 | |||
663 | $meetingInfoExists = false; |
||
664 | $meetingIsRunningInfo = $this->getMeetingInfo($params); |
||
665 | if ($this->debug) { |
||
666 | error_log('Searching meeting with params:'); |
||
667 | error_log(print_r($params, 1)); |
||
668 | error_log('Result:'); |
||
669 | error_log(print_r($meetingIsRunningInfo, 1)); |
||
670 | } |
||
671 | |||
672 | if ($meetingIsRunningInfo === false) { |
||
673 | // checking with the remote_id didn't work, so just in case and |
||
674 | // to provide backwards support, check with the id |
||
675 | $params = array( |
||
676 | 'meetingId' => $meetingData['id'], |
||
677 | // -- REQUIRED - The unique id for the meeting |
||
678 | 'password' => $this->getModMeetingPassword() |
||
679 | // -- REQUIRED - The moderator password for the meeting |
||
680 | ); |
||
681 | $meetingIsRunningInfo = $this->getMeetingInfo($params); |
||
682 | if ($this->debug) { |
||
683 | error_log('Searching meetingId with params:'); |
||
684 | error_log(print_r($params, 1)); |
||
685 | error_log('Result:'); |
||
686 | error_log(print_r($meetingIsRunningInfo, 1)); |
||
687 | } |
||
688 | } |
||
689 | |||
690 | if (strval($meetingIsRunningInfo['returncode']) === 'SUCCESS' && |
||
691 | isset($meetingIsRunningInfo['meetingName']) && |
||
692 | !empty($meetingIsRunningInfo['meetingName']) |
||
693 | ) { |
||
694 | $meetingInfoExists = true; |
||
695 | } |
||
696 | |||
697 | if ($this->debug) { |
||
698 | error_log( |
||
699 | "meeting is running: ".intval($meetingInfoExists) |
||
700 | ); |
||
701 | } |
||
702 | |||
703 | $url = false; |
||
704 | if ($meetingInfoExists) { |
||
705 | $joinParams = [ |
||
706 | 'meetingId' => $meetingData['remote_id'], |
||
707 | // -- REQUIRED - A unique id for the meeting |
||
708 | 'username' => $this->userCompleteName, |
||
709 | //-- REQUIRED - The name that will display for the user in the meeting |
||
710 | 'password' => $pass, |
||
711 | //-- REQUIRED - The attendee or moderator password, depending on what's passed here |
||
712 | //'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly. |
||
713 | 'userID' => api_get_user_id(), |
||
714 | //-- OPTIONAL - string |
||
715 | 'webVoiceConf' => '', |
||
716 | ]; |
||
717 | $url = $this->api->getJoinMeetingURL($joinParams); |
||
718 | $url = $this->protocol.$url; |
||
719 | } |
||
720 | |||
721 | if ($this->debug) { |
||
722 | error_log("return url :".$url); |
||
723 | } |
||
724 | |||
725 | return $url; |
||
726 | } |
||
727 | |||
728 | /** |
||
729 | * Checks whether a user is teacher in the current course |
||
730 | * @return bool True if the user can be considered a teacher in this course, false otherwise |
||
731 | */ |
||
732 | public function isConferenceManager() |
||
733 | { |
||
734 | if (api_is_coach() || api_is_platform_admin(false, true)) { |
||
735 | return true; |
||
736 | } |
||
737 | |||
738 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
739 | $currentUserId = api_get_user_id(); |
||
740 | if ($this->userId === $currentUserId) { |
||
741 | return true; |
||
742 | } else { |
||
743 | return false; |
||
744 | } |
||
745 | } |
||
746 | |||
747 | $courseInfo = api_get_course_info(); |
||
748 | $groupId = api_get_group_id(); |
||
749 | if (!empty($groupId) && !empty($courseInfo)) { |
||
750 | $groupEnabled = api_get_course_plugin_setting('bbb', 'bbb_enable_conference_in_groups') === '1'; |
||
751 | if ($groupEnabled) { |
||
752 | $studentCanStartConference = api_get_course_plugin_setting( |
||
753 | 'bbb', |
||
754 | 'big_blue_button_students_start_conference_in_groups' |
||
755 | ) === '1'; |
||
756 | |||
757 | if ($studentCanStartConference) { |
||
758 | $isSubscribed = GroupManager::is_user_in_group( |
||
759 | api_get_user_id(), |
||
760 | GroupManager::get_group_properties($groupId) |
||
761 | ); |
||
762 | if ($isSubscribed) { |
||
763 | return true; |
||
764 | } |
||
765 | } |
||
766 | } |
||
767 | } |
||
768 | |||
769 | if (!empty($courseInfo)) { |
||
770 | return api_is_course_admin(); |
||
771 | } |
||
772 | |||
773 | return false; |
||
774 | } |
||
775 | |||
776 | /** |
||
777 | * Get information about the given meeting |
||
778 | * |
||
779 | * @param array ...? |
||
780 | * |
||
781 | * @return mixed Array of information on success, false on error |
||
782 | * @assert (array()) === false |
||
783 | */ |
||
784 | public function getMeetingInfo($params) |
||
785 | { |
||
786 | try { |
||
787 | $result = $this->api->getMeetingInfoWithXmlResponseArray($params); |
||
788 | if ($result == null) { |
||
789 | if ($this->debug) { |
||
790 | error_log("Failed to get any response. Maybe we can't contact the BBB server."); |
||
791 | } |
||
792 | } |
||
793 | |||
794 | return $result; |
||
795 | } catch (Exception $e) { |
||
796 | if ($this->debug) { |
||
797 | error_log('Caught exception: ', $e->getMessage(), "\n"); |
||
798 | } |
||
799 | } |
||
800 | |||
801 | return false; |
||
802 | } |
||
803 | |||
804 | |||
805 | /** |
||
806 | * @param int $meetingId |
||
807 | * @param int $userId |
||
808 | * |
||
809 | * @return array |
||
810 | */ |
||
811 | public function getMeetingParticipantInfo($meetingId, $userId) |
||
812 | { |
||
813 | $meetingData = Database::select( |
||
814 | '*', |
||
815 | 'plugin_bbb_room', |
||
816 | array('where' => array('meeting_id = ? AND participant_id = ?' => [$meetingId, $userId])), |
||
817 | 'first' |
||
818 | ); |
||
819 | |||
820 | if ($meetingData) { |
||
821 | return $meetingData; |
||
822 | } |
||
823 | |||
824 | return []; |
||
825 | } |
||
826 | |||
827 | /** |
||
828 | * Save a participant in a meeting room |
||
829 | * |
||
830 | * @param int $meetingId |
||
831 | * @param int $participantId |
||
832 | * |
||
833 | * @return false|int The last inserted ID. Otherwise return false |
||
834 | */ |
||
835 | public function saveParticipant($meetingId, $participantId) |
||
836 | { |
||
837 | $meetingData = Database::select( |
||
838 | '*', |
||
839 | 'plugin_bbb_room', |
||
840 | [ |
||
841 | 'where' => [ |
||
842 | 'meeting_id = ? AND participant_id = ? AND close = ?' => [ |
||
843 | $meetingId, |
||
844 | $participantId, |
||
845 | BBBPlugin::ROOM_OPEN, |
||
846 | ], |
||
847 | ], |
||
848 | ] |
||
849 | ); |
||
850 | |||
851 | foreach ($meetingData as $roomItem) { |
||
852 | $inAt = $roomItem['in_at']; |
||
853 | $outAt = $roomItem['out_at']; |
||
854 | $roomId = $roomItem['id']; |
||
855 | if (!empty($roomId)) { |
||
856 | if ($inAt != $outAt) { |
||
857 | Database::update( |
||
858 | 'plugin_bbb_room', |
||
859 | ['close' => BBBPlugin::ROOM_CLOSE], |
||
860 | ['id = ? ' => $roomId] |
||
861 | ); |
||
862 | } else { |
||
863 | Database::update( |
||
864 | 'plugin_bbb_room', |
||
865 | ['out_at' => api_get_utc_datetime(), 'close' => BBBPlugin::ROOM_CLOSE], |
||
866 | ['id = ? ' => $roomId] |
||
867 | ); |
||
868 | } |
||
869 | } |
||
870 | } |
||
871 | |||
872 | $params = [ |
||
873 | 'meeting_id' => $meetingId, |
||
874 | 'participant_id' => $participantId, |
||
875 | 'in_at' => api_get_utc_datetime(), |
||
876 | 'out_at' => api_get_utc_datetime(), |
||
877 | 'close' => BBBPlugin::ROOM_OPEN, |
||
878 | ]; |
||
879 | |||
880 | return Database::insert( |
||
881 | 'plugin_bbb_room', |
||
882 | $params |
||
883 | ); |
||
884 | } |
||
885 | |||
886 | /** |
||
887 | * Tells whether the given meeting exists and is running |
||
888 | * (using course code as name) |
||
889 | * |
||
890 | * @param string $meetingName Meeting name (usually the course code) |
||
891 | * |
||
892 | * @return bool True if meeting exists, false otherwise |
||
893 | * @assert ('') === false |
||
894 | * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false |
||
895 | */ |
||
896 | public function meetingExists($meetingName) |
||
897 | { |
||
898 | $meetingData = $this->getMeetingByName($meetingName); |
||
899 | |||
900 | return !empty($meetingData); |
||
901 | } |
||
902 | |||
903 | /** |
||
904 | * @param string $meetingName |
||
905 | * |
||
906 | * @return array |
||
907 | */ |
||
908 | public function getMeetingByName($meetingName) |
||
909 | { |
||
910 | if (empty($meetingName)) { |
||
911 | return []; |
||
912 | } |
||
913 | |||
914 | $courseId = api_get_course_int_id(); |
||
915 | $sessionId = api_get_session_id(); |
||
916 | $conditions = array( |
||
917 | 'where' => array( |
||
918 | 'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 AND access_url = ?' => |
||
919 | array($courseId, $sessionId, $meetingName, $this->accessUrl), |
||
920 | ), |
||
921 | ); |
||
922 | |||
923 | if ($this->hasGroupSupport()) { |
||
924 | $groupId = api_get_group_id(); |
||
925 | $conditions = array( |
||
926 | 'where' => array( |
||
927 | 'c_id = ? AND session_id = ? AND meeting_name = ? AND group_id = ? AND status = 1 AND access_url = ?' => |
||
928 | array( |
||
929 | $courseId, |
||
930 | $sessionId, |
||
931 | $meetingName, |
||
932 | $groupId, |
||
933 | $this->accessUrl, |
||
934 | ), |
||
935 | ), |
||
936 | ); |
||
937 | } |
||
938 | |||
939 | $meetingData = Database::select( |
||
940 | '*', |
||
941 | $this->table, |
||
942 | $conditions, |
||
943 | 'first' |
||
944 | ); |
||
945 | |||
946 | if ($this->debug) { |
||
947 | error_log('meeting_exists '.print_r($meetingData, 1)); |
||
948 | } |
||
949 | |||
950 | return $meetingData; |
||
951 | } |
||
952 | |||
953 | /** |
||
954 | * Gets a list from the database of all meetings attached to a course with the given status |
||
955 | * @param int $courseId |
||
956 | * @param int $sessionId |
||
957 | * @param int $status 0 for closed meetings, 1 for open meetings |
||
958 | * |
||
959 | * @return array |
||
960 | */ |
||
961 | public function getAllMeetingsInCourse($courseId, $sessionId, $status) |
||
962 | { |
||
963 | $conditions = array( |
||
964 | 'where' => array( |
||
965 | 'status = ? AND c_id = ? AND session_id = ? ' => array( |
||
966 | $status, |
||
967 | $courseId, |
||
968 | $sessionId, |
||
969 | ), |
||
970 | ), |
||
971 | ); |
||
972 | |||
973 | return Database::select( |
||
974 | '*', |
||
975 | $this->table, |
||
976 | $conditions |
||
977 | ); |
||
978 | } |
||
979 | |||
980 | /** |
||
981 | * Gets all the course meetings saved in the plugin_bbb_meeting table and |
||
982 | * generate actionable links (join/close/delete/etc) |
||
983 | * |
||
984 | * @param int $courseId |
||
985 | * @param int $sessionId |
||
986 | * @param int $groupId |
||
987 | * @param bool $isAdminReport Optional. Set to true then the report is for admins |
||
988 | * @param array $dateRange Optional |
||
989 | * @param int $start Optional |
||
990 | * @param int $limit Optional |
||
991 | * |
||
992 | * @return array Array of current open meeting rooms |
||
993 | * @throws Exception |
||
994 | */ |
||
995 | public function getMeetings( |
||
996 | $courseId = 0, |
||
997 | $sessionId = 0, |
||
998 | $groupId = 0, |
||
999 | $isAdminReport = false, |
||
1000 | $dateRange = [], |
||
1001 | $start = 0, |
||
1002 | $limit = 0 |
||
1003 | ) { |
||
1004 | $em = Database::getManager(); |
||
1005 | $manager = $this->isConferenceManager(); |
||
1006 | |||
1007 | $conditions = []; |
||
1008 | if ($courseId || $sessionId || $groupId) { |
||
1009 | $conditions = array( |
||
1010 | 'where' => array( |
||
1011 | 'c_id = ? AND session_id = ? ' => array($courseId, $sessionId), |
||
1012 | ), |
||
1013 | ); |
||
1014 | |||
1015 | if ($this->hasGroupSupport()) { |
||
1016 | $conditions = array( |
||
1017 | 'where' => array( |
||
1018 | 'c_id = ? AND session_id = ? AND group_id = ? ' => array( |
||
1019 | $courseId, |
||
1020 | $sessionId, |
||
1021 | $groupId, |
||
1022 | ), |
||
1023 | ), |
||
1024 | ); |
||
1025 | } |
||
1026 | |||
1027 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
1028 | $conditions = array( |
||
1029 | 'where' => array( |
||
1030 | 'c_id = ? AND session_id = ? AND user_id = ?' => array( |
||
1031 | $courseId, |
||
1032 | $sessionId, |
||
1033 | $this->userId, |
||
1034 | ), |
||
1035 | ), |
||
1036 | ); |
||
1037 | } |
||
1038 | } |
||
1039 | if ($this->isGlobalConference()) { |
||
1040 | $conditions = array( |
||
1041 | 'where' => array( |
||
1042 | 'c_id = ? AND user_id = ?' => array( |
||
1043 | 0, |
||
1044 | $this->userId, |
||
1045 | ), |
||
1046 | ), |
||
1047 | ); |
||
1048 | } |
||
1049 | |||
1050 | if (!empty($dateRange)) { |
||
1051 | $dateStart = date_create($dateRange['search_meeting_start']); |
||
1052 | $dateStart = date_format($dateStart, 'Y-m-d H:i:s'); |
||
1053 | $dateEnd = date_create($dateRange['search_meeting_end']); |
||
1054 | $dateEnd = $dateEnd->add(new DateInterval('P1D')); |
||
1055 | $dateEnd = date_format($dateEnd, 'Y-m-d H:i:s'); |
||
1056 | |||
1057 | $conditions = array( |
||
1058 | 'where' => array( |
||
1059 | 'created_at BETWEEN ? AND ? ' => array($dateStart, $dateEnd), |
||
1060 | ), |
||
1061 | ); |
||
1062 | } |
||
1063 | |||
1064 | $conditions['order'] = 'created_at ASC'; |
||
1065 | |||
1066 | if ($limit) { |
||
1067 | $conditions['limit'] = "$start , $limit"; |
||
1068 | } |
||
1069 | |||
1070 | $meetingList = Database::select( |
||
1071 | '*', |
||
1072 | $this->table, |
||
1073 | $conditions |
||
1074 | ); |
||
1075 | $isGlobal = $this->isGlobalConference(); |
||
1076 | $newMeetingList = array(); |
||
1077 | foreach ($meetingList as $meetingDB) { |
||
1078 | $item = array(); |
||
1079 | $item['metting_name'] = $meetingDB['meeting_name']; |
||
1080 | $courseId = $meetingDB['c_id']; |
||
1081 | $courseInfo = api_get_course_info_by_id($courseId); |
||
1082 | $courseCode = ''; |
||
1083 | if (!empty($courseInfo)) { |
||
1084 | $courseCode = $courseInfo['code']; |
||
1085 | } |
||
1086 | |||
1087 | if ($manager) { |
||
1088 | $pass = $meetingDB['moderator_pw']; |
||
1089 | } else { |
||
1090 | $pass = $meetingDB['attendee_pw']; |
||
1091 | } |
||
1092 | |||
1093 | $meetingBBB = $this->getMeetingInfo( |
||
1094 | [ |
||
1095 | 'meetingId' => $meetingDB['remote_id'], |
||
1096 | 'password' => $pass, |
||
1097 | ] |
||
1098 | ); |
||
1099 | |||
1100 | if ($meetingBBB === false) { |
||
1101 | // Checking with the remote_id didn't work, so just in case and |
||
1102 | // to provide backwards support, check with the id |
||
1103 | $params = array( |
||
1104 | 'meetingId' => $meetingDB['id'], |
||
1105 | // -- REQUIRED - The unique id for the meeting |
||
1106 | 'password' => $pass |
||
1107 | // -- REQUIRED - The moderator password for the meeting |
||
1108 | ); |
||
1109 | $meetingBBB = $this->getMeetingInfo($params); |
||
1110 | } |
||
1111 | |||
1112 | if ($meetingDB['visibility'] == 0 && $this->isConferenceManager() === false) { |
||
1113 | continue; |
||
1114 | } |
||
1115 | |||
1116 | $meetingBBB['end_url'] = $this->endUrl($meetingDB); |
||
1117 | |||
1118 | if (isset($meetingBBB['returncode']) && (string) $meetingBBB['returncode'] === 'FAILED') { |
||
1119 | if ($meetingDB['status'] == 1 && $this->isConferenceManager()) { |
||
1120 | $this->endMeeting($meetingDB['id'], $courseCode); |
||
1121 | } |
||
1122 | } else { |
||
1123 | $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB); |
||
1124 | } |
||
1125 | |||
1126 | if ($meetingDB['record'] == 1) { |
||
1127 | // backwards compatibility (when there was no remote ID) |
||
1128 | $mId = $meetingDB['remote_id']; |
||
1129 | if (empty($mId)) { |
||
1130 | $mId = $meetingDB['id']; |
||
1131 | } |
||
1132 | if (empty($mId)) { |
||
1133 | // if the id is still empty (should *never* occur as 'id' is |
||
1134 | // the table's primary key), skip this conference |
||
1135 | continue; |
||
1136 | } |
||
1137 | |||
1138 | $record = []; |
||
1139 | $recordingParams = ['meetingId' => $mId]; |
||
1140 | $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams); |
||
1141 | |||
1142 | if (!empty($records)) { |
||
1143 | if (!isset($records['messageKey']) || $records['messageKey'] !== 'noRecordings') { |
||
1144 | $record = end($records); |
||
1145 | if (!is_array($record) || !isset($record['recordId'])) { |
||
1146 | continue; |
||
1147 | } |
||
1148 | |||
1149 | if (!empty($record['playbackFormat'])) { |
||
1150 | $this->updateMeetingVideoUrl($meetingDB['id'], $record['playbackFormatUrl']); |
||
1151 | } |
||
1152 | } |
||
1153 | } |
||
1154 | |||
1155 | if (isset($record['playbackFormat']) && !empty($record['playbackFormat'])) { |
||
1156 | $recordLink = []; |
||
1157 | foreach ($record['playbackFormat'] as $format) { |
||
1158 | $this->insertMeetingFormat(intval($meetingDB['id']), $format->type->__toString(), $format->url->__toString()); |
||
1159 | $recordLink['record'][] = 1; |
||
1160 | $recordLink[] = Display::url( |
||
1161 | $this->plugin->get_lang($format->type->__toString()), |
||
1162 | $format->url->__toString(), |
||
1163 | ['target' => '_blank', 'class' => 'btn btn-default'] |
||
1164 | ); |
||
1165 | } |
||
1166 | } else { |
||
1167 | $recordLink = $this->plugin->get_lang('NoRecording'); |
||
1168 | } |
||
1169 | |||
1170 | if ($isAdminReport) { |
||
1171 | $this->forceCIdReq( |
||
1172 | $courseInfo['code'], |
||
1173 | $meetingDB['session_id'], |
||
1174 | $meetingDB['group_id'] |
||
1175 | ); |
||
1176 | } |
||
1177 | |||
1178 | $actionLinks = $this->getActionLinks( |
||
1179 | $meetingDB, |
||
1180 | $record, |
||
1181 | $isGlobal, |
||
1182 | $isAdminReport |
||
1183 | ); |
||
1184 | $item['show_links'] = $recordLink; |
||
1185 | $item['record'] = true; |
||
1186 | } else { |
||
1187 | $actionLinks = $this->getActionLinks( |
||
1188 | $meetingDB, |
||
1189 | [], |
||
1190 | $isGlobal, |
||
1191 | $isAdminReport |
||
1192 | ); |
||
1193 | |||
1194 | $item['show_links'] = $this->plugin->get_lang('NoRecording'); |
||
1195 | $item['record'] = false; |
||
1196 | } |
||
1197 | |||
1198 | $item['action_links'] = implode(PHP_EOL, $actionLinks); |
||
1199 | $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']); |
||
1200 | // created_at |
||
1201 | $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below |
||
1202 | |||
1203 | $item['closed_at'] = ''; |
||
1204 | if (!empty($meetingDB['closed_at'])) { |
||
1205 | $item['closed_at'] = api_convert_and_format_date($meetingDB['closed_at']); |
||
1206 | $meetingDB['closed_at'] = $item['closed_at']; |
||
1207 | } |
||
1208 | |||
1209 | $item['publish_url'] = $this->publishUrl($meetingDB); |
||
1210 | $item['unpublish_url'] = $this->unPublishUrl($meetingBBB); |
||
1211 | |||
1212 | if ($meetingDB['status'] == 1) { |
||
1213 | $joinParams = [ |
||
1214 | 'meetingId' => $meetingDB['remote_id'], |
||
1215 | //-- REQUIRED - A unique id for the meeting |
||
1216 | 'username' => $this->userCompleteName, |
||
1217 | //-- REQUIRED - The name that will display for the user in the meeting |
||
1218 | 'password' => $pass, |
||
1219 | //-- REQUIRED - The attendee or moderator password, depending on what's passed here |
||
1220 | 'createTime' => '', |
||
1221 | //-- OPTIONAL - string. Leave blank ('') unless you set this correctly. |
||
1222 | 'userID' => '', |
||
1223 | // -- OPTIONAL - string |
||
1224 | 'webVoiceConf' => '', |
||
1225 | ]; |
||
1226 | $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams); |
||
1227 | } |
||
1228 | $item = array_merge($item, $meetingDB, $meetingBBB); |
||
1229 | |||
1230 | $item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']); |
||
1231 | $item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']); |
||
1232 | $newMeetingList[] = $item; |
||
1233 | } |
||
1234 | |||
1235 | return $newMeetingList; |
||
1236 | } |
||
1237 | |||
1238 | /** |
||
1239 | * Counts all the course meetings saved in the plugin_bbb_meeting table. |
||
1240 | * |
||
1241 | * @param int $courseId |
||
1242 | * @param int $sessionId |
||
1243 | * @param int $groupId |
||
1244 | * @param array $dateRange |
||
1245 | * |
||
1246 | * @return int Count of meetings |
||
1247 | * @throws Exception |
||
1248 | */ |
||
1249 | public function getCountMeetings( |
||
1250 | $courseId = 0, |
||
1251 | $sessionId = 0, |
||
1252 | $groupId = 0, |
||
1253 | $dateRange = [] |
||
1254 | ) { |
||
1255 | $conditions = []; |
||
1256 | if ($courseId || $sessionId || $groupId) { |
||
1257 | $conditions = array( |
||
1258 | 'where' => array( |
||
1259 | 'c_id = ? AND session_id = ? ' => array($courseId, $sessionId), |
||
1260 | ), |
||
1261 | ); |
||
1262 | |||
1263 | if ($this->hasGroupSupport()) { |
||
1264 | $conditions = array( |
||
1265 | 'where' => array( |
||
1266 | 'c_id = ? AND session_id = ? AND group_id = ? ' => array( |
||
1267 | $courseId, |
||
1268 | $sessionId, |
||
1269 | $groupId, |
||
1270 | ), |
||
1271 | ), |
||
1272 | ); |
||
1273 | } |
||
1274 | |||
1275 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
1276 | $conditions = array( |
||
1277 | 'where' => array( |
||
1278 | 'c_id = ? AND session_id = ? AND user_id = ?' => array( |
||
1279 | $courseId, |
||
1280 | $sessionId, |
||
1281 | $this->userId, |
||
1282 | ), |
||
1283 | ), |
||
1284 | ); |
||
1285 | } |
||
1286 | } |
||
1287 | |||
1288 | if (!empty($dateRange)) { |
||
1289 | $dateStart = date_create($dateRange['search_meeting_start']); |
||
1290 | $dateStart = date_format($dateStart, 'Y-m-d H:i:s'); |
||
1291 | $dateEnd = date_create($dateRange['search_meeting_end']); |
||
1292 | $dateEnd = $dateEnd->add(new DateInterval('P1D')); |
||
1293 | $dateEnd = date_format($dateEnd, 'Y-m-d H:i:s'); |
||
1294 | |||
1295 | $conditions = array( |
||
1296 | 'where' => array( |
||
1297 | 'created_at BETWEEN ? AND ? ' => array($dateStart, $dateEnd), |
||
1298 | ), |
||
1299 | ); |
||
1300 | } |
||
1301 | |||
1302 | $row = Database::select( |
||
1303 | 'count(*) as count', |
||
1304 | $this->table, |
||
1305 | $conditions, |
||
1306 | 'first' |
||
1307 | ); |
||
1308 | |||
1309 | return $row['count']; |
||
1310 | } |
||
1311 | |||
1312 | /** |
||
1313 | * @param array $meeting |
||
1314 | * |
||
1315 | * @return string |
||
1316 | */ |
||
1317 | public function endUrl($meeting) |
||
1318 | { |
||
1319 | if (!isset($meeting['id'])) { |
||
1320 | return ''; |
||
1321 | } |
||
1322 | |||
1323 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id']; |
||
1324 | } |
||
1325 | |||
1326 | /** |
||
1327 | * Closes a meeting (usually when the user click on the close button from |
||
1328 | * the conferences listing. |
||
1329 | * |
||
1330 | * @param string The internal ID of the meeting (id field for this meeting) |
||
1331 | * @param string $courseCode |
||
1332 | * |
||
1333 | * @return void |
||
1334 | * @assert (0) === false |
||
1335 | */ |
||
1336 | public function endMeeting($id, $courseCode = null) |
||
1337 | { |
||
1338 | if (empty($id)) { |
||
1339 | return false; |
||
1340 | } |
||
1341 | |||
1342 | $meetingData = Database::select( |
||
1343 | '*', |
||
1344 | $this->table, |
||
1345 | array('where' => array('id = ?' => array($id))), |
||
1346 | 'first' |
||
1347 | ); |
||
1348 | $manager = $this->isConferenceManager(); |
||
1349 | if ($manager) { |
||
1350 | $pass = $meetingData['moderator_pw']; |
||
1351 | } else { |
||
1352 | $pass = $meetingData['attendee_pw']; |
||
1353 | } |
||
1354 | |||
1355 | Event::addEvent( |
||
1356 | 'bbb_end_meeting', |
||
1357 | 'meeting_id', |
||
1358 | (int) $id, |
||
1359 | null, |
||
1360 | api_get_user_id(), |
||
1361 | api_get_course_int_id(), |
||
1362 | api_get_session_id() |
||
1363 | ); |
||
1364 | |||
1365 | $endParams = array( |
||
1366 | 'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end. |
||
1367 | 'password' => $pass, // REQUIRED - Must match moderator pass for meeting. |
||
1368 | ); |
||
1369 | $this->api->endMeetingWithXmlResponseArray($endParams); |
||
1370 | Database::update( |
||
1371 | $this->table, |
||
1372 | array('status' => 0, 'closed_at' => api_get_utc_datetime()), |
||
1373 | array('id = ? ' => $id) |
||
1374 | ); |
||
1375 | |||
1376 | // Update users with in_at y ou_at field equal |
||
1377 | $roomTable = Database::get_main_table('plugin_bbb_room'); |
||
1378 | $conditions['where'] = ['meeting_id=? AND in_at=out_at AND close=?' => [$id, BBBPlugin::ROOM_OPEN]]; |
||
1379 | $roomList = Database::select( |
||
1380 | '*', |
||
1381 | $roomTable, |
||
1382 | $conditions |
||
1383 | ); |
||
1384 | |||
1385 | foreach ($roomList as $roomDB) { |
||
1386 | $roomId = $roomDB['id']; |
||
1387 | if (!empty($roomId)) { |
||
1388 | Database::update( |
||
1389 | $roomTable, |
||
1390 | ['out_at' => api_get_utc_datetime(), 'close' => BBBPlugin::ROOM_CLOSE], |
||
1391 | ['id = ? ' => $roomId] |
||
1392 | ); |
||
1393 | } |
||
1394 | } |
||
1395 | |||
1396 | // Close all meeting rooms with meeting ID |
||
1397 | Database::update( |
||
1398 | $roomTable, |
||
1399 | ['close' => BBBPlugin::ROOM_CLOSE], |
||
1400 | ['meeting_id = ? ' => $id] |
||
1401 | ); |
||
1402 | } |
||
1403 | |||
1404 | /** |
||
1405 | * @param array $meeting |
||
1406 | * @param array $record |
||
1407 | * |
||
1408 | * @return string |
||
1409 | */ |
||
1410 | public function addToCalendarUrl($meeting, $record = []) |
||
1411 | { |
||
1412 | $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : ''; |
||
1413 | |||
1414 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams( |
||
1415 | ).'&action=add_to_calendar&id='.$meeting['id'].'&start='.api_strtotime($meeting['created_at']).'&url='.$url; |
||
1416 | } |
||
1417 | |||
1418 | /** |
||
1419 | * @param int $meetingId |
||
1420 | * @param string $videoUrl |
||
1421 | * |
||
1422 | * @return bool|int |
||
1423 | */ |
||
1424 | public function updateMeetingVideoUrl($meetingId, $videoUrl) |
||
1425 | { |
||
1426 | return Database::update( |
||
1427 | 'plugin_bbb_meeting', |
||
1428 | ['video_url' => $videoUrl], |
||
1429 | ['id = ?' => intval($meetingId)] |
||
1430 | ); |
||
1431 | } |
||
1432 | |||
1433 | /** |
||
1434 | * @param int $meetingId |
||
1435 | * @param string $formatType |
||
1436 | * @param string $resourceUrl |
||
1437 | * |
||
1438 | * @return bool|int |
||
1439 | */ |
||
1440 | public function insertMeetingFormat(int $meetingId, string $formatType, string $resourceUrl) |
||
1441 | { |
||
1442 | $em = Database::getManager(); |
||
1443 | $sm = $em->getConnection()->getSchemaManager(); |
||
1444 | if ($sm->tablesExist('plugin_bbb_meeting_format')) { |
||
1445 | return Database::insert( |
||
1446 | 'plugin_bbb_meeting_format', |
||
1447 | [ |
||
1448 | 'format_type' => $formatType, |
||
1449 | 'resource_url' => $resourceUrl, |
||
1450 | 'meeting_id' => $meetingId |
||
1451 | ] |
||
1452 | ); |
||
1453 | } |
||
1454 | |||
1455 | } |
||
1456 | |||
1457 | /** |
||
1458 | * Force the course, session and/or group IDs |
||
1459 | * |
||
1460 | * @param string $courseCode |
||
1461 | * @param int $sessionId |
||
1462 | * @param int $groupId |
||
1463 | */ |
||
1464 | public function forceCIdReq($courseCode, $sessionId = 0, $groupId = 0) |
||
1465 | { |
||
1466 | $this->courseCode = $courseCode; |
||
1467 | $this->sessionId = (int) $sessionId; |
||
1468 | $this->groupId = (int) $groupId; |
||
1469 | } |
||
1470 | |||
1471 | /** |
||
1472 | * @param array $meetingInfo |
||
1473 | * @param array $recordInfo |
||
1474 | * @param bool $isGlobal |
||
1475 | * @param bool $isAdminReport |
||
1476 | * |
||
1477 | * @return array |
||
1478 | */ |
||
1479 | private function getActionLinks( |
||
1480 | $meetingInfo, |
||
1481 | $recordInfo, |
||
1482 | $isGlobal = false, |
||
1483 | $isAdminReport = false |
||
1484 | ) { |
||
1485 | $isVisible = $meetingInfo['visibility'] != 0; |
||
1486 | $linkVisibility = $isVisible |
||
1487 | ? Display::url( |
||
1488 | Display::return_icon('visible.png', get_lang('MakeInvisible')), |
||
1489 | $this->unPublishUrl($meetingInfo) |
||
1490 | ) |
||
1491 | : Display::url( |
||
1492 | Display::return_icon('invisible.png', get_lang('MakeVisible')), |
||
1493 | $this->publishUrl($meetingInfo) |
||
1494 | ); |
||
1495 | |||
1496 | $links = []; |
||
1497 | if ($this->plugin->get('allow_regenerate_recording') === 'true' && $meetingInfo['record'] == 1) { |
||
1498 | if (!empty($recordInfo)) { |
||
1499 | $links[] = Display::url( |
||
1500 | Display::return_icon('reload.png', get_lang('RegenerateRecord')), |
||
1501 | $this->regenerateRecordUrl($meetingInfo, $recordInfo) |
||
1502 | ); |
||
1503 | } else { |
||
1504 | $links[] = Display::url( |
||
1505 | Display::return_icon('reload.png', get_lang('RegenerateRecord')), |
||
1506 | $this->regenerateRecordUrlFromMeeting($meetingInfo) |
||
1507 | ); |
||
1508 | } |
||
1509 | } |
||
1510 | |||
1511 | if (empty($recordInfo)) { |
||
1512 | if (!$isAdminReport) { |
||
1513 | if ($meetingInfo['status'] == 0) { |
||
1514 | $links[] = Display::url( |
||
1515 | Display::return_icon('delete.png', get_lang('Delete')), |
||
1516 | $this->deleteRecordUrl($meetingInfo) |
||
1517 | ); |
||
1518 | $links[] = $linkVisibility; |
||
1519 | } |
||
1520 | |||
1521 | return $links; |
||
1522 | } else { |
||
1523 | $links[] = Display::url( |
||
1524 | Display::return_icon('course_home.png', get_lang('GoToCourse')), |
||
1525 | $this->getListingUrl($meetingInfo['c_id'], $meetingInfo['session_id'], $meetingInfo['group_id']) |
||
1526 | ); |
||
1527 | |||
1528 | return $links; |
||
1529 | } |
||
1530 | } |
||
1531 | |||
1532 | if (!$isGlobal) { |
||
1533 | $links[] = Display::url( |
||
1534 | Display::return_icon('link.gif', get_lang('UrlMeetingToShare')), |
||
1535 | $this->copyToRecordToLinkTool($meetingInfo) |
||
1536 | ); |
||
1537 | $links[] = Display::url( |
||
1538 | Display::return_icon('agenda.png', get_lang('AddToCalendar')), |
||
1539 | $this->addToCalendarUrl($meetingInfo, $recordInfo) |
||
1540 | ); |
||
1541 | } |
||
1542 | |||
1543 | $hide = $this->plugin->get('disable_download_conference_link') === 'true' ? true : false; |
||
1544 | |||
1545 | if ($hide == false) { |
||
1546 | if ($meetingInfo['has_video_m4v']) { |
||
1547 | $links[] = Display::url( |
||
1548 | Display::return_icon('save.png', get_lang('DownloadFile')), |
||
1549 | $recordInfo['playbackFormatUrl'].'/capture.m4v', |
||
1550 | ['target' => '_blank'] |
||
1551 | ); |
||
1552 | } else { |
||
1553 | $links[] = Display::url( |
||
1554 | Display::return_icon('save.png', get_lang('DownloadFile')), |
||
1555 | '#', |
||
1556 | [ |
||
1557 | 'id' => "btn-check-meeting-video-{$meetingInfo['id']}", |
||
1558 | 'class' => 'check-meeting-video', |
||
1559 | 'data-id' => $meetingInfo['id'], |
||
1560 | ] |
||
1561 | ); |
||
1562 | } |
||
1563 | } |
||
1564 | |||
1565 | |||
1566 | if (!$isAdminReport) { |
||
1567 | $links[] = Display::url( |
||
1568 | Display::return_icon('delete.png', get_lang('Delete')), |
||
1569 | $this->deleteRecordUrl($meetingInfo) |
||
1570 | ); |
||
1571 | $links[] = $linkVisibility; |
||
1572 | } else { |
||
1573 | $links[] = Display::url( |
||
1574 | Display::return_icon('course_home.png', get_lang('GoToCourse')), |
||
1575 | $this->getListingUrl($meetingInfo['c_id'], $meetingInfo['session_id'], $meetingInfo['group_id']) |
||
1576 | ); |
||
1577 | } |
||
1578 | |||
1579 | |||
1580 | return $links; |
||
1581 | } |
||
1582 | |||
1583 | /** |
||
1584 | * @param array $meeting |
||
1585 | * |
||
1586 | * @return string |
||
1587 | */ |
||
1588 | public function unPublishUrl($meeting) |
||
1589 | { |
||
1590 | if (!isset($meeting['id'])) { |
||
1591 | return null; |
||
1592 | } |
||
1593 | |||
1594 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams( |
||
1595 | ).'&action=unpublish&id='.$meeting['id']; |
||
1596 | } |
||
1597 | |||
1598 | /** |
||
1599 | * @param array $meeting |
||
1600 | * |
||
1601 | * @return string |
||
1602 | */ |
||
1603 | public function publishUrl($meeting) |
||
1604 | { |
||
1605 | if (!isset($meeting['id'])) { |
||
1606 | return ''; |
||
1607 | } |
||
1608 | |||
1609 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams( |
||
1610 | ).'&action=publish&id='.$meeting['id']; |
||
1611 | } |
||
1612 | |||
1613 | /** |
||
1614 | * @param array $meeting |
||
1615 | * @param array $recordInfo |
||
1616 | * |
||
1617 | * @return string |
||
1618 | */ |
||
1619 | public function regenerateRecordUrl($meeting, $recordInfo) |
||
1620 | { |
||
1621 | if ($this->plugin->get('allow_regenerate_recording') !== 'true') { |
||
1622 | return ''; |
||
1623 | } |
||
1624 | |||
1625 | if (!isset($meeting['id'])) { |
||
1626 | return ''; |
||
1627 | } |
||
1628 | |||
1629 | if (empty($recordInfo) || (!empty($recordInfo['recordId']) && !isset($recordInfo['recordId']))) { |
||
1630 | return ''; |
||
1631 | } |
||
1632 | |||
1633 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams(). |
||
1634 | '&action=regenerate_record&id='.$meeting['id'].'&record_id='.$recordInfo['recordId']; |
||
1635 | } |
||
1636 | |||
1637 | /** |
||
1638 | * @param array $meeting |
||
1639 | * |
||
1640 | * @return string |
||
1641 | */ |
||
1642 | public function regenerateRecordUrlFromMeeting($meeting) |
||
1643 | { |
||
1644 | if ($this->plugin->get('allow_regenerate_recording') !== 'true') { |
||
1645 | return ''; |
||
1646 | } |
||
1647 | |||
1648 | if (!isset($meeting['id'])) { |
||
1649 | return ''; |
||
1650 | } |
||
1651 | |||
1652 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams(). |
||
1653 | '&action=regenerate_record&id='.$meeting['id']; |
||
1654 | } |
||
1655 | |||
1656 | /** |
||
1657 | * @param array $meeting |
||
1658 | * |
||
1659 | * @return string |
||
1660 | */ |
||
1661 | public function deleteRecordUrl($meeting) |
||
1662 | { |
||
1663 | if (!isset($meeting['id'])) { |
||
1664 | return ''; |
||
1665 | } |
||
1666 | |||
1667 | return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams( |
||
1668 | ).'&action=delete_record&id='.$meeting['id']; |
||
1669 | } |
||
1670 | |||
1671 | /** |
||
1672 | * @param array $meeting |
||
1673 | * |
||
1674 | * @return string |
||
1675 | */ |
||
1676 | public function copyToRecordToLinkTool($meeting) |
||
1677 | { |
||
1678 | if (!isset($meeting['id'])) { |
||
1679 | return ''; |
||
1680 | } |
||
1681 | |||
1682 | return api_get_path(WEB_PLUGIN_PATH). |
||
1683 | 'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id']; |
||
1684 | } |
||
1685 | |||
1686 | /** |
||
1687 | * Function disabled |
||
1688 | */ |
||
1689 | public function publishMeeting($id) |
||
1690 | { |
||
1691 | //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt); |
||
1692 | if (empty($id)) { |
||
1693 | return false; |
||
1694 | } |
||
1695 | $id = intval($id); |
||
1696 | Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id)); |
||
1697 | |||
1698 | return true; |
||
1699 | } |
||
1700 | |||
1701 | /** |
||
1702 | * Function disabled |
||
1703 | */ |
||
1704 | public function unpublishMeeting($id) |
||
1705 | { |
||
1706 | //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt); |
||
1707 | if (empty($id)) { |
||
1708 | return false; |
||
1709 | } |
||
1710 | $id = intval($id); |
||
1711 | Database::update($this->table, array('visibility' => 0), array('id = ?' => $id)); |
||
1712 | |||
1713 | return true; |
||
1714 | } |
||
1715 | |||
1716 | /** |
||
1717 | * Get users online in the current course room. |
||
1718 | * |
||
1719 | * @return int The number of users currently connected to the videoconference |
||
1720 | * @assert () > -1 |
||
1721 | */ |
||
1722 | public function getUsersOnlineInCurrentRoom() |
||
1723 | { |
||
1724 | $courseId = api_get_course_int_id(); |
||
1725 | $sessionId = api_get_session_id(); |
||
1726 | |||
1727 | $conditions = array( |
||
1728 | 'where' => array( |
||
1729 | 'c_id = ? AND session_id = ? AND status = 1 AND access_url = ?' => array( |
||
1730 | $courseId, |
||
1731 | $sessionId, |
||
1732 | $this->accessUrl, |
||
1733 | ), |
||
1734 | ), |
||
1735 | ); |
||
1736 | |||
1737 | if ($this->hasGroupSupport()) { |
||
1738 | $groupId = api_get_group_id(); |
||
1739 | $conditions = array( |
||
1740 | 'where' => array( |
||
1741 | 'c_id = ? AND session_id = ? AND group_id = ? AND status = 1 AND access_url = ?' => array( |
||
1742 | $courseId, |
||
1743 | $sessionId, |
||
1744 | $groupId, |
||
1745 | $this->accessUrl, |
||
1746 | ), |
||
1747 | ), |
||
1748 | ); |
||
1749 | } |
||
1750 | |||
1751 | if ($this->isGlobalConferencePerUserEnabled()) { |
||
1752 | $conditions = array( |
||
1753 | 'where' => array( |
||
1754 | 'user_id = ? AND status = 1 AND access_url = ?' => array( |
||
1755 | $this->userId, |
||
1756 | $this->accessUrl, |
||
1757 | ), |
||
1758 | ), |
||
1759 | ); |
||
1760 | } |
||
1761 | |||
1762 | $meetingData = Database::select( |
||
1763 | '*', |
||
1764 | $this->table, |
||
1765 | $conditions, |
||
1766 | 'first' |
||
1767 | ); |
||
1768 | |||
1769 | if (empty($meetingData)) { |
||
1770 | return 0; |
||
1771 | } |
||
1772 | $pass = $meetingData['moderator_pw']; |
||
1773 | $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass)); |
||
1774 | if ($info === false) { |
||
1775 | //checking with the remote_id didn't work, so just in case and |
||
1776 | // to provide backwards support, check with the id |
||
1777 | $params = array( |
||
1778 | 'meetingId' => $meetingData['id'], |
||
1779 | // -- REQUIRED - The unique id for the meeting |
||
1780 | 'password' => $pass |
||
1781 | // -- REQUIRED - The moderator password for the meeting |
||
1782 | ); |
||
1783 | $info = $this->getMeetingInfo($params); |
||
1784 | } |
||
1785 | |||
1786 | if (!empty($info) && isset($info['participantCount'])) { |
||
1787 | return $info['participantCount']; |
||
1788 | } |
||
1789 | |||
1790 | return 0; |
||
1791 | } |
||
1792 | |||
1793 | /** |
||
1794 | * @param int $id |
||
1795 | * @param string $recordId |
||
1796 | * |
||
1797 | * @return bool |
||
1798 | */ |
||
1799 | public function regenerateRecording($id, $recordId = '') |
||
1800 | { |
||
1801 | if ($this->plugin->get('allow_regenerate_recording') !== 'true') { |
||
1802 | return false; |
||
1803 | } |
||
1804 | |||
1805 | if (empty($id)) { |
||
1806 | return false; |
||
1807 | } |
||
1808 | |||
1809 | $meetingData = Database::select( |
||
1810 | '*', |
||
1811 | $this->table, |
||
1812 | array('where' => array('id = ?' => array($id))), |
||
1813 | 'first' |
||
1814 | ); |
||
1815 | |||
1816 | Event::addEvent( |
||
1817 | 'bbb_regenerate_record', |
||
1818 | 'record_id', |
||
1819 | (int) $recordId, |
||
1820 | null, |
||
1821 | api_get_user_id(), |
||
1822 | api_get_course_int_id(), |
||
1823 | api_get_session_id() |
||
1824 | ); |
||
1825 | |||
1826 | // Check if there are recordings for this meeting |
||
1827 | $recordings = $this->api->getRecordings(['meetingId' => $meetingData['remote_id']]); |
||
1828 | if (!empty($recordings) && isset($recordings['messageKey']) && $recordings['messageKey'] === 'noRecordings') { |
||
1829 | // Regenerate the meeting id |
||
1830 | if (!empty($meetingData['internal_meeting_id'])) { |
||
1831 | return $this->api->generateRecording(['recordId' => $meetingData['internal_meeting_id']]); |
||
1832 | } |
||
1833 | |||
1834 | /*$pass = $this->getModMeetingPassword(); |
||
1835 | $info = $this->getMeetingInfo(['meetingId' => $meetingData['remote_id'], 'password' => $pass]); |
||
1836 | if (!empty($info) && isset($info['internalMeetingID'])) { |
||
1837 | return $this->api->generateRecording(['recordId' => $meetingData['internal_meeting_id']]); |
||
1838 | }*/ |
||
1839 | |||
1840 | return false; |
||
1841 | } else { |
||
1842 | if (!empty($recordings['records'])) { |
||
1843 | $recordExists = false; |
||
1844 | foreach ($recordings['records'] as $record) { |
||
1845 | if ($recordId == $record['recordId']) { |
||
1846 | $recordExists = true; |
||
1847 | break; |
||
1848 | } |
||
1849 | } |
||
1850 | |||
1851 | if ($recordExists) { |
||
1852 | return $this->api->generateRecording(['recordId' => $recordId]); |
||
1853 | } |
||
1854 | } |
||
1855 | } |
||
1856 | |||
1857 | return false; |
||
1858 | } |
||
1859 | |||
1860 | /** |
||
1861 | * Deletes a recording of a meeting |
||
1862 | * |
||
1863 | * @param int $id ID of the recording |
||
1864 | * |
||
1865 | * @return bool |
||
1866 | * |
||
1867 | * @assert () === false |
||
1868 | * @todo Also delete links and agenda items created from this recording |
||
1869 | */ |
||
1870 | public function deleteRecording($id) |
||
1871 | { |
||
1872 | if (empty($id)) { |
||
1873 | return false; |
||
1874 | } |
||
1875 | |||
1876 | $meetingData = Database::select( |
||
1877 | '*', |
||
1878 | $this->table, |
||
1879 | array('where' => array('id = ?' => array($id))), |
||
1880 | 'first' |
||
1881 | ); |
||
1882 | |||
1883 | Event::addEvent( |
||
1884 | 'bbb_delete_record', |
||
1885 | 'meeting_id', |
||
1886 | $id, |
||
1887 | null, |
||
1888 | api_get_user_id(), |
||
1889 | api_get_course_int_id(), |
||
1890 | api_get_session_id() |
||
1891 | ); |
||
1892 | |||
1893 | $delete = false; |
||
1894 | $recordings = []; |
||
1895 | // Check if there are recordings for this meeting |
||
1896 | if (!empty($meetingData['remote_id'])) { |
||
1897 | Event::addEvent( |
||
1898 | 'bbb_delete_record', |
||
1899 | 'remote_id', |
||
1900 | $meetingData['remote_id'], |
||
1901 | null, |
||
1902 | api_get_user_id(), |
||
1903 | api_get_course_int_id(), |
||
1904 | api_get_session_id() |
||
1905 | ); |
||
1906 | $recordings = $this->api->getRecordings(['meetingId' => $meetingData['remote_id']]); |
||
1907 | } |
||
1908 | if (!empty($recordings) && isset($recordings['messageKey']) && $recordings['messageKey'] == 'noRecordings') { |
||
1909 | $delete = true; |
||
1910 | } else { |
||
1911 | if (!empty($recordings['records'])) { |
||
1912 | $recordsToDelete = []; |
||
1913 | foreach ($recordings['records'] as $record) { |
||
1914 | $recordsToDelete[] = $record['recordId']; |
||
1915 | } |
||
1916 | $delete = true; |
||
1917 | if (!empty($recordsToDelete)) { |
||
1918 | $recordingParams = ['recordId' => implode(',', $recordsToDelete)]; |
||
1919 | Event::addEvent( |
||
1920 | 'bbb_delete_record', |
||
1921 | 'record_id_list', |
||
1922 | implode(',', $recordsToDelete), |
||
1923 | null, |
||
1924 | api_get_user_id(), |
||
1925 | api_get_course_int_id(), |
||
1926 | api_get_session_id() |
||
1927 | ); |
||
1928 | $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams); |
||
1929 | if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') { |
||
1930 | $delete = true; |
||
1931 | } |
||
1932 | } |
||
1933 | } |
||
1934 | } |
||
1935 | |||
1936 | if ($delete) { |
||
1937 | Database::delete( |
||
1938 | 'plugin_bbb_room', |
||
1939 | array('meeting_id = ?' => array($id)) |
||
1940 | ); |
||
1941 | |||
1942 | Database::delete( |
||
1943 | $this->table, |
||
1944 | array('id = ?' => array($id)) |
||
1945 | ); |
||
1946 | } |
||
1947 | |||
1948 | return $delete; |
||
1949 | } |
||
1950 | |||
1951 | /** |
||
1952 | * Creates a link in the links tool from the given videoconference recording |
||
1953 | * |
||
1954 | * @param int $id ID of the item in the plugin_bbb_meeting table |
||
1955 | * @param string Hash identifying the recording, as provided by the API |
||
1956 | * |
||
1957 | * @return mixed ID of the newly created link, or false on error |
||
1958 | * @assert (null, null) === false |
||
1959 | * @assert (1, null) === false |
||
1960 | * @assert (null, 'abcdefabcdefabcdefabcdef') === false |
||
1961 | */ |
||
1962 | public function copyRecordingToLinkTool($id) |
||
1963 | { |
||
1964 | if (empty($id)) { |
||
1965 | return false; |
||
1966 | } |
||
1967 | //$records = BigBlueButtonBN::getRecordingsUrl($id); |
||
1968 | $meetingData = Database::select( |
||
1969 | '*', |
||
1970 | $this->table, |
||
1971 | array('where' => array('id = ?' => array($id))), |
||
1972 | 'first' |
||
1973 | ); |
||
1974 | |||
1975 | $records = $this->api->getRecordingsWithXmlResponseArray( |
||
1976 | array('meetingId' => $meetingData['remote_id']) |
||
1977 | ); |
||
1978 | |||
1979 | if (!empty($records)) { |
||
1980 | if (isset($records['message']) && !empty($records['message'])) { |
||
1981 | if ($records['messageKey'] == 'noRecordings') { |
||
1982 | $recordArray[] = $this->plugin->get_lang('NoRecording'); |
||
1983 | } else { |
||
1984 | //$recordArray[] = $records['message']; |
||
1985 | } |
||
1986 | |||
1987 | return false; |
||
1988 | } else { |
||
1989 | $record = $records[0]; |
||
1990 | if (is_array($record) && isset($record['recordId'])) { |
||
1991 | $url = $record['playbackFormatUrl']; |
||
1992 | $link = new Link(); |
||
1993 | $params['url'] = $url; |
||
1994 | $params['title'] = $meetingData['meeting_name']; |
||
1995 | $id = $link->save($params); |
||
1996 | |||
1997 | return $id; |
||
1998 | } |
||
1999 | } |
||
2000 | } |
||
2001 | |||
2002 | return false; |
||
2003 | } |
||
2004 | |||
2005 | /** |
||
2006 | * Checks if the video conference server is running. |
||
2007 | * Function currently disabled (always returns 1) |
||
2008 | * @return bool True if server is running, false otherwise |
||
2009 | * @assert () === false |
||
2010 | */ |
||
2011 | public function isServerRunning() |
||
2012 | { |
||
2013 | return true; |
||
2014 | //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url); |
||
2015 | } |
||
2016 | |||
2017 | /** |
||
2018 | * Checks if the video conference plugin is properly configured |
||
2019 | * @return bool True if plugin has a host and a salt, false otherwise |
||
2020 | * @assert () === false |
||
2021 | */ |
||
2022 | public function isServerConfigured() |
||
2023 | { |
||
2024 | $host = $this->plugin->get('host'); |
||
2025 | |||
2026 | if (empty($host)) { |
||
2027 | return false; |
||
2028 | } |
||
2029 | |||
2030 | $salt = $this->plugin->get('salt'); |
||
2031 | |||
2032 | if (empty($salt)) { |
||
2033 | return false; |
||
2034 | } |
||
2035 | |||
2036 | return true; |
||
2037 | //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url); |
||
2038 | } |
||
2039 | |||
2040 | /** |
||
2041 | * Get active session in the all platform |
||
2042 | */ |
||
2043 | public function getActiveSessionsCount() |
||
2044 | { |
||
2045 | $meetingList = Database::select( |
||
2046 | 'count(id) as count', |
||
2047 | $this->table, |
||
2048 | array('where' => array('status = ? AND access_url = ?' => array(1, $this->accessUrl))), |
||
2049 | 'first' |
||
2050 | ); |
||
2051 | |||
2052 | return $meetingList['count']; |
||
2053 | } |
||
2054 | |||
2055 | /** |
||
2056 | * Get active session in the all platform |
||
2057 | * |
||
2058 | * @param boolean $allSites Parameter to indicate whether to get the result from all sites |
||
2059 | * |
||
2060 | * @return array |
||
2061 | */ |
||
2062 | public function getActiveSessions(bool $allSites = false): array |
||
2074 | ); |
||
2075 | } |
||
2076 | |||
2077 | /** |
||
2078 | * @param string $url |
||
2079 | */ |
||
2080 | public function redirectToBBB($url) |
||
2081 | { |
||
2082 | if (file_exists(__DIR__.'/../config.vm.php')) { |
||
2083 | // Using VM |
||
2084 | echo Display::url($this->plugin->get_lang('ClickToContinue'), $url); |
||
2085 | exit; |
||
2086 | } else { |
||
2087 | // Classic |
||
2088 | header("Location: $url"); |
||
2089 | exit; |
||
2090 | } |
||
2091 | } |
||
2092 | |||
2093 | /** |
||
2094 | * @return string |
||
2095 | */ |
||
2096 | public function getConferenceUrl() |
||
2097 | { |
||
2098 | return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams(); |
||
2099 | } |
||
2100 | |||
2101 | /** |
||
2102 | * Get the meeting info from DB by its name |
||
2103 | * |
||
2104 | * @param string $name |
||
2105 | * |
||
2106 | * @return array |
||
2107 | */ |
||
2108 | public function findMeetingByName($name) |
||
2109 | { |
||
2110 | $meetingData = Database::select( |
||
2111 | '*', |
||
2112 | 'plugin_bbb_meeting', |
||
2113 | array('where' => array('meeting_name = ? AND status = 1 ' => $name)), |
||
2114 | 'first' |
||
2115 | ); |
||
2116 | |||
2117 | return $meetingData; |
||
2118 | } |
||
2119 | |||
2120 | /** |
||
2121 | * Get the meeting info from DB by its name |
||
2122 | * |
||
2123 | * @param int $id |
||
2124 | * |
||
2125 | * @return array |
||
2126 | */ |
||
2127 | public function getMeeting($id) |
||
2128 | { |
||
2129 | $meetingData = Database::select( |
||
2130 | '*', |
||
2131 | 'plugin_bbb_meeting', |
||
2132 | array('where' => array('id = ?' => $id)), |
||
2133 | 'first' |
||
2134 | ); |
||
2135 | |||
2136 | return $meetingData; |
||
2137 | } |
||
2138 | |||
2139 | /** |
||
2140 | * Get the meeting info. |
||
2141 | * |
||
2142 | * @param int $id |
||
2143 | * |
||
2144 | * @return array |
||
2145 | */ |
||
2146 | public function getMeetingByRemoteId($id) |
||
2147 | { |
||
2148 | $meetingData = Database::select( |
||
2149 | '*', |
||
2150 | 'plugin_bbb_meeting', |
||
2151 | array('where' => array('remote_id = ?' => $id)), |
||
2152 | 'first' |
||
2153 | ); |
||
2154 | |||
2155 | return $meetingData; |
||
2156 | } |
||
2157 | |||
2158 | /** |
||
2159 | * @param int $meetingId |
||
2160 | * |
||
2161 | * @return array |
||
2162 | */ |
||
2163 | public function findConnectedMeetingParticipants($meetingId) |
||
2190 | } |
||
2191 | |||
2192 | /** |
||
2193 | * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated |
||
2194 | * |
||
2195 | * @param int $meetingId |
||
2196 | * |
||
2197 | * @return bool |
||
2198 | */ |
||
2199 | public function checkDirectMeetingVideoUrl($meetingId) |
||
2200 | { |
||
2201 | $meetingInfo = Database::select( |
||
2202 | '*', |
||
2203 | 'plugin_bbb_meeting', |
||
2204 | [ |
||
2205 | 'where' => ['id = ?' => intval($meetingId)], |
||
2206 | ], |
||
2207 | 'first' |
||
2208 | ); |
||
2209 | |||
2210 | if (!isset($meetingInfo['video_url'])) { |
||
2211 | return false; |
||
2212 | } |
||
2213 | |||
2214 | $hasCapture = SocialManager::verifyUrl($meetingInfo['video_url'].'/capture.m4v'); |
||
2215 | |||
2216 | if ($hasCapture) { |
||
2217 | return Database::update( |
||
2218 | 'plugin_bbb_meeting', |
||
2219 | ['has_video_m4v' => true], |
||
2220 | ['id = ?' => intval($meetingId)] |
||
2221 | ); |
||
2222 | } |
||
2223 | |||
2224 | return $hasCapture; |
||
2225 | } |
||
2226 | } |
||
2227 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.