bbb.lib.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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_plugin_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 ? 1 : 0;
  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. $params['closed_at'] = '';
  300. $id = Database::insert($this->table, $params);
  301. if ($id) {
  302. if ($this->debug) {
  303. error_log("create_meeting: $id ");
  304. }
  305. $meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : $this->getCurrentVideoConferenceName();
  306. $welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
  307. $record = isset($params['record']) && $params['record'] ? 'true' : 'false';
  308. $duration = isset($params['duration']) ? intval($params['duration']) : 0;
  309. // This setting currently limits the maximum conference duration,
  310. // to avoid lingering sessions on the video-conference server #6261
  311. $duration = 300;
  312. $bbbParams = array(
  313. 'meetingId' => $params['remote_id'], // REQUIRED
  314. 'meetingName' => $meetingName, // REQUIRED
  315. 'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee.
  316. 'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator.
  317. 'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize.
  318. 'dialNumber' => '', // The main number to call into. Optional.
  319. 'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required.
  320. 'webVoice' => '', // Alphanumeric to join voice. Optional.
  321. 'logoutUrl' => $this->logoutUrl,
  322. 'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
  323. 'record' => $record, // New. 'true' will tell BBB to record the meeting.
  324. 'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
  325. //'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
  326. );
  327. if ($this->debug) {
  328. error_log("create_meeting params: ".print_r($bbbParams, 1));
  329. }
  330. $status = false;
  331. $meeting = null;
  332. while ($status === false) {
  333. $result = $this->api->createMeetingWithXmlResponseArray(
  334. $bbbParams
  335. );
  336. if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
  337. if ($this->debug) {
  338. error_log(
  339. "create_meeting result: ".print_r($result, 1)
  340. );
  341. }
  342. $meeting = $this->joinMeeting($meetingName, true);
  343. return $meeting;
  344. }
  345. }
  346. return $this->logoutUrl;
  347. }
  348. }
  349. /**
  350. * Save a participant in a meeting room
  351. * @param int $meetingId
  352. * @param int $participantId
  353. * @return false|int The last inserted ID. Otherwise return false
  354. */
  355. public function saveParticipant($meetingId, $participantId)
  356. {
  357. return Database::insert(
  358. 'plugin_bbb_room',
  359. [
  360. 'meeting_id' => $meetingId,
  361. 'participant_id' => $participantId,
  362. 'in_at' => api_get_utc_datetime(),
  363. 'out_at' => api_get_utc_datetime()
  364. ]
  365. );
  366. }
  367. /**
  368. * Tells whether the given meeting exists and is running
  369. * (using course code as name)
  370. * @param string $meetingName Meeting name (usually the course code)
  371. *
  372. * @return bool True if meeting exists, false otherwise
  373. * @assert ('') === false
  374. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  375. */
  376. public function meetingExists($meetingName)
  377. {
  378. if (empty($meetingName)) {
  379. return false;
  380. }
  381. $courseId = api_get_course_int_id();
  382. $sessionId = api_get_session_id();
  383. $conditions = array(
  384. 'where' => array(
  385. 'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 AND access_url = ?' =>
  386. array($courseId, $sessionId, $meetingName, $this->accessUrl)
  387. )
  388. );
  389. if ($this->hasGroupSupport()) {
  390. $groupId = api_get_group_id();
  391. $conditions = array(
  392. 'where' => array(
  393. 'c_id = ? AND session_id = ? AND meeting_name = ? AND group_id = ? AND status = 1 AND access_url = ?' =>
  394. array(
  395. $courseId,
  396. $sessionId,
  397. $meetingName,
  398. $groupId,
  399. $this->accessUrl
  400. )
  401. )
  402. );
  403. }
  404. $meetingData = Database::select(
  405. '*',
  406. $this->table,
  407. $conditions,
  408. 'first'
  409. );
  410. if ($this->debug) {
  411. error_log("meeting_exists ".print_r($meetingData, 1));
  412. }
  413. if (empty($meetingData)) {
  414. return false;
  415. } else {
  416. return true;
  417. }
  418. }
  419. /**
  420. * Returns a meeting "join" URL
  421. * @param string The name of the meeting (usually the course code)
  422. * @return mixed The URL to join the meeting, or false on error
  423. * @todo implement moderator pass
  424. * @assert ('') === false
  425. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  426. */
  427. public function joinMeeting($meetingName, $loop = false)
  428. {
  429. if (empty($meetingName)) {
  430. return false;
  431. }
  432. $manager = $this->isConferenceManager();
  433. if ($manager) {
  434. $pass = $this->getModMeetingPassword();
  435. } else {
  436. $pass = $this->getUserMeetingPassword();
  437. }
  438. $meetingData = Database::select(
  439. '*',
  440. $this->table,
  441. array(
  442. 'where' => array(
  443. 'meeting_name = ? AND status = 1 AND access_url = ?' => array(
  444. $meetingName,
  445. $this->accessUrl
  446. )
  447. )
  448. ),
  449. 'first'
  450. );
  451. if (empty($meetingData) || !is_array($meetingData)) {
  452. if ($this->debug) {
  453. error_log("meeting does not exist: $meetingName");
  454. }
  455. return false;
  456. }
  457. $params = array(
  458. 'meetingId' => $meetingData['remote_id'],
  459. // -- REQUIRED - The unique id for the meeting
  460. 'password' => $this->getModMeetingPassword()
  461. // -- REQUIRED - The moderator password for the meeting
  462. );
  463. $status = false;
  464. $meetingInfoExists = false;
  465. while ($status === false) {
  466. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  467. if ($meetingIsRunningInfo === false) {
  468. //checking with the remote_id didn't work, so just in case and
  469. // to provide backwards support, check with the id
  470. $params = array(
  471. 'meetingId' => $meetingData['id'],
  472. // -- REQUIRED - The unique id for the meeting
  473. 'password' => $this->getModMeetingPassword()
  474. // -- REQUIRED - The moderator password for the meeting
  475. );
  476. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  477. }
  478. if ($this->debug) {
  479. error_log(print_r($meetingIsRunningInfo, 1));
  480. }
  481. if (strval($meetingIsRunningInfo['returncode']) == 'SUCCESS' &&
  482. isset($meetingIsRunningInfo['meetingName']) &&
  483. !empty($meetingIsRunningInfo['meetingName'])
  484. //strval($meetingIsRunningInfo['running']) == 'true'
  485. ) {
  486. $meetingInfoExists = true;
  487. }
  488. if ($this->debug) {
  489. error_log(
  490. "meeting is running: ".intval($meetingInfoExists)
  491. );
  492. }
  493. if ($meetingInfoExists) {
  494. $status = true;
  495. }
  496. if ($loop) {
  497. continue;
  498. } else {
  499. break;
  500. }
  501. }
  502. if ($meetingInfoExists) {
  503. $joinParams = array(
  504. 'meetingId' => $meetingData['remote_id'], // -- REQUIRED - A unique id for the meeting
  505. 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
  506. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  507. //'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  508. 'userID' => api_get_user_id(), //-- OPTIONAL - string
  509. 'webVoiceConf' => '' // -- OPTIONAL - string
  510. );
  511. $url = $this->api->getJoinMeetingURL($joinParams);
  512. $url = $this->protocol.$url;
  513. } else {
  514. $url = $this->logoutUrl;
  515. }
  516. if ($this->debug) {
  517. error_log("return url :".$url);
  518. }
  519. return $url;
  520. }
  521. /**
  522. * Get information about the given meeting
  523. * @param array ...?
  524. * @return mixed Array of information on success, false on error
  525. * @assert (array()) === false
  526. */
  527. public function getMeetingInfo($params)
  528. {
  529. try {
  530. $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
  531. if ($result == null) {
  532. if ($this->debug) {
  533. error_log("Failed to get any response. Maybe we can't contact the BBB server.");
  534. }
  535. } else {
  536. return $result;
  537. }
  538. } catch (Exception $e) {
  539. if ($this->debug) {
  540. error_log('Caught exception: ', $e->getMessage(), "\n");
  541. }
  542. }
  543. return false;
  544. }
  545. /**
  546. * @param int $courseId
  547. * @param int $sessionId
  548. * @param int $status
  549. *
  550. * @return array
  551. */
  552. public function getAllMeetingsInCourse($courseId, $sessionId, $status)
  553. {
  554. $conditions = array(
  555. 'where' => array(
  556. 'status = ? AND c_id = ? AND session_id = ? ' => array(
  557. $status,
  558. $courseId,
  559. $sessionId,
  560. ),
  561. ),
  562. );
  563. $meetingList = Database::select(
  564. '*',
  565. $this->table,
  566. $conditions
  567. );
  568. return $meetingList;
  569. }
  570. /**
  571. * Gets all the course meetings saved in the plugin_bbb_meeting table
  572. * @param int $courseId
  573. * @param int $sessionId
  574. * @param int $groupId
  575. * @param bool $isAdminReport Optional. Set to true then the report is for admins
  576. * @param array $dateRange Optional
  577. * @return array Array of current open meeting rooms
  578. */
  579. public function getMeetings(
  580. $courseId = 0,
  581. $sessionId = 0,
  582. $groupId = 0,
  583. $isAdminReport = false,
  584. $dateRange = []
  585. ) {
  586. $em = Database::getManager();
  587. $manager = $this->isConferenceManager();
  588. $conditions = [];
  589. if ($courseId || $sessionId || $groupId) {
  590. $conditions = array(
  591. 'where' => array(
  592. 'c_id = ? AND session_id = ? ' => array($courseId, $sessionId),
  593. ),
  594. );
  595. if ($this->hasGroupSupport()) {
  596. $conditions = array(
  597. 'where' => array(
  598. 'c_id = ? AND session_id = ? AND group_id = ? ' => array(
  599. $courseId,
  600. $sessionId,
  601. $groupId
  602. )
  603. )
  604. );
  605. }
  606. }
  607. if (!empty($dateRange)) {
  608. $dateStart = date_create($dateRange['search_meeting_start']);
  609. $dateStart = date_format($dateStart, 'Y-m-d H:i:s');
  610. $dateEnd = date_create($dateRange['search_meeting_end']);
  611. $dateEnd = $dateEnd->add(new DateInterval('P1D'));
  612. $dateEnd = date_format($dateEnd, 'Y-m-d H:i:s');
  613. $conditions = array(
  614. 'where' => array(
  615. 'created_at BETWEEN ? AND ? ' => array($dateStart, $dateEnd),
  616. ),
  617. );
  618. }
  619. $meetingList = Database::select(
  620. '*',
  621. $this->table,
  622. $conditions
  623. );
  624. $isGlobal = $this->isGlobalConference();
  625. $newMeetingList = array();
  626. foreach ($meetingList as $meetingDB) {
  627. $item = array();
  628. $courseId = $meetingDB['c_id'];
  629. $courseInfo = api_get_course_info_by_id($courseId);
  630. $courseCode = '';
  631. if (!empty($courseInfo)) {
  632. $courseCode = $courseInfo['code'];
  633. }
  634. if ($manager) {
  635. $pass = $this->getUserMeetingPassword($courseCode);
  636. } else {
  637. $pass = $this->getModMeetingPassword($courseCode);
  638. }
  639. $meetingBBB = $this->getMeetingInfo(
  640. [
  641. 'meetingId' => $meetingDB['remote_id'],
  642. 'password' => $pass
  643. ]
  644. );
  645. if ($meetingBBB === false) {
  646. //checking with the remote_id didn't work, so just in case and
  647. // to provide backwards support, check with the id
  648. $params = array(
  649. 'meetingId' => $meetingDB['id'],
  650. // -- REQUIRED - The unique id for the meeting
  651. 'password' => $pass
  652. // -- REQUIRED - The moderator password for the meeting
  653. );
  654. $meetingBBB = $this->getMeetingInfo($params);
  655. }
  656. if ($meetingDB['visibility'] == 0 && $this->isConferenceManager() === false) {
  657. continue;
  658. }
  659. $meetingBBB['end_url'] = $this->endUrl($meetingDB);
  660. if (isset($meetingBBB['returncode']) && (string) $meetingBBB['returncode'] == 'FAILED') {
  661. if ($meetingDB['status'] == 1 && $this->isConferenceManager()) {
  662. $this->endMeeting($meetingDB['id'], $courseCode);
  663. }
  664. } else {
  665. $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB);
  666. }
  667. $item['action_links'] = '';
  668. if ($meetingDB['record'] == 1) {
  669. // backwards compatibility (when there was no remote ID)
  670. $mId = $meetingDB['remote_id'];
  671. if (empty($mId)) {
  672. $mId = $meetingDB['id'];
  673. }
  674. if (empty($mId)) {
  675. // if the id is still empty (should *never* occur as 'id' is
  676. // the table's primary key), skip this conference
  677. continue;
  678. }
  679. $record = [];
  680. if (empty($meetingDB['video_url'])) {
  681. $recordingParams = ['meetingId' => $mId];
  682. $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
  683. if (!empty($records)) {
  684. if (!isset($records['messageKey']) || $records['messageKey'] != 'noRecordings') {
  685. $record = end($records);
  686. if (!is_array($record) || !isset($record['recordId'])) {
  687. continue;
  688. }
  689. $this->updateMeetingVideoUrl($meetingDB['id'], $record['playbackFormatUrl']);
  690. if (!$this->isConferenceManager()) {
  691. $record = [];
  692. }
  693. }
  694. }
  695. } else {
  696. $record['playbackFormatUrl'] = $meetingDB['video_url'];
  697. }
  698. $recordLink = isset($record['playbackFormatUrl']) && !empty($record['playbackFormatUrl'])
  699. ? Display::url(
  700. $this->plugin->get_lang('ViewRecord'),
  701. $record['playbackFormatUrl'],
  702. ['target' => '_blank']
  703. )
  704. : get_lang('NoRecording');
  705. if ($isAdminReport) {
  706. $this->forceCIdReq($courseInfo['code'], $meetingDB['session_id'], $meetingDB['group_id']);
  707. }
  708. $actionLinks = $this->getActionLinks($meetingDB, $record, $isGlobal, $isAdminReport);
  709. $item['show_links'] = $recordLink;
  710. } else {
  711. $actionLinks = $this->getActionLinks($meetingDB, [], $isGlobal, $isAdminReport);
  712. $item['show_links'] = get_lang('NoRecording');
  713. }
  714. $item['action_links'] = implode(PHP_EOL, $actionLinks);
  715. $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
  716. // created_at
  717. $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
  718. $item['publish_url'] = $this->publishUrl($meetingDB);
  719. $item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
  720. if ($meetingDB['status'] == 1) {
  721. $joinParams = array(
  722. 'meetingId' => $meetingDB['remote_id'], //-- REQUIRED - A unique id for the meeting
  723. 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
  724. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  725. 'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  726. 'userID' => '', // -- OPTIONAL - string
  727. 'webVoiceConf' => '' // -- OPTIONAL - string
  728. );
  729. $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
  730. }
  731. $item = array_merge($item, $meetingDB, $meetingBBB);
  732. $item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']);
  733. $item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']);
  734. $newMeetingList[] = $item;
  735. }
  736. return $newMeetingList;
  737. }
  738. /**
  739. * Function disabled
  740. */
  741. public function publishMeeting($id)
  742. {
  743. //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
  744. if (empty($id)) {
  745. return false;
  746. }
  747. $id = intval($id);
  748. Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
  749. return true;
  750. }
  751. /**
  752. * Function disabled
  753. */
  754. public function unpublishMeeting($id)
  755. {
  756. //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
  757. if (empty($id)) {
  758. return false;
  759. }
  760. $id = intval($id);
  761. Database::update($this->table, array('visibility' => 0), array('id = ?' => $id));
  762. return true;
  763. }
  764. /**
  765. * Closes a meeting (usually when the user click on the close button from
  766. * the conferences listing.
  767. * @param string The internal ID of the meeting (id field for this meeting)
  768. * @param string $courseCode
  769. *
  770. * @return void
  771. * @assert (0) === false
  772. */
  773. public function endMeeting($id, $courseCode = null)
  774. {
  775. if (empty($id)) {
  776. return false;
  777. }
  778. $meetingData = Database::select(
  779. '*',
  780. $this->table,
  781. array('where' => array('id = ?' => array($id))),
  782. 'first'
  783. );
  784. $manager = $this->isConferenceManager();
  785. if ($manager) {
  786. $pass = $this->getUserMeetingPassword($courseCode);
  787. } else {
  788. $pass = $this->getModMeetingPassword($courseCode);
  789. }
  790. $endParams = array(
  791. 'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end.
  792. 'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
  793. );
  794. $this->api->endMeetingWithXmlResponseArray($endParams);
  795. Database::update(
  796. $this->table,
  797. array('status' => 0, 'closed_at' => api_get_utc_datetime()),
  798. array('id = ? ' => $id)
  799. );
  800. }
  801. /**
  802. * Gets the password for a specific meeting for the current user
  803. * @param string $courseCode
  804. * @return string A moderator password if user is teacher, or the course code otherwise
  805. *
  806. */
  807. public function getUserMeetingPassword($courseCode = null)
  808. {
  809. if ($this->isGlobalConferencePerUserEnabled()) {
  810. return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
  811. }
  812. if ($this->isGlobalConference()) {
  813. return 'url_'.api_get_current_access_url_id();
  814. }
  815. $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
  816. return $courseCode;
  817. }
  818. /**
  819. * Generated a moderator password for the meeting
  820. * @param string $courseCode
  821. *
  822. * @return string A password for the moderation of the videoconference
  823. */
  824. public function getModMeetingPassword($courseCode = null)
  825. {
  826. if ($this->isGlobalConferencePerUserEnabled()) {
  827. return 'url_'.$this->userId.'_'.api_get_current_access_url_id().'_mod';
  828. }
  829. if ($this->isGlobalConference()) {
  830. return 'url_'.api_get_current_access_url_id().'_mod';
  831. }
  832. $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
  833. return $courseCode.'mod';
  834. }
  835. /**
  836. * Get users online in the current course room
  837. * @return int The number of users currently connected to the videoconference
  838. * @assert () > -1
  839. */
  840. public function getUsersOnlineInCurrentRoom()
  841. {
  842. $courseId = api_get_course_int_id();
  843. $sessionId = api_get_session_id();
  844. $conditions = array(
  845. 'where' => array(
  846. 'c_id = ? AND session_id = ? AND status = 1 AND access_url = ?' => array(
  847. $courseId,
  848. $sessionId,
  849. $this->accessUrl
  850. ),
  851. ),
  852. );
  853. if ($this->hasGroupSupport()) {
  854. $groupId = api_get_group_id();
  855. $conditions = array(
  856. 'where' => array(
  857. 'c_id = ? AND session_id = ? AND group_id = ? AND status = 1 AND access_url = ?' => array(
  858. $courseId,
  859. $sessionId,
  860. $groupId,
  861. $this->accessUrl
  862. ),
  863. ),
  864. );
  865. }
  866. if ($this->isGlobalConferencePerUserEnabled()) {
  867. $conditions = array(
  868. 'where' => array(
  869. 'user_id = ? AND status = 1 AND access_url = ?' => array(
  870. $this->userId,
  871. $this->accessUrl
  872. ),
  873. ),
  874. );
  875. }
  876. $meetingData = Database::select(
  877. '*',
  878. $this->table,
  879. $conditions,
  880. 'first'
  881. );
  882. if (empty($meetingData)) {
  883. return 0;
  884. }
  885. $pass = $this->getModMeetingPassword();
  886. $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass));
  887. if ($info === false) {
  888. //checking with the remote_id didn't work, so just in case and
  889. // to provide backwards support, check with the id
  890. $params = array(
  891. 'meetingId' => $meetingData['id'],
  892. // -- REQUIRED - The unique id for the meeting
  893. 'password' => $pass
  894. // -- REQUIRED - The moderator password for the meeting
  895. );
  896. $info = $this->getMeetingInfo($params);
  897. }
  898. if (!empty($info) && isset($info['participantCount'])) {
  899. return $info['participantCount'];
  900. }
  901. return 0;
  902. }
  903. /**
  904. * Deletes a previous recording of a meeting
  905. * @param int $id ID of the recording
  906. * @return array ?
  907. * @assert () === false
  908. * @todo Also delete links and agenda items created from this recording
  909. */
  910. public function deleteRecording($id)
  911. {
  912. if (empty($id)) {
  913. return false;
  914. }
  915. $meetingData = Database::select(
  916. '*',
  917. $this->table,
  918. array('where' => array('id = ?' => array($id))),
  919. 'first'
  920. );
  921. $recordingParams = array(
  922. /*
  923. * NOTE: Set the recordId below to a valid id after you have
  924. * created a recorded meeting, and received a real recordID
  925. * back from your BBB server using the
  926. * getRecordingsWithXmlResponseArray method.
  927. */
  928. // REQUIRED - We have to know which recording:
  929. 'recordId' => $meetingData['remote_id'],
  930. );
  931. $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
  932. if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
  933. Database::delete(
  934. 'plugin_bbb_room',
  935. array('meeting_id = ?' => array($id))
  936. );
  937. Database::delete(
  938. $this->table,
  939. array('id = ?' => array($id))
  940. );
  941. }
  942. return $result;
  943. }
  944. /**
  945. * Creates a link in the links tool from the given videoconference recording
  946. * @param int $id ID of the item in the plugin_bbb_meeting table
  947. * @param string Hash identifying the recording, as provided by the API
  948. * @return mixed ID of the newly created link, or false on error
  949. * @assert (null, null) === false
  950. * @assert (1, null) === false
  951. * @assert (null, 'abcdefabcdefabcdefabcdef') === false
  952. */
  953. public function copyRecordingToLinkTool($id)
  954. {
  955. if (empty($id)) {
  956. return false;
  957. }
  958. //$records = BigBlueButtonBN::getRecordingsUrl($id);
  959. $meetingData = Database::select(
  960. '*',
  961. $this->table,
  962. array('where' => array('id = ?' => array($id))),
  963. 'first'
  964. );
  965. $records = $this->api->getRecordingsWithXmlResponseArray(
  966. array('meetingId' => $meetingData['remote_id'])
  967. );
  968. if (!empty($records)) {
  969. if (isset($records['message']) && !empty($records['message'])) {
  970. if ($records['messageKey'] == 'noRecordings') {
  971. $recordArray[] = $this->plugin->get_lang('NoRecording');
  972. } else {
  973. //$recordArray[] = $records['message'];
  974. }
  975. return false;
  976. } else {
  977. $record = $records[0];
  978. if (is_array($record) && isset($record['recordId'])) {
  979. $url = $record['playbackFormatUrl'];
  980. $link = new Link();
  981. $params['url'] = $url;
  982. $params['title'] = $meetingData['meeting_name'];
  983. $id = $link->save($params);
  984. return $id;
  985. }
  986. }
  987. }
  988. return false;
  989. }
  990. /**
  991. * Checks if the video conference server is running.
  992. * Function currently disabled (always returns 1)
  993. * @return bool True if server is running, false otherwise
  994. * @assert () === false
  995. */
  996. public function isServerRunning()
  997. {
  998. return true;
  999. //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
  1000. }
  1001. /**
  1002. * Get active session in the all platform
  1003. */
  1004. public function getActiveSessionsCount()
  1005. {
  1006. $meetingList = Database::select(
  1007. 'count(id) as count',
  1008. $this->table,
  1009. array('where' => array('status = ? AND access_url = ?' => array(1, $this->accessUrl))),
  1010. 'first'
  1011. );
  1012. return $meetingList['count'];
  1013. }
  1014. /**
  1015. * @param string $url
  1016. */
  1017. public function redirectToBBB($url)
  1018. {
  1019. if (file_exists(__DIR__.'/../config.vm.php')) {
  1020. // Using VM
  1021. echo Display::url($this->plugin->get_lang('ClickToContinue'), $url);
  1022. exit;
  1023. } else {
  1024. // Classic
  1025. header("Location: $url");
  1026. exit;
  1027. }
  1028. }
  1029. /**
  1030. * @return string
  1031. */
  1032. public function getUrlParams()
  1033. {
  1034. if (empty($this->courseCode)) {
  1035. if ($this->isGlobalConferencePerUserEnabled()) {
  1036. return 'global=1&user_id='.$this->userId;
  1037. }
  1038. if ($this->isGlobalConference()) {
  1039. return 'global=1';
  1040. }
  1041. return '';
  1042. }
  1043. return http_build_query([
  1044. 'cidReq' => $this->courseCode,
  1045. 'id_session' => $this->sessionId,
  1046. 'gidReq' => $this->groupId
  1047. ]);
  1048. }
  1049. /**
  1050. * @return string
  1051. */
  1052. public function getCurrentVideoConferenceName()
  1053. {
  1054. if ($this->isGlobalConferencePerUserEnabled()) {
  1055. return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
  1056. }
  1057. if ($this->isGlobalConference()) {
  1058. return 'url_'.api_get_current_access_url_id();
  1059. }
  1060. if ($this->hasGroupSupport()) {
  1061. return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
  1062. }
  1063. return api_get_course_id().'-'.api_get_session_id();
  1064. }
  1065. /**
  1066. * @return string
  1067. */
  1068. public function getConferenceUrl()
  1069. {
  1070. return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
  1071. }
  1072. /**
  1073. * @return string
  1074. */
  1075. public function getListingUrl()
  1076. {
  1077. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams();
  1078. }
  1079. /**
  1080. * @param array $meeting
  1081. * @return string
  1082. */
  1083. public function endUrl($meeting)
  1084. {
  1085. if (!isset($meeting['id'])) {
  1086. return '';
  1087. }
  1088. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id'];
  1089. }
  1090. /**
  1091. * @param array $meeting
  1092. * @param array $record
  1093. * @return string
  1094. */
  1095. public function addToCalendarUrl($meeting, $record = [])
  1096. {
  1097. $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
  1098. 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;
  1099. }
  1100. /**
  1101. * @param array $meeting
  1102. * @return string
  1103. */
  1104. public function publishUrl($meeting)
  1105. {
  1106. if (!isset($meeting['id'])) {
  1107. return '';
  1108. }
  1109. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=publish&id='.$meeting['id'];
  1110. }
  1111. /**
  1112. * @param array $meeting
  1113. * @return string
  1114. */
  1115. public function unPublishUrl($meeting)
  1116. {
  1117. if (!isset($meeting['id'])) {
  1118. return null;
  1119. }
  1120. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=unpublish&id='.$meeting['id'];
  1121. }
  1122. /**
  1123. * @param array $meeting
  1124. * @return string
  1125. */
  1126. public function deleteRecordUrl($meeting)
  1127. {
  1128. if (!isset($meeting['id'])) {
  1129. return '';
  1130. }
  1131. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=delete_record&id='.$meeting['id'];
  1132. }
  1133. /**
  1134. * @param array $meeting
  1135. * @return string
  1136. */
  1137. public function copyToRecordToLinkTool($meeting)
  1138. {
  1139. if (!isset($meeting['id'])) {
  1140. return '';
  1141. }
  1142. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
  1143. }
  1144. /**
  1145. * Get the meeting info from DB by its name
  1146. * @param string $name
  1147. * @return array
  1148. */
  1149. public function findMeetingByName($name)
  1150. {
  1151. $meetingData = Database::select(
  1152. '*',
  1153. 'plugin_bbb_meeting',
  1154. array('where' => array('meeting_name = ? AND status = 1 ' => $name)),
  1155. 'first'
  1156. );
  1157. return $meetingData;
  1158. }
  1159. /**
  1160. * @param int $meetingId
  1161. * @return array
  1162. */
  1163. public function findMeetingParticipants($meetingId)
  1164. {
  1165. $em = Database::getManager();
  1166. $meetingData = Database::select(
  1167. '*',
  1168. 'plugin_bbb_room',
  1169. array('where' => array('meeting_id = ?' => intval($meetingId)))
  1170. );
  1171. $participantIds = [];
  1172. $return = [];
  1173. foreach ($meetingData as $participantInfo) {
  1174. if (in_array($participantInfo['participant_id'], $participantIds)) {
  1175. continue;
  1176. }
  1177. $participantIds[] = $participantInfo['participant_id'];
  1178. $return[] = [
  1179. 'id' => $participantInfo['id'],
  1180. 'meeting_id' => $participantInfo['meeting_id'],
  1181. 'participant' => $em->find('ChamiloUserBundle:User', $participantInfo['participant_id']),
  1182. 'in_at' => $participantInfo['in_at'],
  1183. 'out_at' => $participantInfo['out_at']
  1184. ];
  1185. }
  1186. return $return;
  1187. }
  1188. /**
  1189. * @param array $meetingInfo
  1190. * @param array $recordInfo
  1191. * @param bool $isGlobal
  1192. * @param bool $isAdminReport
  1193. * @return array
  1194. */
  1195. private function getActionLinks($meetingInfo, $recordInfo, $isGlobal = false, $isAdminReport = false)
  1196. {
  1197. $isVisible = $meetingInfo['visibility'] != 0;
  1198. $linkVisibility = $isVisible
  1199. ? Display::url(
  1200. Display::return_icon('visible.png', get_lang('MakeInvisible')),
  1201. $this->unPublishUrl($meetingInfo)
  1202. )
  1203. : Display::url(
  1204. Display::return_icon('invisible.png', get_lang('MakeVisible')),
  1205. $this->publishUrl($meetingInfo)
  1206. );
  1207. $links = [];
  1208. if (empty($recordInfo)) {
  1209. if (!$isAdminReport) {
  1210. $links[] = Display::url(
  1211. Display::return_icon('delete.png', get_lang('Delete')),
  1212. $this->deleteRecordUrl($meetingInfo)
  1213. );
  1214. $links[] = $linkVisibility;
  1215. return $links;
  1216. } else {
  1217. $links[] = Display::url(
  1218. Display::return_icon('course_home.png', get_lang('GoToCourse')),
  1219. $this->getListingUrl()
  1220. );
  1221. return $links;
  1222. }
  1223. }
  1224. if (!$isGlobal) {
  1225. $links[] = Display::url(
  1226. Display::return_icon('link.gif', get_lang('UrlMeetingToShare')),
  1227. $this->copyToRecordToLinkTool($meetingInfo)
  1228. );
  1229. $links[] = Display::url(
  1230. Display::return_icon('agenda.png', get_lang('AddToCalendar')),
  1231. $this->addToCalendarUrl($meetingInfo, $recordInfo)
  1232. );
  1233. }
  1234. if ($meetingInfo['has_video_m4v']) {
  1235. $links[] = Display::url(
  1236. Display::return_icon('save.png', get_lang('DownloadFile')),
  1237. $recordInfo['playbackFormatUrl'].'/capture.m4v',
  1238. ['target' => '_blank']
  1239. );
  1240. } else {
  1241. $links[] = Display::url(
  1242. Display::return_icon('save.png', get_lang('DownloadFile')),
  1243. '#',
  1244. [
  1245. 'id' => "btn-check-meeting-video-{$meetingInfo['id']}",
  1246. 'class' => 'check-meeting-video',
  1247. 'data-id' => $meetingInfo['id']
  1248. ]
  1249. );
  1250. }
  1251. if (!$isAdminReport) {
  1252. $links[] = Display::url(
  1253. Display::return_icon('delete.png', get_lang('Delete')),
  1254. $this->deleteRecordUrl($meetingInfo)
  1255. );
  1256. $links[] = $linkVisibility;
  1257. } else {
  1258. $links[] = Display::url(
  1259. Display::return_icon('course_home.png', get_lang('GoToCourse')),
  1260. $this->getListingUrl()
  1261. );
  1262. }
  1263. return $links;
  1264. }
  1265. /**
  1266. * @param int $meetingId
  1267. * @param string $videoUrl
  1268. * @return bool|int
  1269. */
  1270. public function updateMeetingVideoUrl($meetingId, $videoUrl)
  1271. {
  1272. return Database::update(
  1273. 'plugin_bbb_meeting',
  1274. ['video_url' => $videoUrl],
  1275. ['id = ?' => intval($meetingId)]
  1276. );
  1277. }
  1278. /**
  1279. * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated
  1280. * @param int $meetingId
  1281. * @return bool
  1282. */
  1283. public function checkDirectMeetingVideoUrl($meetingId)
  1284. {
  1285. $meetingInfo = Database::select(
  1286. '*',
  1287. 'plugin_bbb_meeting',
  1288. [
  1289. 'where' => ['id = ?' => intval($meetingId)]
  1290. ],
  1291. 'first'
  1292. );
  1293. if (!isset($meetingInfo['video_url'])) {
  1294. return false;
  1295. }
  1296. $hasCapture = SocialManager::verifyUrl($meetingInfo['video_url'].'/capture.m4v');
  1297. if ($hasCapture) {
  1298. return Database::update(
  1299. 'plugin_bbb_meeting',
  1300. ['has_video_m4v' => true],
  1301. ['id = ?' => intval($meetingId)]
  1302. );
  1303. }
  1304. return $hasCapture;
  1305. }
  1306. /**
  1307. * @param array $userInfo
  1308. * @return bool
  1309. */
  1310. public static function showGlobalConferenceLink($userInfo)
  1311. {
  1312. if (empty($userInfo)) {
  1313. return false;
  1314. }
  1315. $setting = api_get_plugin_setting('bbb', 'enable_global_conference');
  1316. $settingLink = api_get_plugin_setting('bbb', 'enable_global_conference_link');
  1317. if ($setting === 'true' && $settingLink === 'true') {
  1318. //$content = Display::url(get_lang('LaunchVideoConferenceRoom'), $url);
  1319. $allowedRoles = api_get_plugin_setting(
  1320. 'bbb',
  1321. 'global_conference_allow_roles'
  1322. );
  1323. if (api_is_platform_admin()) {
  1324. $userInfo['status'] = PLATFORM_ADMIN;
  1325. }
  1326. $showGlobalLink = true;
  1327. if (!empty($allowedRoles)) {
  1328. if (!in_array($userInfo['status'], $allowedRoles)) {
  1329. $showGlobalLink = false;
  1330. }
  1331. }
  1332. return $showGlobalLink;
  1333. }
  1334. }
  1335. }