1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Class bbb
- * This script initiates a video conference session, calling the BigBlueButton
- * API
- * @package chamilo.plugin.bigbluebutton
- *
- * BigBlueButton-Chamilo connector class
- */
- //namespace Chamilo\Plugin\BBB;
- /**
- * Class bbb
- * @package Chamilo\Plugin\BBB
- */
- class bbb
- {
- public $url;
- public $salt;
- public $api;
- public $userCompleteName = '';
- public $protocol = 'http://';
- public $debug = false;
- public $logoutUrl = '';
- public $pluginEnabled = false;
- public $enableGlobalConference = false;
- public $enableGlobalConferencePerUser = false;
- public $isGlobalConference = false;
- public $groupSupport = false;
- public $userSupport = false;
- public $accessUrl = 1;
- public $userId = 0;
- public $plugin;
- private $courseCode;
- private $courseId;
- private $sessionId;
- private $groupId;
- private $maxUsersLimit;
- /**
- * Constructor (generates a connection to the API and the Chamilo settings
- * required for the connection to the video conference server)
- * @param string $host
- * @param string $salt
- * @param bool $isGlobalConference
- * @param int $isGlobalPerUser
- */
- public function __construct($host = '', $salt = '', $isGlobalConference = false, $isGlobalPerUser = 0)
- {
- $this->courseCode = api_get_course_id();
- $this->courseId = api_get_course_int_id();
- $this->sessionId = api_get_session_id();
- $this->groupId = api_get_group_id();
- // Initialize video server settings from global settings
- $this->plugin = BBBPlugin::create();
- $bbbPluginEnabled = $this->plugin->get('tool_enable');
- $bbb_host = !empty($host) ? $host : $this->plugin->get('host');
- $bbb_salt = !empty($salt) ? $salt : $this->plugin->get('salt');
- $this->logoutUrl = $this->getListingUrl();
- $this->table = Database::get_main_table('plugin_bbb_meeting');
- $this->enableGlobalConference = (bool) $this->plugin->get('enable_global_conference');
- $this->isGlobalConference = (bool) $isGlobalConference;
- $columns = Database::listTableColumns($this->table);
- $this->groupSupport = isset($columns['group_id']) ? true : false;
- $this->userSupport = isset($columns['user_id']) ? true : false;
- $this->accessUrl = api_get_current_access_url_id();
- if ($this->userSupport && !empty($isGlobalPerUser)) {
- $this->enableGlobalConferencePerUser = (bool) $this->plugin->get('enable_global_conference_per_user');
- $this->userId = $isGlobalPerUser;
- } else {
- $this->enableGlobalConferencePerUser = false;
- }
- if ($this->groupSupport) {
- // Plugin check
- $this->groupSupport = (bool) $this->plugin->get('enable_conference_in_course_groups');
- if ($this->groupSupport) {
- // Platform check
- $bbbSetting = api_get_setting('bbb_enable_conference_in_course_groups');
- $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
- if ($bbbSetting) {
- // Course check
- $courseInfo = api_get_course_info();
- if ($courseInfo) {
- $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups', $courseInfo['code']) === '1';
- }
- }
- }
- }
- $this->maxUsersLimit = $this->plugin->get('max_users_limit');
- if ($bbbPluginEnabled === 'true') {
- $userInfo = api_get_user_info();
- if (empty($userInfo) && !empty($isGlobalPerUser)) {
- // If we are following a link to a global "per user" conference
- // then generate a random guest name to join the conference
- // because there is no part of the process where we give a name
- $this->userCompleteName = 'Guest'.rand(1000, 9999);
- } else {
- $this->userCompleteName = $userInfo['complete_name'];
- }
- $this->salt = $bbb_salt;
- $info = parse_url($bbb_host);
- $this->url = $bbb_host.'/bigbluebutton/';
- if (isset($info['scheme'])) {
- $this->protocol = $info['scheme'].'://';
- $this->url = str_replace($this->protocol, '', $this->url);
- }
- // Setting BBB api
- define('CONFIG_SECURITY_SALT', $this->salt);
- define('CONFIG_SERVER_BASE_URL', $this->url);
- $this->api = new BigBlueButtonBN();
- $this->pluginEnabled = true;
- }
- }
- /**
- * Force the course, session and/or group IDs
- * @param string $courseCode
- * @param int $sessionId
- * @param int $groupId
- */
- public function forceCIdReq($courseCode, $sessionId = 0, $groupId = 0)
- {
- $this->courseCode = $courseCode;
- $this->sessionId = intval($sessionId);
- $this->groupId = intval($groupId);
- }
- /**
- * @return bool
- */
- public function isGlobalConferenceEnabled()
- {
- return $this->enableGlobalConference;
- }
- /**
- * @return bool
- */
- public function isGlobalConferencePerUserEnabled()
- {
- return $this->enableGlobalConferencePerUser;
- }
- /**
- * @return bool
- */
- public function isGlobalConference()
- {
- if ($this->isGlobalConferenceEnabled() === false) {
- return false;
- }
- return (bool) $this->isGlobalConference;
- }
- /**
- * @return bool
- */
- public function hasGroupSupport()
- {
- return $this->groupSupport;
- }
- /**
- * Checks whether a user is teacher in the current course
- * @return bool True if the user can be considered a teacher in this course, false otherwise
- */
- public function isConferenceManager()
- {
- if (api_is_coach() || api_is_platform_admin()) {
- return true;
- }
- if ($this->isGlobalConferencePerUserEnabled()) {
- $currentUserId = api_get_user_id();
- if ($this->userId === $currentUserId) {
- return true;
- } else {
- return false;
- }
- }
- $courseInfo = api_get_course_info();
- if (!empty($courseInfo)) {
- return api_is_course_admin();
- }
- return false;
- }
- /**
- * Gets the global limit of users in a video-conference room.
- * This value can be overridden by course-specific values
- * @return int Maximum number of users set globally
- */
- public function getMaxUsersLimit() {
- $limit = $this->maxUsersLimit;
- if ($limit <= 0) {
- $limit = 0;
- }
- $courseLimit = 0;
- $sessionLimit = 0;
- // Check the extra fields for this course and session
- // Session limit takes priority over course limit
- // Course limit takes priority over global limit
- if (!empty($this->courseId)) {
- $extraField = new ExtraField('course');
- $fieldId = $extraField->get_all(
- array('variable = ?' => 'plugin_bbb_course_users_limit')
- );
- $extraValue = new ExtraFieldValue('course');
- $value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId[0]['id']);
- if (!empty($value['value'])) {
- $courseLimit = $value['value'];
- }
- }
- if (!empty($this->sessionId)) {
- $extraField = new ExtraField('session');
- $fieldId = $extraField->get_all(
- array('variable = ?' => 'plugin_bbb_session_users_limit')
- );
- $extraValue = new ExtraFieldValue('session');
- $value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId[0]['id']);
- if (!empty($value['value'])) {
- $sessionLimit = $value['value'];
- }
- }
- if (!empty($sessionLimit)) {
- return $sessionLimit;
- } elseif (!empty($courseLimit)) {
- return $courseLimit;
- }
- return $limit;
- }
- /**
- * Sets the global limit of users in a video-conference room.
- * @param int Maximum number of users (globally)
- */
- public function setMaxUsersLimit($max) {
- if ($max < 0) {
- $max = 0;
- }
- $this->maxUsersLimit = intval($max);
- }
- /**
- * See this file in you BBB to set up default values
- * @param array $params Array of parameters that will be completed if not containing all expected variables
- /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
- *
- More record information:
- http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
- # Default maximum number of users a meeting can have.
- # Doesn't get enforced yet but is the default value when the create
- # API doesn't pass a value.
- defaultMaxUsers=20
- # Default duration of the meeting in minutes.
- # Current default is 0 (meeting doesn't end).
- defaultMeetingDuration=0
- # Remove the meeting from memory when the end API is called.
- # This allows 3rd-party apps to recycle the meeting right-away
- # instead of waiting for the meeting to expire (see below).
- removeMeetingWhenEnded=false
- # The number of minutes before the system removes the meeting from memory.
- defaultMeetingExpireDuration=1
- # The number of minutes the system waits when a meeting is created and when
- # a user joins. If after this period, a user hasn't joined, the meeting is
- # removed from memory.
- defaultMeetingCreateJoinDuration=5
- *
- * @return mixed
- */
- public function createMeeting($params)
- {
- $courseCode = api_get_course_id();
- $params['c_id'] = api_get_course_int_id();
- $params['session_id'] = api_get_session_id();
- if ($this->hasGroupSupport()) {
- $params['group_id'] = api_get_group_id();
- }
- if ($this->isGlobalConferencePerUserEnabled()) {
- $currentUserId = api_get_user_id();
- if ($this->userId === $currentUserId) {
- $params['user_id'] = $this->userId;
- }
- }
- $params['attendee_pw'] = isset($params['attendee_pw']) ? $params['attendee_pw'] : $this->getUserMeetingPassword();
- $attendeePassword = $params['attendee_pw'];
- $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
- $moderatorPassword = $params['moderator_pw'];
- $params['record'] = api_get_course_setting('big_blue_button_record_and_store', $courseCode) == 1 ? true : false;
- $max = api_get_course_setting('big_blue_button_max_students_allowed', $courseCode);
- $max = isset($max) ? $max : -1;
- $params['status'] = 1;
- // Generate a pseudo-global-unique-id to avoid clash of conferences on
- // the same BBB server with several Chamilo portals
- $params['remote_id'] = uniqid(true, true);
- // Each simultaneous conference room needs to have a different
- // voice_bridge composed of a 5 digits number, so generating a random one
- $params['voice_bridge'] = rand(10000, 99999);
- if ($this->debug) {
- error_log("enter create_meeting ".print_r($params, 1));
- }
- $params['created_at'] = api_get_utc_datetime();
- $params['access_url'] = $this->accessUrl;
- $id = Database::insert($this->table, $params);
- if ($id) {
- if ($this->debug) {
- error_log("create_meeting: $id ");
- }
- $meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : $this->getCurrentVideoConferenceName();
- $welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
- $record = isset($params['record']) && $params['record'] ? 'true' : 'false';
- $duration = isset($params['duration']) ? intval($params['duration']) : 0;
- // This setting currently limits the maximum conference duration,
- // to avoid lingering sessions on the video-conference server #6261
- $duration = 300;
- $bbbParams = array(
- 'meetingId' => $params['remote_id'], // REQUIRED
- 'meetingName' => $meetingName, // REQUIRED
- 'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee.
- 'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator.
- 'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize.
- 'dialNumber' => '', // The main number to call into. Optional.
- 'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required.
- 'webVoice' => '', // Alphanumeric to join voice. Optional.
- 'logoutUrl' => $this->logoutUrl,
- 'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
- 'record' => $record, // New. 'true' will tell BBB to record the meeting.
- 'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
- //'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
- );
- if ($this->debug) {
- error_log("create_meeting params: ".print_r($bbbParams, 1));
- }
- $status = false;
- $meeting = null;
- while ($status === false) {
- $result = $this->api->createMeetingWithXmlResponseArray(
- $bbbParams
- );
- if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
- if ($this->debug) {
- error_log(
- "create_meeting result: ".print_r($result, 1)
- );
- }
- $meeting = $this->joinMeeting($meetingName, true);
- return $meeting;
- }
- }
- return $this->logoutUrl;
- }
- }
- /**
- * Save a participant in a meeting room
- * @param int $meetingId
- * @param int $participantId
- * @return false|int The last inserted ID. Otherwise return false
- */
- public function saveParticipant($meetingId, $participantId)
- {
- return Database::insert(
- 'plugin_bbb_room',
- [
- 'meeting_id' => $meetingId,
- 'participant_id' => $participantId,
- 'in_at' => api_get_utc_datetime(),
- 'out_at' => api_get_utc_datetime()
- ]
- );
- }
- /**
- * Tells whether the given meeting exists and is running
- * (using course code as name)
- * @param string $meetingName Meeting name (usually the course code)
- *
- * @return bool True if meeting exists, false otherwise
- * @assert ('') === false
- * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
- */
- public function meetingExists($meetingName)
- {
- if (empty($meetingName)) {
- return false;
- }
- $courseId = api_get_course_int_id();
- $sessionId = api_get_session_id();
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 AND access_url = ?' =>
- array($courseId, $sessionId, $meetingName, $this->accessUrl)
- )
- );
- if ($this->hasGroupSupport()) {
- $groupId = api_get_group_id();
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? AND meeting_name = ? AND group_id = ? AND status = 1 AND access_url = ?' =>
- array($courseId, $sessionId, $meetingName, $groupId, $this->accessUrl)
- )
- );
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- $conditions,
- 'first'
- );
- if ($this->debug) {
- error_log("meeting_exists ".print_r($meetingData, 1));
- }
- if (empty($meetingData)) {
- return false;
- } else {
- return true;
- }
- }
- /**
- * Returns a meeting "join" URL
- * @param string The name of the meeting (usually the course code)
- * @return mixed The URL to join the meeting, or false on error
- * @todo implement moderator pass
- * @assert ('') === false
- * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
- */
- public function joinMeeting($meetingName, $loop = false)
- {
- if (empty($meetingName)) {
- return false;
- }
- $manager = $this->isConferenceManager();
- if ($manager) {
- $pass = $this->getModMeetingPassword();
- } else {
- $pass = $this->getUserMeetingPassword();
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- array('where' => array('meeting_name = ? AND status = 1 AND access_url = ?' => array($meetingName, $this->accessUrl))),
- 'first'
- );
- if (empty($meetingData) || !is_array($meetingData)) {
- if ($this->debug) {
- error_log("meeting does not exist: $meetingName");
- }
- return false;
- }
- $params = array(
- 'meetingId' => $meetingData['remote_id'],
- // -- REQUIRED - The unique id for the meeting
- 'password' => $this->getModMeetingPassword()
- // -- REQUIRED - The moderator password for the meeting
- );
- $status = false;
- $meetingInfoExists = false;
- while ($status === false) {
- $meetingIsRunningInfo = $this->getMeetingInfo($params);
- if ($meetingIsRunningInfo === false) {
- //checking with the remote_id didn't work, so just in case and
- // to provide backwards support, check with the id
- $params = array(
- 'meetingId' => $meetingData['id'],
- // -- REQUIRED - The unique id for the meeting
- 'password' => $this->getModMeetingPassword()
- // -- REQUIRED - The moderator password for the meeting
- );
- $meetingIsRunningInfo = $this->getMeetingInfo($params);
- }
- if ($this->debug) {
- error_log(print_r($meetingIsRunningInfo, 1));
- }
- if (strval($meetingIsRunningInfo['returncode']) == 'SUCCESS' &&
- isset($meetingIsRunningInfo['meetingName']) &&
- !empty($meetingIsRunningInfo['meetingName'])
- //strval($meetingIsRunningInfo['running']) == 'true'
- ) {
- $meetingInfoExists = true;
- }
- if ($this->debug) {
- error_log(
- "meeting is running: ".intval($meetingInfoExists)
- );
- }
- if ($meetingInfoExists) {
- $status = true;
- }
- if ($loop) {
- continue;
- } else {
- break;
- }
- }
- if ($meetingInfoExists) {
- $joinParams = array(
- 'meetingId' => $meetingData['remote_id'], // -- REQUIRED - A unique id for the meeting
- 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
- 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
- //'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
- 'userID' => api_get_user_id(), //-- OPTIONAL - string
- 'webVoiceConf' => '' // -- OPTIONAL - string
- );
- $url = $this->api->getJoinMeetingURL($joinParams);
- $url = $this->protocol.$url;
- } else {
- $url = $this->logoutUrl;
- }
- if ($this->debug) {
- error_log("return url :".$url);
- }
- return $url;
- }
- /**
- * Get information about the given meeting
- * @param array ...?
- * @return mixed Array of information on success, false on error
- * @assert (array()) === false
- */
- public function getMeetingInfo($params)
- {
- try {
- $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
- if ($result == null) {
- if ($this->debug) {
- error_log("Failed to get any response. Maybe we can't contact the BBB server.");
- }
- } else {
- return $result;
- }
- } catch (Exception $e) {
- if ($this->debug) {
- error_log('Caught exception: ', $e->getMessage(), "\n");
- }
- }
- return false;
- }
- /**
- * @param int $courseId
- * @param int $sessionId
- * @param int $status
- *
- * @return array
- */
- public function getAllMeetingsInCourse($courseId, $sessionId, $status)
- {
- $conditions = array(
- 'where' => array(
- 'status = ? AND c_id = ? AND session_id = ? ' => array(
- $status,
- $courseId,
- $sessionId,
- ),
- ),
- );
- $meetingList = Database::select(
- '*',
- $this->table,
- $conditions
- );
- return $meetingList;
- }
- /**
- * Gets all the course meetings saved in the plugin_bbb_meeting table
- * @param int $courseId
- * @param int $sessionId
- * @param int $groupId
- * @param bool $isAdminReport Optional. Set to true then the report is for admins
- * @param array $dateRange Optional
- * @return array Array of current open meeting rooms
- */
- public function getMeetings(
- $courseId = 0,
- $sessionId = 0,
- $groupId = 0,
- $isAdminReport = false,
- $dateRange = []
- ) {
- $em = Database::getManager();
- $manager = $this->isConferenceManager();
- $conditions = [];
- if ($courseId || $sessionId || $groupId) {
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? ' => array($courseId, $sessionId),
- ),
- );
- if ($this->hasGroupSupport()) {
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? AND group_id = ? ' => array($courseId, $sessionId, $groupId)
- )
- );
- }
- }
- if (!empty($dateRange)) {
- $dateStart = date_create($dateRange['search_meeting_start']);
- $dateStart = date_format($dateStart, 'Y-m-d H:i:s');
- $dateEnd = date_create($dateRange['search_meeting_end']);
- $dateEnd = $dateEnd->add(new DateInterval('P1D'));
- $dateEnd = date_format($dateEnd, 'Y-m-d H:i:s');
- $conditions = array(
- 'where' => array(
- 'created_at BETWEEN ? AND ? ' => array($dateStart, $dateEnd),
- ),
- );
- }
- $meetingList = Database::select(
- '*',
- $this->table,
- $conditions
- );
- $isGlobal = $this->isGlobalConference();
- $newMeetingList = array();
- foreach ($meetingList as $meetingDB) {
- $item = array();
- $courseId = $meetingDB['c_id'];
- $courseInfo = api_get_course_info_by_id($courseId);
- $courseCode = $courseInfo['code'];
- if ($manager) {
- $pass = $this->getUserMeetingPassword($courseCode);
- } else {
- $pass = $this->getModMeetingPassword($courseCode);
- }
- $meetingBBB = $this->getMeetingInfo(
- [
- 'meetingId' => $meetingDB['remote_id'],
- 'password' => $pass
- ]
- );
- if ($meetingBBB === false) {
- //checking with the remote_id didn't work, so just in case and
- // to provide backwards support, check with the id
- $params = array(
- 'meetingId' => $meetingDB['id'],
- // -- REQUIRED - The unique id for the meeting
- 'password' => $pass
- // -- REQUIRED - The moderator password for the meeting
- );
- $meetingBBB = $this->getMeetingInfo($params);
- }
- if ($meetingDB['visibility'] == 0 && $this->isConferenceManager() === false) {
- continue;
- }
- $meetingBBB['end_url'] = $this->endUrl($meetingDB);
- if (isset($meetingBBB['returncode']) && (string) $meetingBBB['returncode'] == 'FAILED') {
- if ($meetingDB['status'] == 1 && $this->isConferenceManager()) {
- $this->endMeeting($meetingDB['id'], $courseCode);
- }
- } else {
- $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB);
- }
- if ($meetingDB['record'] == 1) {
- // backwards compatibility (when there was no remote ID)
- $mId = $meetingDB['remote_id'];
- if (empty($mId)) {
- $mId = $meetingDB['id'];
- }
- if (empty($mId)) {
- // if the id is still empty (should *never* occur as 'id' is
- // the table's primary key), skip this conference
- continue;
- }
- $record = [];
- if (empty($meetingDB['video_url'])) {
- $recordingParams = ['meetingId' => $mId];
- $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
- if (!empty($records)) {
- if (!isset($records['messageKey']) || $records['messageKey'] != 'noRecordings') {
- $record = end($records);
- if (!is_array($record) || !isset($record['recordId'])) {
- continue;
- }
- $this->updateMeetingVideoUrl($meetingDB['id'], $record['playbackFormatUrl']);
- if (!$this->isConferenceManager()) {
- $record = [];
- }
- }
- }
- } else {
- $record['playbackFormatUrl'] = $meetingDB['video_url'];
- }
- $recordLink = isset($record['playbackFormatUrl']) && !empty($record['playbackFormatUrl'])
- ? Display::url(
- $this->plugin->get_lang('ViewRecord'),
- $record['playbackFormatUrl'],
- ['target' => '_blank']
- )
- : get_lang('NoRecording');
- if ($isAdminReport) {
- $this->forceCIdReq($courseInfo['code'], $meetingDB['session_id'], $meetingDB['group_id']);
- }
- $actionLinks = $this->getActionLinks($meetingDB, $record, $isGlobal, $isAdminReport);
- $item['show_links'] = $recordLink;
- } else {
- $actionLinks = $this->getActionLinks($meetingDB, [], $isGlobal, $isAdminReport);
- $item['show_links'] = get_lang('NoRecording');
- }
- $item['action_links'] = implode(PHP_EOL, $actionLinks);
- $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
- // created_at
- $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
- $item['publish_url'] = $this->publishUrl($meetingDB);
- $item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
- if ($meetingDB['status'] == 1) {
- $joinParams = array(
- 'meetingId' => $meetingDB['remote_id'], //-- REQUIRED - A unique id for the meeting
- 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
- 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
- 'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
- 'userID' => '', // -- OPTIONAL - string
- 'webVoiceConf' => '' // -- OPTIONAL - string
- );
- $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
- }
- $item = array_merge($item, $meetingDB, $meetingBBB);
- $item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']);
- $item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']);
- $newMeetingList[] = $item;
- }
- return $newMeetingList;
- }
- /**
- * Function disabled
- */
- public function publishMeeting($id)
- {
- //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
- if (empty($id)) {
- return false;
- }
- $id = intval($id);
- Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
- return true;
- }
- /**
- * Function disabled
- */
- public function unpublishMeeting($id)
- {
- //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
- if (empty($id)) {
- return false;
- }
- $id = intval($id);
- Database::update($this->table, array('visibility' => 0), array('id = ?' => $id));
- return true;
- }
- /**
- * Closes a meeting (usually when the user click on the close button from
- * the conferences listing.
- * @param string The internal ID of the meeting (id field for this meeting)
- * @param string $courseCode
- *
- * @return void
- * @assert (0) === false
- */
- public function endMeeting($id, $courseCode = null)
- {
- if (empty($id)) {
- return false;
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- array('where' => array('id = ?' => array($id))),
- 'first'
- );
- $manager = $this->isConferenceManager();
- if ($manager) {
- $pass = $this->getUserMeetingPassword($courseCode);
- } else {
- $pass = $this->getModMeetingPassword($courseCode);
- }
- $endParams = array(
- 'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end.
- 'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
- );
- $this->api->endMeetingWithXmlResponseArray($endParams);
- Database::update(
- $this->table,
- array('status' => 0, 'closed_at' => api_get_utc_datetime()),
- array('id = ? ' => $id)
- );
- }
- /**
- * Gets the password for a specific meeting for the current user
- * @param string $courseCode
- * @return string A moderator password if user is teacher, or the course code otherwise
- *
- */
- public function getUserMeetingPassword($courseCode = null)
- {
- if ($this->isGlobalConferencePerUserEnabled()) {
- return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
- }
- if ($this->isGlobalConference()) {
- return 'url_'.api_get_current_access_url_id();
- }
- $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
- return $courseCode;
- }
- /**
- * Generated a moderator password for the meeting
- * @param string $courseCode
- *
- * @return string A password for the moderation of the videoconference
- */
- public function getModMeetingPassword($courseCode = null)
- {
- if ($this->isGlobalConferencePerUserEnabled()) {
- return 'url_'.$this->userId.'_'.api_get_current_access_url_id().'_mod';
- }
- if ($this->isGlobalConference()) {
- return 'url_'.api_get_current_access_url_id().'_mod';
- }
- $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
- return $courseCode.'mod';
- }
- /**
- * Get users online in the current course room
- * @return int The number of users currently connected to the videoconference
- * @assert () > -1
- */
- public function getUsersOnlineInCurrentRoom()
- {
- $courseId = api_get_course_int_id();
- $sessionId = api_get_session_id();
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? AND status = 1 AND access_url = ?' => array(
- $courseId,
- $sessionId,
- $this->accessUrl
- ),
- ),
- );
- if ($this->hasGroupSupport()) {
- $groupId = api_get_group_id();
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? AND group_id = ? AND status = 1 AND access_url = ?' => array(
- $courseId,
- $sessionId,
- $groupId,
- $this->accessUrl
- ),
- ),
- );
- }
- if ($this->isGlobalConferencePerUserEnabled()) {
- $conditions = array(
- 'where' => array(
- 'user_id = ? AND status = 1 AND access_url = ?' => array(
- $this->userId,
- $this->accessUrl
- ),
- ),
- );
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- $conditions,
- 'first'
- );
- if (empty($meetingData)) {
- return 0;
- }
- $pass = $this->getModMeetingPassword();
- $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass));
- if ($info === false) {
- //checking with the remote_id didn't work, so just in case and
- // to provide backwards support, check with the id
- $params = array(
- 'meetingId' => $meetingData['id'],
- // -- REQUIRED - The unique id for the meeting
- 'password' => $pass
- // -- REQUIRED - The moderator password for the meeting
- );
- $info = $this->getMeetingInfo($params);
- }
- if (!empty($info) && isset($info['participantCount'])) {
- return $info['participantCount'];
- }
- return 0;
- }
- /**
- * Deletes a previous recording of a meeting
- * @param int $id ID of the recording
- * @return array ?
- * @assert () === false
- * @todo Also delete links and agenda items created from this recording
- */
- public function deleteRecording($id)
- {
- if (empty($id)) {
- return false;
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- array('where' => array('id = ?' => array($id))),
- 'first'
- );
- $recordingParams = array(
- /*
- * NOTE: Set the recordId below to a valid id after you have
- * created a recorded meeting, and received a real recordID
- * back from your BBB server using the
- * getRecordingsWithXmlResponseArray method.
- */
- // REQUIRED - We have to know which recording:
- 'recordId' => $meetingData['remote_id'],
- );
- $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
- if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
- Database::delete(
- 'plugin_bbb_room',
- array('meeting_id = ?' => array($id))
- );
- Database::delete(
- $this->table,
- array('id = ?' => array($id))
- );
- }
- return $result;
- }
- /**
- * Creates a link in the links tool from the given videoconference recording
- * @param int $id ID of the item in the plugin_bbb_meeting table
- * @param string Hash identifying the recording, as provided by the API
- * @return mixed ID of the newly created link, or false on error
- * @assert (null, null) === false
- * @assert (1, null) === false
- * @assert (null, 'abcdefabcdefabcdefabcdef') === false
- */
- public function copyRecordingToLinkTool($id)
- {
- if (empty($id)) {
- return false;
- }
- //$records = BigBlueButtonBN::getRecordingsUrl($id);
- $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
- $records = $this->api->getRecordingsWithXmlResponseArray(array('meetingId' => $meetingData['remote_id']));
- if (!empty($records)) {
- if (isset($records['message']) && !empty($records['message'])) {
- if ($records['messageKey'] == 'noRecordings') {
- $recordArray[] = $this->plugin->get_lang('NoRecording');
- } else {
- //$recordArray[] = $records['message'];
- }
- return false;
- } else {
- $record = $records[0];
- if (is_array($record) && isset($record['recordId'])) {
- $url = $record['playbackFormatUrl'];
- $link = new Link();
- $params['url'] = $url;
- $params['title'] = $meetingData['meeting_name'];
- $id = $link->save($params);
- return $id;
- }
- }
- }
- return false;
- }
- /**
- * Checks if the video conference server is running.
- * Function currently disabled (always returns 1)
- * @return bool True if server is running, false otherwise
- * @assert () === false
- */
- public function isServerRunning()
- {
- return true;
- //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
- }
- /**
- * Get active session in the all platform
- */
- public function getActiveSessionsCount()
- {
- $meetingList = Database::select(
- 'count(id) as count',
- $this->table,
- array('where' => array('status = ? AND access_url = ?' => array(1, $this->accessUrl))),
- 'first'
- );
- return $meetingList['count'];
- }
- /**
- * @param string $url
- */
- public function redirectToBBB($url)
- {
- if (file_exists(__DIR__.'/../config.vm.php')) {
- // Using VM
- echo Display::url($this->plugin->get_lang('ClickToContinue'), $url);
- exit;
- } else {
- // Classic
- header("Location: $url");
- exit;
- }
- }
- /**
- * @return string
- */
- public function getUrlParams()
- {
- if (empty($this->courseCode)) {
- if ($this->isGlobalConferencePerUserEnabled()) {
- return 'global=1&user_id='.$this->userId;
- }
- if ($this->isGlobalConference()) {
- return 'global=1';
- }
- return '';
- }
- return http_build_query([
- 'cidReq' => $this->courseCode,
- 'id_session' => $this->sessionId,
- 'gidReq' => $this->groupId
- ]);
- }
- /**
- * @return string
- */
- public function getCurrentVideoConferenceName()
- {
- if ($this->isGlobalConferencePerUserEnabled()) {
- return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
- }
- if ($this->isGlobalConference()) {
- return 'url_'.api_get_current_access_url_id();
- }
- if ($this->hasGroupSupport()) {
- return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
- }
- return api_get_course_id().'-'.api_get_session_id();
- }
- /**
- * @return string
- */
- public function getConferenceUrl()
- {
- return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
- }
- /**
- * @return string
- */
- public function getListingUrl()
- {
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams();
- }
- /**
- * @param array $meeting
- * @return string
- */
- public function endUrl($meeting)
- {
- if (!isset($meeting['id'])) {
- return '';
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id'];
- }
- /**
- * @param array $meeting
- * @param array $record
- * @return string
- */
- public function addToCalendarUrl($meeting, $record = [])
- {
- $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
- 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;
- }
- /**
- * @param array $meeting
- * @return string
- */
- public function publishUrl($meeting)
- {
- if (!isset($meeting['id'])) {
- return '';
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=publish&id='.$meeting['id'];
- }
- /**
- * @param array $meeting
- * @return string
- */
- public function unPublishUrl($meeting)
- {
- if (!isset($meeting['id'])) {
- return null;
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=unpublish&id='.$meeting['id'];
- }
- /**
- * @param array $meeting
- * @return string
- */
- public function deleteRecordUrl($meeting)
- {
- if (!isset($meeting['id'])) {
- return '';
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=delete_record&id='.$meeting['id'];
- }
- /**
- * @param array $meeting
- * @return string
- */
- public function copyToRecordToLinkTool($meeting)
- {
- if (!isset($meeting['id'])) {
- return '';
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
- }
- /**
- * Get the meeting info from DB by its name
- * @param string $name
- * @return array
- */
- public function findMeetingByName($name)
- {
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_meeting',
- array('where' => array('meeting_name = ? AND status = 1 ' => $name)),
- 'first'
- );
- return $meetingData;
- }
- /**
- * @param int $meetingId
- * @return array
- */
- public function findMeetingParticipants($meetingId)
- {
- $em = Database::getManager();
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_room',
- array('where' => array('meeting_id = ?' => intval($meetingId)))
- );
- $participantIds = [];
- $return = [];
- foreach ($meetingData as $participantInfo) {
- if (in_array($participantInfo['participant_id'], $participantIds)) {
- continue;
- }
- $participantIds[] = $participantInfo['participant_id'];
- $return[] = [
- 'id' => $participantInfo['id'],
- 'meeting_id' => $participantInfo['meeting_id'],
- 'participant' => $em->find('ChamiloUserBundle:User', $participantInfo['participant_id']),
- 'in_at' => $participantInfo['in_at'],
- 'out_at' => $participantInfo['out_at']
- ];
- }
- return $return;
- }
- /**
- * @param array $meetingInfo
- * @param array $recordInfo
- * @param bool $isGlobal
- * @param bool $isAdminReport
- * @return array
- */
- private function getActionLinks($meetingInfo, $recordInfo, $isGlobal = false, $isAdminReport = false)
- {
- $isVisible = $meetingInfo['visibility'] != 0;
- $linkVisibility = $isVisible
- ? Display::url(
- Display::return_icon('visible.png', get_lang('MakeInvisible')),
- $this->unPublishUrl($meetingInfo)
- )
- : Display::url(
- Display::return_icon('invisible.png', get_lang('MakeVisible')),
- $this->publishUrl($meetingInfo)
- );
- $links = [];
- if (empty($recordInfo)) {
- if (!$isAdminReport) {
- $links[] = Display::url(
- Display::return_icon('delete.png', get_lang('Delete')),
- $this->deleteRecordUrl($meetingInfo)
- );
- $links[] = $linkVisibility;
- return $links;
- } else {
- $links[] = Display::url(
- Display::return_icon('course_home.png', get_lang('GoToCourse')),
- $this->getListingUrl()
- );
- return $links;
- }
- }
- if (!$isGlobal) {
- $links[] = Display::url(
- Display::return_icon('link.gif', get_lang('UrlMeetingToShare')),
- $this->copyToRecordToLinkTool($meetingInfo)
- );
- $links[] = Display::url(
- Display::return_icon('agenda.png', get_lang('AddToCalendar')),
- $this->addToCalendarUrl($meetingInfo, $recordInfo)
- );
- }
- if ($meetingInfo['has_video_m4v']) {
- $links[] = Display::url(
- Display::return_icon('save.png', get_lang('DownloadFile')),
- $recordInfo['playbackFormatUrl'].'/capture.m4v',
- ['target' => '_blank']
- );
- } else {
- $links[] = Display::url(
- Display::return_icon('save.png', get_lang('DownloadFile')),
- '#',
- [
- 'id' => "btn-check-meeting-video-{$meetingInfo['id']}",
- 'class' => 'check-meeting-video',
- 'data-id' => $meetingInfo['id']
- ]
- );
- }
- if (!$isAdminReport) {
- $links[] = Display::url(
- Display::return_icon('delete.png', get_lang('Delete')),
- $this->deleteRecordUrl($meetingInfo)
- );
- $links[] = $linkVisibility;
- } else {
- $links[] = Display::url(
- Display::return_icon('course_home.png', get_lang('GoToCourse')),
- $this->getListingUrl()
- );
- }
- return $links;
- }
- /**
- * @param int $meetingId
- * @param string $videoUrl
- * @return bool|int
- */
- public function updateMeetingVideoUrl($meetingId, $videoUrl)
- {
- return Database::update(
- 'plugin_bbb_meeting',
- ['video_url' => $videoUrl],
- ['id = ?' => intval($meetingId)]
- );
- }
- /**
- * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated
- * @param int $meetingId
- * @return bool
- */
- public function checkDirectMeetingVideoUrl($meetingId)
- {
- $meetingInfo = Database::select(
- '*',
- 'plugin_bbb_meeting',
- [
- 'where' => ['id = ?' => intval($meetingId)]
- ],
- 'first'
- );
- if (!isset($meetingInfo['video_url'])) {
- return false;
- }
- $hasCapture = SocialManager::verifyUrl($meetingInfo['video_url'].'/capture.m4v');
- if ($hasCapture) {
- return Database::update(
- 'plugin_bbb_meeting',
- ['has_video_m4v' => true],
- ['id = ?' => intval($meetingId)]
- );
- }
- return $hasCapture;
- }
- }
|