bbb.lib.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class bbb
  5. * This script initiates a video conference session, calling the BigBlueButton
  6. * API
  7. * @package chamilo.plugin.bigbluebutton
  8. *
  9. * BigBlueButton-Chamilo connector class
  10. */
  11. //namespace Chamilo\Plugin\BBB;
  12. /**
  13. * Class bbb
  14. * @package Chamilo\Plugin\BBB
  15. */
  16. class bbb
  17. {
  18. public $url;
  19. public $salt;
  20. public $api;
  21. public $userCompleteName = '';
  22. public $protocol = 'http://';
  23. public $debug = false;
  24. public $logoutUrl = '';
  25. public $pluginEnabled = false;
  26. public $enableGlobalConference = false;
  27. public $enableGlobalConferencePerUser = false;
  28. public $isGlobalConference = false;
  29. public $groupSupport = false;
  30. public $userSupport = false;
  31. public $accessUrl = 1;
  32. public $userId = 0;
  33. public $plugin;
  34. private $courseCode;
  35. private $courseId;
  36. private $sessionId;
  37. private $groupId;
  38. private $maxUsersLimit;
  39. /**
  40. * Constructor (generates a connection to the API and the Chamilo settings
  41. * required for the connection to the video conference server)
  42. * @param string $host
  43. * @param string $salt
  44. * @param bool $isGlobalConference
  45. * @param int $isGlobalPerUser
  46. */
  47. public function __construct($host = '', $salt = '', $isGlobalConference = false, $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. // Initialize video server settings from global settings
  54. $this->plugin = BBBPlugin::create();
  55. $bbbPluginEnabled = $this->plugin->get('tool_enable');
  56. $bbb_host = !empty($host) ? $host : $this->plugin->get('host');
  57. $bbb_salt = !empty($salt) ? $salt : $this->plugin->get('salt');
  58. $this->logoutUrl = $this->getListingUrl();
  59. $this->table = Database::get_main_table('plugin_bbb_meeting');
  60. $this->enableGlobalConference = (bool) $this->plugin->get('enable_global_conference');
  61. $this->isGlobalConference = (bool) $isGlobalConference;
  62. $columns = Database::listTableColumns($this->table);
  63. $this->groupSupport = isset($columns['group_id']) ? true : false;
  64. $this->userSupport = isset($columns['user_id']) ? true : false;
  65. $this->accessUrl = api_get_current_access_url_id();
  66. if ($this->userSupport && !empty($isGlobalPerUser)) {
  67. $this->enableGlobalConferencePerUser = (bool) $this->plugin->get('enable_global_conference_per_user');
  68. $this->userId = $isGlobalPerUser;
  69. } else {
  70. $this->enableGlobalConferencePerUser = false;
  71. }
  72. if ($this->groupSupport) {
  73. // Plugin check
  74. $this->groupSupport = (bool) $this->plugin->get('enable_conference_in_course_groups');
  75. if ($this->groupSupport) {
  76. // Platform check
  77. $bbbSetting = api_get_setting('bbb_enable_conference_in_course_groups');
  78. $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
  79. if ($bbbSetting) {
  80. // Course check
  81. $courseInfo = api_get_course_info();
  82. if ($courseInfo) {
  83. $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups', $courseInfo['code']) === '1';
  84. }
  85. }
  86. }
  87. }
  88. $this->maxUsersLimit = $this->plugin->get('max_users_limit');
  89. if ($bbbPluginEnabled === 'true') {
  90. $userInfo = api_get_user_info();
  91. if (empty($userInfo) && !empty($isGlobalPerUser)) {
  92. // If we are following a link to a global "per user" conference
  93. // then generate a random guest name to join the conference
  94. // because there is no part of the process where we give a name
  95. $this->userCompleteName = 'Guest'.rand(1000, 9999);
  96. } else {
  97. $this->userCompleteName = $userInfo['complete_name'];
  98. }
  99. $this->salt = $bbb_salt;
  100. $info = parse_url($bbb_host);
  101. $this->url = $bbb_host.'/bigbluebutton/';
  102. if (isset($info['scheme'])) {
  103. $this->protocol = $info['scheme'].'://';
  104. $this->url = str_replace($this->protocol, '', $this->url);
  105. }
  106. // Setting BBB api
  107. define('CONFIG_SECURITY_SALT', $this->salt);
  108. define('CONFIG_SERVER_BASE_URL', $this->url);
  109. $this->api = new BigBlueButtonBN();
  110. $this->pluginEnabled = true;
  111. }
  112. }
  113. /**
  114. * Force the course, session and/or group IDs
  115. * @param string $courseCode
  116. * @param int $sessionId
  117. * @param int $groupId
  118. */
  119. public function forceCIdReq($courseCode, $sessionId = 0, $groupId = 0)
  120. {
  121. $this->courseCode = $courseCode;
  122. $this->sessionId = intval($sessionId);
  123. $this->groupId = intval($groupId);
  124. }
  125. /**
  126. * @return bool
  127. */
  128. public function isGlobalConferenceEnabled()
  129. {
  130. return $this->enableGlobalConference;
  131. }
  132. /**
  133. * @return bool
  134. */
  135. public function isGlobalConferencePerUserEnabled()
  136. {
  137. return $this->enableGlobalConferencePerUser;
  138. }
  139. /**
  140. * @return bool
  141. */
  142. public function isGlobalConference()
  143. {
  144. if ($this->isGlobalConferenceEnabled() === false) {
  145. return false;
  146. }
  147. return (bool) $this->isGlobalConference;
  148. }
  149. /**
  150. * @return bool
  151. */
  152. public function hasGroupSupport()
  153. {
  154. return $this->groupSupport;
  155. }
  156. /**
  157. * Checks whether a user is teacher in the current course
  158. * @return bool True if the user can be considered a teacher in this course, false otherwise
  159. */
  160. public function isConferenceManager()
  161. {
  162. if (api_is_coach() || api_is_platform_admin()) {
  163. return true;
  164. }
  165. if ($this->isGlobalConferencePerUserEnabled()) {
  166. $currentUserId = api_get_user_id();
  167. if ($this->userId === $currentUserId) {
  168. return true;
  169. } else {
  170. return false;
  171. }
  172. }
  173. $courseInfo = api_get_course_info();
  174. if (!empty($courseInfo)) {
  175. return api_is_course_admin();
  176. }
  177. return false;
  178. }
  179. /**
  180. * Gets the global limit of users in a video-conference room.
  181. * This value can be overridden by course-specific values
  182. * @return int Maximum number of users set globally
  183. */
  184. public function getMaxUsersLimit() {
  185. $limit = $this->maxUsersLimit;
  186. if ($limit <= 0) {
  187. $limit = 0;
  188. }
  189. $courseLimit = 0;
  190. $sessionLimit = 0;
  191. // Check the extra fields for this course and session
  192. // Session limit takes priority over course limit
  193. // Course limit takes priority over global limit
  194. if (!empty($this->courseId)) {
  195. $extraField = new ExtraField('course');
  196. $fieldId = $extraField->get_all(
  197. array('variable = ?' => 'plugin_bbb_course_users_limit')
  198. );
  199. $extraValue = new ExtraFieldValue('course');
  200. $value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId[0]['id']);
  201. if (!empty($value['value'])) {
  202. $courseLimit = $value['value'];
  203. }
  204. }
  205. if (!empty($this->sessionId)) {
  206. $extraField = new ExtraField('session');
  207. $fieldId = $extraField->get_all(
  208. array('variable = ?' => 'plugin_bbb_session_users_limit')
  209. );
  210. $extraValue = new ExtraFieldValue('session');
  211. $value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId[0]['id']);
  212. if (!empty($value['value'])) {
  213. $sessionLimit = $value['value'];
  214. }
  215. }
  216. if (!empty($sessionLimit)) {
  217. return $sessionLimit;
  218. } elseif (!empty($courseLimit)) {
  219. return $courseLimit;
  220. }
  221. return $limit;
  222. }
  223. /**
  224. * Sets the global limit of users in a video-conference room.
  225. * @param int Maximum number of users (globally)
  226. */
  227. public function setMaxUsersLimit($max) {
  228. if ($max < 0) {
  229. $max = 0;
  230. }
  231. $this->maxUsersLimit = intval($max);
  232. }
  233. /**
  234. * See this file in you BBB to set up default values
  235. * @param array $params Array of parameters that will be completed if not containing all expected variables
  236. /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
  237. *
  238. More record information:
  239. http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
  240. # Default maximum number of users a meeting can have.
  241. # Doesn't get enforced yet but is the default value when the create
  242. # API doesn't pass a value.
  243. defaultMaxUsers=20
  244. # Default duration of the meeting in minutes.
  245. # Current default is 0 (meeting doesn't end).
  246. defaultMeetingDuration=0
  247. # Remove the meeting from memory when the end API is called.
  248. # This allows 3rd-party apps to recycle the meeting right-away
  249. # instead of waiting for the meeting to expire (see below).
  250. removeMeetingWhenEnded=false
  251. # The number of minutes before the system removes the meeting from memory.
  252. defaultMeetingExpireDuration=1
  253. # The number of minutes the system waits when a meeting is created and when
  254. # a user joins. If after this period, a user hasn't joined, the meeting is
  255. # removed from memory.
  256. defaultMeetingCreateJoinDuration=5
  257. *
  258. * @return mixed
  259. */
  260. public function createMeeting($params)
  261. {
  262. $courseCode = api_get_course_id();
  263. $params['c_id'] = api_get_course_int_id();
  264. $params['session_id'] = api_get_session_id();
  265. if ($this->hasGroupSupport()) {
  266. $params['group_id'] = api_get_group_id();
  267. }
  268. if ($this->isGlobalConferencePerUserEnabled()) {
  269. $currentUserId = api_get_user_id();
  270. if ($this->userId === $currentUserId) {
  271. $params['user_id'] = $this->userId;
  272. }
  273. }
  274. $params['attendee_pw'] = isset($params['attendee_pw']) ? $params['attendee_pw'] : $this->getUserMeetingPassword();
  275. $attendeePassword = $params['attendee_pw'];
  276. $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
  277. $moderatorPassword = $params['moderator_pw'];
  278. $params['record'] = api_get_course_setting('big_blue_button_record_and_store', $courseCode) == 1 ? true : false;
  279. $max = api_get_course_setting('big_blue_button_max_students_allowed', $courseCode);
  280. $max = isset($max) ? $max : -1;
  281. $params['status'] = 1;
  282. // Generate a pseudo-global-unique-id to avoid clash of conferences on
  283. // the same BBB server with several Chamilo portals
  284. $params['remote_id'] = uniqid(true, true);
  285. // Each simultaneous conference room needs to have a different
  286. // voice_bridge composed of a 5 digits number, so generating a random one
  287. $params['voice_bridge'] = rand(10000, 99999);
  288. if ($this->debug) {
  289. error_log("enter create_meeting ".print_r($params, 1));
  290. }
  291. $params['created_at'] = api_get_utc_datetime();
  292. $params['access_url'] = $this->accessUrl;
  293. $id = Database::insert($this->table, $params);
  294. if ($id) {
  295. if ($this->debug) {
  296. error_log("create_meeting: $id ");
  297. }
  298. $meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : $this->getCurrentVideoConferenceName();
  299. $welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
  300. $record = isset($params['record']) && $params['record'] ? 'true' : 'false';
  301. $duration = isset($params['duration']) ? intval($params['duration']) : 0;
  302. // This setting currently limits the maximum conference duration,
  303. // to avoid lingering sessions on the video-conference server #6261
  304. $duration = 300;
  305. $bbbParams = array(
  306. 'meetingId' => $params['remote_id'], // REQUIRED
  307. 'meetingName' => $meetingName, // REQUIRED
  308. 'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee.
  309. 'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator.
  310. 'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize.
  311. 'dialNumber' => '', // The main number to call into. Optional.
  312. 'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required.
  313. 'webVoice' => '', // Alphanumeric to join voice. Optional.
  314. 'logoutUrl' => $this->logoutUrl,
  315. 'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
  316. 'record' => $record, // New. 'true' will tell BBB to record the meeting.
  317. 'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
  318. //'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
  319. );
  320. if ($this->debug) {
  321. error_log("create_meeting params: ".print_r($bbbParams, 1));
  322. }
  323. $status = false;
  324. $meeting = null;
  325. while ($status === false) {
  326. $result = $this->api->createMeetingWithXmlResponseArray(
  327. $bbbParams
  328. );
  329. if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
  330. if ($this->debug) {
  331. error_log(
  332. "create_meeting result: ".print_r($result, 1)
  333. );
  334. }
  335. $meeting = $this->joinMeeting($meetingName, true);
  336. return $meeting;
  337. }
  338. }
  339. return $this->logoutUrl;
  340. }
  341. }
  342. /**
  343. * Save a participant in a meeting room
  344. * @param int $meetingId
  345. * @param int $participantId
  346. * @return false|int The last inserted ID. Otherwise return false
  347. */
  348. public function saveParticipant($meetingId, $participantId)
  349. {
  350. return Database::insert(
  351. 'plugin_bbb_room',
  352. [
  353. 'meeting_id' => $meetingId,
  354. 'participant_id' => $participantId,
  355. 'in_at' => api_get_utc_datetime(),
  356. 'out_at' => api_get_utc_datetime()
  357. ]
  358. );
  359. }
  360. /**
  361. * Tells whether the given meeting exists and is running
  362. * (using course code as name)
  363. * @param string $meetingName Meeting name (usually the course code)
  364. *
  365. * @return bool True if meeting exists, false otherwise
  366. * @assert ('') === false
  367. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  368. */
  369. public function meetingExists($meetingName)
  370. {
  371. if (empty($meetingName)) {
  372. return false;
  373. }
  374. $courseId = api_get_course_int_id();
  375. $sessionId = api_get_session_id();
  376. $conditions = array(
  377. 'where' => array(
  378. 'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 AND access_url = ?' =>
  379. array($courseId, $sessionId, $meetingName, $this->accessUrl)
  380. )
  381. );
  382. if ($this->hasGroupSupport()) {
  383. $groupId = api_get_group_id();
  384. $conditions = array(
  385. 'where' => array(
  386. 'c_id = ? AND session_id = ? AND meeting_name = ? AND group_id = ? AND status = 1 AND access_url = ?' =>
  387. array($courseId, $sessionId, $meetingName, $groupId, $this->accessUrl)
  388. )
  389. );
  390. }
  391. $meetingData = Database::select(
  392. '*',
  393. $this->table,
  394. $conditions,
  395. 'first'
  396. );
  397. if ($this->debug) {
  398. error_log("meeting_exists ".print_r($meetingData, 1));
  399. }
  400. if (empty($meetingData)) {
  401. return false;
  402. } else {
  403. return true;
  404. }
  405. }
  406. /**
  407. * Returns a meeting "join" URL
  408. * @param string The name of the meeting (usually the course code)
  409. * @return mixed The URL to join the meeting, or false on error
  410. * @todo implement moderator pass
  411. * @assert ('') === false
  412. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  413. */
  414. public function joinMeeting($meetingName, $loop = false)
  415. {
  416. if (empty($meetingName)) {
  417. return false;
  418. }
  419. $manager = $this->isConferenceManager();
  420. if ($manager) {
  421. $pass = $this->getModMeetingPassword();
  422. } else {
  423. $pass = $this->getUserMeetingPassword();
  424. }
  425. $meetingData = Database::select(
  426. '*',
  427. $this->table,
  428. array('where' => array('meeting_name = ? AND status = 1 AND access_url = ?' => array($meetingName, $this->accessUrl))),
  429. 'first'
  430. );
  431. if (empty($meetingData) || !is_array($meetingData)) {
  432. if ($this->debug) {
  433. error_log("meeting does not exist: $meetingName");
  434. }
  435. return false;
  436. }
  437. $params = array(
  438. 'meetingId' => $meetingData['remote_id'],
  439. // -- REQUIRED - The unique id for the meeting
  440. 'password' => $this->getModMeetingPassword()
  441. // -- REQUIRED - The moderator password for the meeting
  442. );
  443. $status = false;
  444. $meetingInfoExists = false;
  445. while ($status === false) {
  446. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  447. if ($meetingIsRunningInfo === false) {
  448. //checking with the remote_id didn't work, so just in case and
  449. // to provide backwards support, check with the id
  450. $params = array(
  451. 'meetingId' => $meetingData['id'],
  452. // -- REQUIRED - The unique id for the meeting
  453. 'password' => $this->getModMeetingPassword()
  454. // -- REQUIRED - The moderator password for the meeting
  455. );
  456. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  457. }
  458. if ($this->debug) {
  459. error_log(print_r($meetingIsRunningInfo, 1));
  460. }
  461. if (strval($meetingIsRunningInfo['returncode']) == 'SUCCESS' &&
  462. isset($meetingIsRunningInfo['meetingName']) &&
  463. !empty($meetingIsRunningInfo['meetingName'])
  464. //strval($meetingIsRunningInfo['running']) == 'true'
  465. ) {
  466. $meetingInfoExists = true;
  467. }
  468. if ($this->debug) {
  469. error_log(
  470. "meeting is running: ".intval($meetingInfoExists)
  471. );
  472. }
  473. if ($meetingInfoExists) {
  474. $status = true;
  475. }
  476. if ($loop) {
  477. continue;
  478. } else {
  479. break;
  480. }
  481. }
  482. if ($meetingInfoExists) {
  483. $joinParams = array(
  484. 'meetingId' => $meetingData['remote_id'], // -- REQUIRED - A unique id for the meeting
  485. 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
  486. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  487. //'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  488. 'userID' => api_get_user_id(), //-- OPTIONAL - string
  489. 'webVoiceConf' => '' // -- OPTIONAL - string
  490. );
  491. $url = $this->api->getJoinMeetingURL($joinParams);
  492. $url = $this->protocol.$url;
  493. } else {
  494. $url = $this->logoutUrl;
  495. }
  496. if ($this->debug) {
  497. error_log("return url :".$url);
  498. }
  499. return $url;
  500. }
  501. /**
  502. * Get information about the given meeting
  503. * @param array ...?
  504. * @return mixed Array of information on success, false on error
  505. * @assert (array()) === false
  506. */
  507. public function getMeetingInfo($params)
  508. {
  509. try {
  510. $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
  511. if ($result == null) {
  512. if ($this->debug) {
  513. error_log("Failed to get any response. Maybe we can't contact the BBB server.");
  514. }
  515. } else {
  516. return $result;
  517. }
  518. } catch (Exception $e) {
  519. if ($this->debug) {
  520. error_log('Caught exception: ', $e->getMessage(), "\n");
  521. }
  522. }
  523. return false;
  524. }
  525. /**
  526. * @param int $courseId
  527. * @param int $sessionId
  528. * @param int $status
  529. *
  530. * @return array
  531. */
  532. public function getAllMeetingsInCourse($courseId, $sessionId, $status)
  533. {
  534. $conditions = array(
  535. 'where' => array(
  536. 'status = ? AND c_id = ? AND session_id = ? ' => array(
  537. $status,
  538. $courseId,
  539. $sessionId,
  540. ),
  541. ),
  542. );
  543. $meetingList = Database::select(
  544. '*',
  545. $this->table,
  546. $conditions
  547. );
  548. return $meetingList;
  549. }
  550. /**
  551. * Gets all the course meetings saved in the plugin_bbb_meeting table
  552. * @param int $courseId
  553. * @param int $sessionId
  554. * @param int $groupId
  555. * @param bool $isAdminReport Optional. Set to true then the report is for admins
  556. * @param array $dateRange Optional
  557. * @return array Array of current open meeting rooms
  558. */
  559. public function getMeetings(
  560. $courseId = 0,
  561. $sessionId = 0,
  562. $groupId = 0,
  563. $isAdminReport = false,
  564. $dateRange = []
  565. ) {
  566. $em = Database::getManager();
  567. $manager = $this->isConferenceManager();
  568. $conditions = [];
  569. if ($courseId || $sessionId || $groupId) {
  570. $conditions = array(
  571. 'where' => array(
  572. 'c_id = ? AND session_id = ? ' => array($courseId, $sessionId),
  573. ),
  574. );
  575. if ($this->hasGroupSupport()) {
  576. $conditions = array(
  577. 'where' => array(
  578. 'c_id = ? AND session_id = ? AND group_id = ? ' => array($courseId, $sessionId, $groupId)
  579. )
  580. );
  581. }
  582. }
  583. if (!empty($dateRange)) {
  584. $dateStart = date_create($dateRange['search_meeting_start']);
  585. $dateStart = date_format($dateStart, 'Y-m-d H:i:s');
  586. $dateEnd = date_create($dateRange['search_meeting_end']);
  587. $dateEnd = $dateEnd->add(new DateInterval('P1D'));
  588. $dateEnd = date_format($dateEnd, 'Y-m-d H:i:s');
  589. $conditions = array(
  590. 'where' => array(
  591. 'created_at BETWEEN ? AND ? ' => array($dateStart, $dateEnd),
  592. ),
  593. );
  594. }
  595. $meetingList = Database::select(
  596. '*',
  597. $this->table,
  598. $conditions
  599. );
  600. $isGlobal = $this->isGlobalConference();
  601. $newMeetingList = array();
  602. foreach ($meetingList as $meetingDB) {
  603. $item = array();
  604. $courseId = $meetingDB['c_id'];
  605. $courseInfo = api_get_course_info_by_id($courseId);
  606. $courseCode = $courseInfo['code'];
  607. if ($manager) {
  608. $pass = $this->getUserMeetingPassword($courseCode);
  609. } else {
  610. $pass = $this->getModMeetingPassword($courseCode);
  611. }
  612. $meetingBBB = $this->getMeetingInfo(
  613. [
  614. 'meetingId' => $meetingDB['remote_id'],
  615. 'password' => $pass
  616. ]
  617. );
  618. if ($meetingBBB === false) {
  619. //checking with the remote_id didn't work, so just in case and
  620. // to provide backwards support, check with the id
  621. $params = array(
  622. 'meetingId' => $meetingDB['id'],
  623. // -- REQUIRED - The unique id for the meeting
  624. 'password' => $pass
  625. // -- REQUIRED - The moderator password for the meeting
  626. );
  627. $meetingBBB = $this->getMeetingInfo($params);
  628. }
  629. if ($meetingDB['visibility'] == 0 && $this->isConferenceManager() === false) {
  630. continue;
  631. }
  632. $meetingBBB['end_url'] = $this->endUrl($meetingDB);
  633. if (isset($meetingBBB['returncode']) && (string) $meetingBBB['returncode'] == 'FAILED') {
  634. if ($meetingDB['status'] == 1 && $this->isConferenceManager()) {
  635. $this->endMeeting($meetingDB['id'], $courseCode);
  636. }
  637. } else {
  638. $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB);
  639. }
  640. if ($meetingDB['record'] == 1) {
  641. // backwards compatibility (when there was no remote ID)
  642. $mId = $meetingDB['remote_id'];
  643. if (empty($mId)) {
  644. $mId = $meetingDB['id'];
  645. }
  646. if (empty($mId)) {
  647. // if the id is still empty (should *never* occur as 'id' is
  648. // the table's primary key), skip this conference
  649. continue;
  650. }
  651. $record = [];
  652. if (empty($meetingDB['video_url'])) {
  653. $recordingParams = ['meetingId' => $mId];
  654. $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
  655. if (!empty($records)) {
  656. if (!isset($records['messageKey']) || $records['messageKey'] != 'noRecordings') {
  657. $record = end($records);
  658. if (!is_array($record) || !isset($record['recordId'])) {
  659. continue;
  660. }
  661. $this->updateMeetingVideoUrl($meetingDB['id'], $record['playbackFormatUrl']);
  662. if (!$this->isConferenceManager()) {
  663. $record = [];
  664. }
  665. }
  666. }
  667. } else {
  668. $record['playbackFormatUrl'] = $meetingDB['video_url'];
  669. }
  670. $recordLink = isset($record['playbackFormatUrl']) && !empty($record['playbackFormatUrl'])
  671. ? Display::url(
  672. $this->plugin->get_lang('ViewRecord'),
  673. $record['playbackFormatUrl'],
  674. ['target' => '_blank']
  675. )
  676. : get_lang('NoRecording');
  677. if ($isAdminReport) {
  678. $this->forceCIdReq($courseInfo['code'], $meetingDB['session_id'], $meetingDB['group_id']);
  679. }
  680. $actionLinks = $this->getActionLinks($meetingDB, $record, $isGlobal, $isAdminReport);
  681. $item['show_links'] = $recordLink;
  682. } else {
  683. $actionLinks = $this->getActionLinks($meetingDB, [], $isGlobal, $isAdminReport);
  684. $item['show_links'] = get_lang('NoRecording');
  685. }
  686. $item['action_links'] = implode(PHP_EOL, $actionLinks);
  687. $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
  688. // created_at
  689. $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
  690. $item['publish_url'] = $this->publishUrl($meetingDB);
  691. $item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
  692. if ($meetingDB['status'] == 1) {
  693. $joinParams = array(
  694. 'meetingId' => $meetingDB['remote_id'], //-- REQUIRED - A unique id for the meeting
  695. 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
  696. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  697. 'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  698. 'userID' => '', // -- OPTIONAL - string
  699. 'webVoiceConf' => '' // -- OPTIONAL - string
  700. );
  701. $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
  702. }
  703. $item = array_merge($item, $meetingDB, $meetingBBB);
  704. $item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']);
  705. $item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']);
  706. $newMeetingList[] = $item;
  707. }
  708. return $newMeetingList;
  709. }
  710. /**
  711. * Function disabled
  712. */
  713. public function publishMeeting($id)
  714. {
  715. //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
  716. if (empty($id)) {
  717. return false;
  718. }
  719. $id = intval($id);
  720. Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
  721. return true;
  722. }
  723. /**
  724. * Function disabled
  725. */
  726. public function unpublishMeeting($id)
  727. {
  728. //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
  729. if (empty($id)) {
  730. return false;
  731. }
  732. $id = intval($id);
  733. Database::update($this->table, array('visibility' => 0), array('id = ?' => $id));
  734. return true;
  735. }
  736. /**
  737. * Closes a meeting (usually when the user click on the close button from
  738. * the conferences listing.
  739. * @param string The internal ID of the meeting (id field for this meeting)
  740. * @param string $courseCode
  741. *
  742. * @return void
  743. * @assert (0) === false
  744. */
  745. public function endMeeting($id, $courseCode = null)
  746. {
  747. if (empty($id)) {
  748. return false;
  749. }
  750. $meetingData = Database::select(
  751. '*',
  752. $this->table,
  753. array('where' => array('id = ?' => array($id))),
  754. 'first'
  755. );
  756. $manager = $this->isConferenceManager();
  757. if ($manager) {
  758. $pass = $this->getUserMeetingPassword($courseCode);
  759. } else {
  760. $pass = $this->getModMeetingPassword($courseCode);
  761. }
  762. $endParams = array(
  763. 'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end.
  764. 'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
  765. );
  766. $this->api->endMeetingWithXmlResponseArray($endParams);
  767. Database::update(
  768. $this->table,
  769. array('status' => 0, 'closed_at' => api_get_utc_datetime()),
  770. array('id = ? ' => $id)
  771. );
  772. }
  773. /**
  774. * Gets the password for a specific meeting for the current user
  775. * @param string $courseCode
  776. * @return string A moderator password if user is teacher, or the course code otherwise
  777. *
  778. */
  779. public function getUserMeetingPassword($courseCode = null)
  780. {
  781. if ($this->isGlobalConferencePerUserEnabled()) {
  782. return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
  783. }
  784. if ($this->isGlobalConference()) {
  785. return 'url_'.api_get_current_access_url_id();
  786. }
  787. $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
  788. return $courseCode;
  789. }
  790. /**
  791. * Generated a moderator password for the meeting
  792. * @param string $courseCode
  793. *
  794. * @return string A password for the moderation of the videoconference
  795. */
  796. public function getModMeetingPassword($courseCode = null)
  797. {
  798. if ($this->isGlobalConferencePerUserEnabled()) {
  799. return 'url_'.$this->userId.'_'.api_get_current_access_url_id().'_mod';
  800. }
  801. if ($this->isGlobalConference()) {
  802. return 'url_'.api_get_current_access_url_id().'_mod';
  803. }
  804. $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
  805. return $courseCode.'mod';
  806. }
  807. /**
  808. * Get users online in the current course room
  809. * @return int The number of users currently connected to the videoconference
  810. * @assert () > -1
  811. */
  812. public function getUsersOnlineInCurrentRoom()
  813. {
  814. $courseId = api_get_course_int_id();
  815. $sessionId = api_get_session_id();
  816. $conditions = array(
  817. 'where' => array(
  818. 'c_id = ? AND session_id = ? AND status = 1 AND access_url = ?' => array(
  819. $courseId,
  820. $sessionId,
  821. $this->accessUrl
  822. ),
  823. ),
  824. );
  825. if ($this->hasGroupSupport()) {
  826. $groupId = api_get_group_id();
  827. $conditions = array(
  828. 'where' => array(
  829. 'c_id = ? AND session_id = ? AND group_id = ? AND status = 1 AND access_url = ?' => array(
  830. $courseId,
  831. $sessionId,
  832. $groupId,
  833. $this->accessUrl
  834. ),
  835. ),
  836. );
  837. }
  838. if ($this->isGlobalConferencePerUserEnabled()) {
  839. $conditions = array(
  840. 'where' => array(
  841. 'user_id = ? AND status = 1 AND access_url = ?' => array(
  842. $this->userId,
  843. $this->accessUrl
  844. ),
  845. ),
  846. );
  847. }
  848. $meetingData = Database::select(
  849. '*',
  850. $this->table,
  851. $conditions,
  852. 'first'
  853. );
  854. if (empty($meetingData)) {
  855. return 0;
  856. }
  857. $pass = $this->getModMeetingPassword();
  858. $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass));
  859. if ($info === false) {
  860. //checking with the remote_id didn't work, so just in case and
  861. // to provide backwards support, check with the id
  862. $params = array(
  863. 'meetingId' => $meetingData['id'],
  864. // -- REQUIRED - The unique id for the meeting
  865. 'password' => $pass
  866. // -- REQUIRED - The moderator password for the meeting
  867. );
  868. $info = $this->getMeetingInfo($params);
  869. }
  870. if (!empty($info) && isset($info['participantCount'])) {
  871. return $info['participantCount'];
  872. }
  873. return 0;
  874. }
  875. /**
  876. * Deletes a previous recording of a meeting
  877. * @param int $id ID of the recording
  878. * @return array ?
  879. * @assert () === false
  880. * @todo Also delete links and agenda items created from this recording
  881. */
  882. public function deleteRecording($id)
  883. {
  884. if (empty($id)) {
  885. return false;
  886. }
  887. $meetingData = Database::select(
  888. '*',
  889. $this->table,
  890. array('where' => array('id = ?' => array($id))),
  891. 'first'
  892. );
  893. $recordingParams = array(
  894. /*
  895. * NOTE: Set the recordId below to a valid id after you have
  896. * created a recorded meeting, and received a real recordID
  897. * back from your BBB server using the
  898. * getRecordingsWithXmlResponseArray method.
  899. */
  900. // REQUIRED - We have to know which recording:
  901. 'recordId' => $meetingData['remote_id'],
  902. );
  903. $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
  904. if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
  905. Database::delete(
  906. 'plugin_bbb_room',
  907. array('meeting_id = ?' => array($id))
  908. );
  909. Database::delete(
  910. $this->table,
  911. array('id = ?' => array($id))
  912. );
  913. }
  914. return $result;
  915. }
  916. /**
  917. * Creates a link in the links tool from the given videoconference recording
  918. * @param int $id ID of the item in the plugin_bbb_meeting table
  919. * @param string Hash identifying the recording, as provided by the API
  920. * @return mixed ID of the newly created link, or false on error
  921. * @assert (null, null) === false
  922. * @assert (1, null) === false
  923. * @assert (null, 'abcdefabcdefabcdefabcdef') === false
  924. */
  925. public function copyRecordingToLinkTool($id)
  926. {
  927. if (empty($id)) {
  928. return false;
  929. }
  930. //$records = BigBlueButtonBN::getRecordingsUrl($id);
  931. $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
  932. $records = $this->api->getRecordingsWithXmlResponseArray(array('meetingId' => $meetingData['remote_id']));
  933. if (!empty($records)) {
  934. if (isset($records['message']) && !empty($records['message'])) {
  935. if ($records['messageKey'] == 'noRecordings') {
  936. $recordArray[] = $this->plugin->get_lang('NoRecording');
  937. } else {
  938. //$recordArray[] = $records['message'];
  939. }
  940. return false;
  941. } else {
  942. $record = $records[0];
  943. if (is_array($record) && isset($record['recordId'])) {
  944. $url = $record['playbackFormatUrl'];
  945. $link = new Link();
  946. $params['url'] = $url;
  947. $params['title'] = $meetingData['meeting_name'];
  948. $id = $link->save($params);
  949. return $id;
  950. }
  951. }
  952. }
  953. return false;
  954. }
  955. /**
  956. * Checks if the video conference server is running.
  957. * Function currently disabled (always returns 1)
  958. * @return bool True if server is running, false otherwise
  959. * @assert () === false
  960. */
  961. public function isServerRunning()
  962. {
  963. return true;
  964. //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
  965. }
  966. /**
  967. * Get active session in the all platform
  968. */
  969. public function getActiveSessionsCount()
  970. {
  971. $meetingList = Database::select(
  972. 'count(id) as count',
  973. $this->table,
  974. array('where' => array('status = ? AND access_url = ?' => array(1, $this->accessUrl))),
  975. 'first'
  976. );
  977. return $meetingList['count'];
  978. }
  979. /**
  980. * @param string $url
  981. */
  982. public function redirectToBBB($url)
  983. {
  984. if (file_exists(__DIR__.'/../config.vm.php')) {
  985. // Using VM
  986. echo Display::url($this->plugin->get_lang('ClickToContinue'), $url);
  987. exit;
  988. } else {
  989. // Classic
  990. header("Location: $url");
  991. exit;
  992. }
  993. }
  994. /**
  995. * @return string
  996. */
  997. public function getUrlParams()
  998. {
  999. if (empty($this->courseCode)) {
  1000. if ($this->isGlobalConferencePerUserEnabled()) {
  1001. return 'global=1&user_id='.$this->userId;
  1002. }
  1003. if ($this->isGlobalConference()) {
  1004. return 'global=1';
  1005. }
  1006. return '';
  1007. }
  1008. return http_build_query([
  1009. 'cidReq' => $this->courseCode,
  1010. 'id_session' => $this->sessionId,
  1011. 'gidReq' => $this->groupId
  1012. ]);
  1013. }
  1014. /**
  1015. * @return string
  1016. */
  1017. public function getCurrentVideoConferenceName()
  1018. {
  1019. if ($this->isGlobalConferencePerUserEnabled()) {
  1020. return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
  1021. }
  1022. if ($this->isGlobalConference()) {
  1023. return 'url_'.api_get_current_access_url_id();
  1024. }
  1025. if ($this->hasGroupSupport()) {
  1026. return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
  1027. }
  1028. return api_get_course_id().'-'.api_get_session_id();
  1029. }
  1030. /**
  1031. * @return string
  1032. */
  1033. public function getConferenceUrl()
  1034. {
  1035. return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
  1036. }
  1037. /**
  1038. * @return string
  1039. */
  1040. public function getListingUrl()
  1041. {
  1042. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams();
  1043. }
  1044. /**
  1045. * @param array $meeting
  1046. * @return string
  1047. */
  1048. public function endUrl($meeting)
  1049. {
  1050. if (!isset($meeting['id'])) {
  1051. return '';
  1052. }
  1053. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id'];
  1054. }
  1055. /**
  1056. * @param array $meeting
  1057. * @param array $record
  1058. * @return string
  1059. */
  1060. public function addToCalendarUrl($meeting, $record = [])
  1061. {
  1062. $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
  1063. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=add_to_calendar&id='.$meeting['id'].'&start='.api_strtotime($meeting['created_at']).'&url='.$url;
  1064. }
  1065. /**
  1066. * @param array $meeting
  1067. * @return string
  1068. */
  1069. public function publishUrl($meeting)
  1070. {
  1071. if (!isset($meeting['id'])) {
  1072. return '';
  1073. }
  1074. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=publish&id='.$meeting['id'];
  1075. }
  1076. /**
  1077. * @param array $meeting
  1078. * @return string
  1079. */
  1080. public function unPublishUrl($meeting)
  1081. {
  1082. if (!isset($meeting['id'])) {
  1083. return null;
  1084. }
  1085. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=unpublish&id='.$meeting['id'];
  1086. }
  1087. /**
  1088. * @param array $meeting
  1089. * @return string
  1090. */
  1091. public function deleteRecordUrl($meeting)
  1092. {
  1093. if (!isset($meeting['id'])) {
  1094. return '';
  1095. }
  1096. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=delete_record&id='.$meeting['id'];
  1097. }
  1098. /**
  1099. * @param array $meeting
  1100. * @return string
  1101. */
  1102. public function copyToRecordToLinkTool($meeting)
  1103. {
  1104. if (!isset($meeting['id'])) {
  1105. return '';
  1106. }
  1107. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
  1108. }
  1109. /**
  1110. * Get the meeting info from DB by its name
  1111. * @param string $name
  1112. * @return array
  1113. */
  1114. public function findMeetingByName($name)
  1115. {
  1116. $meetingData = Database::select(
  1117. '*',
  1118. 'plugin_bbb_meeting',
  1119. array('where' => array('meeting_name = ? AND status = 1 ' => $name)),
  1120. 'first'
  1121. );
  1122. return $meetingData;
  1123. }
  1124. /**
  1125. * @param int $meetingId
  1126. * @return array
  1127. */
  1128. public function findMeetingParticipants($meetingId)
  1129. {
  1130. $em = Database::getManager();
  1131. $meetingData = Database::select(
  1132. '*',
  1133. 'plugin_bbb_room',
  1134. array('where' => array('meeting_id = ?' => intval($meetingId)))
  1135. );
  1136. $participantIds = [];
  1137. $return = [];
  1138. foreach ($meetingData as $participantInfo) {
  1139. if (in_array($participantInfo['participant_id'], $participantIds)) {
  1140. continue;
  1141. }
  1142. $participantIds[] = $participantInfo['participant_id'];
  1143. $return[] = [
  1144. 'id' => $participantInfo['id'],
  1145. 'meeting_id' => $participantInfo['meeting_id'],
  1146. 'participant' => $em->find('ChamiloUserBundle:User', $participantInfo['participant_id']),
  1147. 'in_at' => $participantInfo['in_at'],
  1148. 'out_at' => $participantInfo['out_at']
  1149. ];
  1150. }
  1151. return $return;
  1152. }
  1153. /**
  1154. * @param array $meetingInfo
  1155. * @param array $recordInfo
  1156. * @param bool $isGlobal
  1157. * @param bool $isAdminReport
  1158. * @return array
  1159. */
  1160. private function getActionLinks($meetingInfo, $recordInfo, $isGlobal = false, $isAdminReport = false)
  1161. {
  1162. $isVisible = $meetingInfo['visibility'] != 0;
  1163. $linkVisibility = $isVisible
  1164. ? Display::url(
  1165. Display::return_icon('visible.png', get_lang('MakeInvisible')),
  1166. $this->unPublishUrl($meetingInfo)
  1167. )
  1168. : Display::url(
  1169. Display::return_icon('invisible.png', get_lang('MakeVisible')),
  1170. $this->publishUrl($meetingInfo)
  1171. );
  1172. $links = [];
  1173. if (empty($recordInfo)) {
  1174. if (!$isAdminReport) {
  1175. $links[] = Display::url(
  1176. Display::return_icon('delete.png', get_lang('Delete')),
  1177. $this->deleteRecordUrl($meetingInfo)
  1178. );
  1179. $links[] = $linkVisibility;
  1180. return $links;
  1181. } else {
  1182. $links[] = Display::url(
  1183. Display::return_icon('course_home.png', get_lang('GoToCourse')),
  1184. $this->getListingUrl()
  1185. );
  1186. return $links;
  1187. }
  1188. }
  1189. if (!$isGlobal) {
  1190. $links[] = Display::url(
  1191. Display::return_icon('link.gif', get_lang('UrlMeetingToShare')),
  1192. $this->copyToRecordToLinkTool($meetingInfo)
  1193. );
  1194. $links[] = Display::url(
  1195. Display::return_icon('agenda.png', get_lang('AddToCalendar')),
  1196. $this->addToCalendarUrl($meetingInfo, $recordInfo)
  1197. );
  1198. }
  1199. if ($meetingInfo['has_video_m4v']) {
  1200. $links[] = Display::url(
  1201. Display::return_icon('save.png', get_lang('DownloadFile')),
  1202. $recordInfo['playbackFormatUrl'].'/capture.m4v',
  1203. ['target' => '_blank']
  1204. );
  1205. } else {
  1206. $links[] = Display::url(
  1207. Display::return_icon('save.png', get_lang('DownloadFile')),
  1208. '#',
  1209. [
  1210. 'id' => "btn-check-meeting-video-{$meetingInfo['id']}",
  1211. 'class' => 'check-meeting-video',
  1212. 'data-id' => $meetingInfo['id']
  1213. ]
  1214. );
  1215. }
  1216. if (!$isAdminReport) {
  1217. $links[] = Display::url(
  1218. Display::return_icon('delete.png', get_lang('Delete')),
  1219. $this->deleteRecordUrl($meetingInfo)
  1220. );
  1221. $links[] = $linkVisibility;
  1222. } else {
  1223. $links[] = Display::url(
  1224. Display::return_icon('course_home.png', get_lang('GoToCourse')),
  1225. $this->getListingUrl()
  1226. );
  1227. }
  1228. return $links;
  1229. }
  1230. /**
  1231. * @param int $meetingId
  1232. * @param string $videoUrl
  1233. * @return bool|int
  1234. */
  1235. public function updateMeetingVideoUrl($meetingId, $videoUrl)
  1236. {
  1237. return Database::update(
  1238. 'plugin_bbb_meeting',
  1239. ['video_url' => $videoUrl],
  1240. ['id = ?' => intval($meetingId)]
  1241. );
  1242. }
  1243. /**
  1244. * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated
  1245. * @param int $meetingId
  1246. * @return bool
  1247. */
  1248. public function checkDirectMeetingVideoUrl($meetingId)
  1249. {
  1250. $meetingInfo = Database::select(
  1251. '*',
  1252. 'plugin_bbb_meeting',
  1253. [
  1254. 'where' => ['id = ?' => intval($meetingId)]
  1255. ],
  1256. 'first'
  1257. );
  1258. if (!isset($meetingInfo['video_url'])) {
  1259. return false;
  1260. }
  1261. $hasCapture = SocialManager::verifyUrl($meetingInfo['video_url'].'/capture.m4v');
  1262. if ($hasCapture) {
  1263. return Database::update(
  1264. 'plugin_bbb_meeting',
  1265. ['has_video_m4v' => true],
  1266. ['id = ?' => intval($meetingId)]
  1267. );
  1268. }
  1269. return $hasCapture;
  1270. }
  1271. }