bbb.lib.php 51 KB

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