123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794 |
- <?php
- 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;
-
- 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();
-
- $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->table = Database::get_main_table('plugin_bbb_meeting');
- $this->enableGlobalConference = $this->plugin->get('enable_global_conference') === 'true' ? true : false;
- $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();
- $this->enableGlobalConferencePerUser = false;
- if ($this->userSupport && !empty($isGlobalPerUser)) {
- $this->enableGlobalConferencePerUser = $this->plugin->get('enable_global_conference_per_user') === 'true' ? true : false;
- $this->userId = $isGlobalPerUser;
- }
- if ($this->groupSupport) {
-
- $this->groupSupport = $this->plugin->get('enable_conference_in_course_groups') === 'true' ? true : false;
- if ($this->groupSupport) {
-
- $bbbSetting = api_get_setting('bbb_enable_conference_in_course_groups');
- $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
- if ($bbbSetting) {
-
- $courseInfo = api_get_course_info();
- if ($courseInfo) {
- $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups', $courseInfo) === '1';
- }
- }
- }
- }
- $this->maxUsersLimit = $this->plugin->get('max_users_limit');
- if ($bbbPluginEnabled === 'true') {
- $userInfo = api_get_user_info();
- if (empty($userInfo) && !empty($isGlobalPerUser)) {
-
-
-
- $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);
- $urlWithProtocol = $bbb_host;
- } else {
-
- $urlWithProtocol = 'http://'.$bbb_host;
- }
-
- define('CONFIG_SECURITY_SALT', $this->salt);
- define('CONFIG_SERVER_URL_WITH_PROTOCOL', $urlWithProtocol);
- define('CONFIG_SERVER_BASE_URL', $this->url);
- $this->api = new BigBlueButtonBN();
- $this->pluginEnabled = true;
- $this->logoutUrl = $this->getListingUrl();
- }
- }
-
- public function forceCIdReq($courseCode, $sessionId = 0, $groupId = 0)
- {
- $this->courseCode = $courseCode;
- $this->sessionId = (int) $sessionId;
- $this->groupId = (int) $groupId;
- }
-
- public function isGlobalConferenceEnabled()
- {
- return $this->enableGlobalConference;
- }
-
- public function isGlobalConferencePerUserEnabled()
- {
- return $this->enableGlobalConferencePerUser;
- }
-
- public function isGlobalConference()
- {
- if ($this->isGlobalConferenceEnabled() === false) {
- return false;
- }
- return (bool) $this->isGlobalConference;
- }
-
- public function hasGroupSupport()
- {
- return $this->groupSupport;
- }
-
- 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;
- }
-
- public function getMaxUsersLimit()
- {
- $limit = $this->maxUsersLimit;
- if ($limit <= 0) {
- $limit = 0;
- }
- $courseLimit = 0;
- $sessionLimit = 0;
-
-
-
- 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 = (int) $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 = (int) $value['value'];
- }
- }
- if (!empty($sessionLimit)) {
- return $sessionLimit;
- } elseif (!empty($courseLimit)) {
- return $courseLimit;
- }
- return (int) $limit;
- }
-
- public function setMaxUsersLimit($max)
- {
- if ($max < 0) {
- $max = 0;
- }
- $this->maxUsersLimit = (int) $max;
- }
-
- public function createMeeting($params)
- {
- $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() && !empty($this->userId)) {
- $params['user_id'] = (int) $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') == 1 ? true : false;
- $max = api_get_course_setting('big_blue_button_max_students_allowed');
- $max = isset($max) ? $max : -1;
- $params['status'] = 1;
-
-
- $params['remote_id'] = uniqid(true, true);
-
-
- $params['voice_bridge'] = rand(10000, 99999);
- $params['created_at'] = api_get_utc_datetime();
- $params['access_url'] = $this->accessUrl;
-
- $interfaceFeature = $this->plugin->get('interface');
- if ($interfaceFeature === false) {
- if (isset($params['interface'])) {
- unset($params['interface']);
- }
- }
- $id = Database::insert($this->table, $params);
- if ($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 = 300;
- $bbbParams = array(
- 'meetingId' => $params['remote_id'],
- 'meetingName' => $meetingName,
- 'attendeePw' => $attendeePassword,
- 'moderatorPw' => $moderatorPassword,
- 'welcomeMsg' => $welcomeMessage,
- 'dialNumber' => '',
- 'voiceBridge' => $params['voice_bridge'],
- 'webVoice' => '',
- 'logoutUrl' => $this->logoutUrl.'&action=logout&remote_id='.$params['remote_id'],
- 'maxParticipants' => $max,
- 'record' => $record,
- 'duration' => $duration,
-
- );
- $status = false;
- $meeting = null;
- while ($status === false) {
- $result = $this->api->createMeetingWithXmlResponseArray($bbbParams);
- if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
- if ($this->plugin->get('allow_regenerate_recording') === 'true') {
- $internalId = Database::escape_string($result['internalMeetingID']);
- $sql = "UPDATE $this->table SET internal_meeting_id = '".$internalId."'
- WHERE id = $id";
- Database::query($sql);
- }
- $meeting = $this->joinMeeting($meetingName, true);
- return $meeting;
- }
- }
- }
- return false;
- }
-
- public function saveParticipant($meetingId, $participantId, $interface = 0)
- {
- $params = [
- 'meeting_id' => $meetingId,
- 'participant_id' => $participantId,
- 'in_at' => api_get_utc_datetime(),
- 'out_at' => api_get_utc_datetime()
- ];
- if ($this->plugin->get('interface') !== false) {
- $params['interface'] = $interface;
- }
- return Database::insert(
- 'plugin_bbb_room',
- $params
- );
- }
-
- public function getMeetingByName($meetingName)
- {
- if (empty($meetingName)) {
- return [];
- }
- $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));
- }
- return $meetingData;
- }
-
- public function meetingExists($meetingName)
- {
- $meetingData = $this->getMeetingByName($meetingName);
- return !empty($meetingData);
- }
-
- public function joinMeeting($meetingName)
- {
- if ($this->debug) {
- error_log("joinMeeting: $meetingName");
- }
- 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'],
-
- 'password' => $this->getModMeetingPassword()
-
- );
- $meetingInfoExists = false;
- $meetingIsRunningInfo = $this->getMeetingInfo($params);
- if ($this->debug) {
- error_log('Searching meeting with params:');
- error_log(print_r($params, 1));
- error_log('Result:');
- error_log(print_r($meetingIsRunningInfo, 1));
- }
- if ($meetingIsRunningInfo === false) {
-
-
- $params = array(
- 'meetingId' => $meetingData['id'],
-
- 'password' => $this->getModMeetingPassword()
-
- );
- $meetingIsRunningInfo = $this->getMeetingInfo($params);
- if ($this->debug) {
- error_log('Searching meetingId with params:');
- error_log(print_r($params, 1));
- error_log('Result:');
- error_log(print_r($meetingIsRunningInfo, 1));
- }
- }
- if (strval($meetingIsRunningInfo['returncode']) === 'SUCCESS' &&
- isset($meetingIsRunningInfo['meetingName']) &&
- !empty($meetingIsRunningInfo['meetingName'])
- ) {
- $meetingInfoExists = true;
- }
- if ($this->debug) {
- error_log(
- "meeting is running: ".intval($meetingInfoExists)
- );
- }
- $url = false;
- if ($meetingInfoExists) {
- $joinParams = [
- 'meetingId' => $meetingData['remote_id'],
- 'username' => $this->userCompleteName,
- 'password' => $pass,
-
- 'userID' => api_get_user_id(),
- 'webVoiceConf' => '',
- 'interface' => $this->checkInterface($meetingData),
- ];
- $url = $this->api->getJoinMeetingURL($joinParams);
- $url = $this->protocol.$url;
- }
- if ($this->debug) {
- error_log("return url :".$url);
- }
- return $url;
- }
-
- 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.");
- }
- }
- return $result;
- } catch (Exception $e) {
- if ($this->debug) {
- error_log('Caught exception: ', $e->getMessage(), "\n");
- }
- }
- return false;
- }
-
- 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;
- }
-
- 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 ($this->isGlobalConferencePerUserEnabled()) {
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND session_id = ? AND user_id = ?' => array(
- $courseId,
- $sessionId,
- $this->userId
- ),
- ),
- );
- }
- }
- 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),
- ),
- );
- }
- $conditions['order'] = 'created_at ASC';
- $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 = '';
- if (!empty($courseInfo)) {
- $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) {
-
-
- $params = array(
- 'meetingId' => $meetingDB['id'],
-
- 'password' => $pass
-
- );
- $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) {
-
- $mId = $meetingDB['remote_id'];
- if (empty($mId)) {
- $mId = $meetingDB['id'];
- }
- if (empty($mId)) {
-
-
- continue;
- }
- $record = [];
- $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;
- }
- if (!empty($record['playbackFormatUrl'])) {
- $this->updateMeetingVideoUrl($meetingDB['id'], $record['playbackFormatUrl']);
- }
-
- }
- }
- if (isset($record['playbackFormatUrl']) && !empty($record['playbackFormatUrl'])) {
- $recordLink = Display::url(
- $this->plugin->get_lang('ViewRecord'),
- $record['playbackFormatUrl'],
- ['target' => '_blank', 'class' => 'btn btn-default']
- );
- } else {
- $recordLink = $this->plugin->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'] = $this->plugin->get_lang('NoRecording');
- }
- $item['action_links'] = implode(PHP_EOL, $actionLinks);
- $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
-
- $meetingDB['created_at'] = $item['created_at'];
- $item['publish_url'] = $this->publishUrl($meetingDB);
- $item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
- if ($meetingDB['status'] == 1) {
- $joinParams = [
- 'meetingId' => $meetingDB['remote_id'],
- 'username' => $this->userCompleteName,
- 'password' => $pass,
- 'createTime' => '',
- 'userID' => '',
- 'webVoiceConf' => '',
- 'interface' => $this->checkInterface($meetingDB),
- ];
- $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;
- }
-
- public function checkInterface($meetingInfo)
- {
- $interface = BBBPlugin::LAUNCH_TYPE_DEFAULT;
- $type = $this->plugin->get('launch_type');
- switch ($type) {
- case BBBPlugin::LAUNCH_TYPE_DEFAULT:
- $interface = $this->plugin->get('interface');
- break;
- case BBBPlugin::LAUNCH_TYPE_SET_BY_TEACHER:
- if (isset($meetingInfo['interface'])) {
- $interface = $meetingInfo['interface'];
- }
- break;
- case BBBPlugin::LAUNCH_TYPE_SET_BY_STUDENT:
- if (isset($meetingInfo['id'])) {
- $roomInfo = $this->getMeetingParticipantInfo($meetingInfo['id'], api_get_user_id());
- if (!empty($roomInfo) && isset($roomInfo['interface'])) {
- $interface = $roomInfo['interface'];
- } else {
- if (isset($_REQUEST['interface'])) {
- $interface = isset($_REQUEST['interface']) ? (int) $_REQUEST['interface'] : 0;
- }
- }
- }
- break;
- }
- return $interface;
- }
-
- public function publishMeeting($id)
- {
-
- if (empty($id)) {
- return false;
- }
- $id = intval($id);
- Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
- return true;
- }
-
- public function unpublishMeeting($id)
- {
-
- if (empty($id)) {
- return false;
- }
- $id = intval($id);
- Database::update($this->table, array('visibility' => 0), array('id = ?' => $id));
- return true;
- }
-
- 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'],
- 'password' => $pass,
- );
- $this->api->endMeetingWithXmlResponseArray($endParams);
- Database::update(
- $this->table,
- array('status' => 0, 'closed_at' => api_get_utc_datetime()),
- array('id = ? ' => $id)
- );
- }
-
- 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;
- }
-
- 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';
- }
-
- 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) {
-
-
- $params = array(
- 'meetingId' => $meetingData['id'],
-
- 'password' => $pass
-
- );
- $info = $this->getMeetingInfo($params);
- }
- if (!empty($info) && isset($info['participantCount'])) {
- return $info['participantCount'];
- }
- return 0;
- }
-
- public function regenerateRecording($id, $recordId = '')
- {
- if ($this->plugin->get('allow_regenerate_recording') !== 'true') {
- return false;
- }
- if (empty($id)) {
- return false;
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- array('where' => array('id = ?' => array($id))),
- 'first'
- );
-
- $recordings = $this->api->getRecordings(['meetingId' => $meetingData['remote_id']]);
- if (!empty($recordings) && isset($recordings['messageKey']) && $recordings['messageKey'] === 'noRecordings') {
-
- if (!empty($meetingData['internal_meeting_id'])) {
- return $this->api->generateRecording(['recordId' => $meetingData['internal_meeting_id']]);
- }
-
- return false;
- } else {
- if (!empty($recordings['records'])) {
- $recordExists = false;
- foreach ($recordings['records'] as $record) {
- if ($recordId == $record['recordId']) {
- $recordExists = true;
- break;
- }
- }
- if ($recordExists) {
- return $this->api->generateRecording(['recordId' => $recordId]);
- }
- }
- }
- return false;
- }
-
- public function deleteRecording($id)
- {
- if (empty($id)) {
- return false;
- }
- $meetingData = Database::select(
- '*',
- $this->table,
- array('where' => array('id = ?' => array($id))),
- 'first'
- );
- $delete = false;
-
- $recordings = $this->api->getRecordings(['meetingId' => $meetingData['remote_id']]);
- if (!empty($recordings) && isset($recordings['messageKey']) && $recordings['messageKey'] == 'noRecordings') {
- $delete = true;
- } else {
- $recordsToDelete = [];
- if (!empty($recordings['records'])) {
- foreach ($recordings['records'] as $record) {
- $recordsToDelete[] = $record['recordId'];
- }
- $recordingParams = ['recordId' => implode(',', $recordsToDelete)];
- $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
- if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
- $delete = true;
- }
- }
- }
- if ($delete) {
- Database::delete(
- 'plugin_bbb_room',
- array('meeting_id = ?' => array($id))
- );
- Database::delete(
- $this->table,
- array('id = ?' => array($id))
- );
- }
- return $delete;
- }
-
- public function copyRecordingToLinkTool($id)
- {
- if (empty($id)) {
- return false;
- }
-
- $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 {
-
- }
- 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;
- }
-
- public function isServerRunning()
- {
- $host = $this->plugin->get('host');
- if (empty($host)) {
- return false;
- }
- return true;
-
- }
-
- 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'];
- }
-
- public function redirectToBBB($url)
- {
- if (file_exists(__DIR__.'/../config.vm.php')) {
-
- echo Display::url($this->plugin->get_lang('ClickToContinue'), $url);
- exit;
- } else {
-
- header("Location: $url");
- exit;
- }
- }
-
- 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
- ]);
- }
-
- 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();
- }
-
- public function getConferenceUrl()
- {
- return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
- }
-
- public function getListingUrl()
- {
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams();
- }
-
- 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'];
- }
-
- 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;
- }
-
- 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'];
- }
-
- 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'];
- }
-
- 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'];
- }
-
- public function regenerateRecordUrl($meeting, $recordInfo)
- {
- if ($this->plugin->get('allow_regenerate_recording') !== 'true') {
- return '';
- }
- if (!isset($meeting['id'])) {
- return '';
- }
- if (empty($recordInfo) || (!empty($recordInfo['recordId']) && !isset($recordInfo['recordId']))) {
- return '';
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().
- '&action=regenerate_record&id='.$meeting['id'].'&record_id='.$recordInfo['recordId'];
- }
-
- public function regenerateRecordUrlFromMeeting($meeting)
- {
- if ($this->plugin->get('allow_regenerate_recording') !== 'true') {
- return '';
- }
- if (!isset($meeting['id'])) {
- return '';
- }
- return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().
- '&action=regenerate_record&id='.$meeting['id'];
- }
-
- 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'];
- }
-
- public function findMeetingByName($name)
- {
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_meeting',
- array('where' => array('meeting_name = ? AND status = 1 ' => $name)),
- 'first'
- );
- return $meetingData;
- }
-
- public function getMeeting($id)
- {
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_meeting',
- array('where' => array('id = ?' => $id)),
- 'first'
- );
- return $meetingData;
- }
-
- public function getMeetingByRemoteId($id)
- {
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_meeting',
- array('where' => array('remote_id = ?' => $id)),
- 'first'
- );
- return $meetingData;
- }
-
- public function findConnectedMeetingParticipants($meetingId)
- {
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_room',
- array('where' => array('meeting_id = ? AND in_at IS NOT NULL' => $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' => api_get_user_entity($participantInfo['participant_id']),
- 'in_at' => $participantInfo['in_at'],
- 'out_at' => $participantInfo['out_at']
- ];
- }
- return $return;
- }
-
- public function getMeetingParticipantInfo($meetingId, $userId)
- {
- $meetingData = Database::select(
- '*',
- 'plugin_bbb_room',
- array('where' => array('meeting_id = ? AND participant_id = ?' => [$meetingId, $userId])),
- 'first'
- );
- if ($meetingData) {
- return $meetingData;
- }
- return [];
- }
-
- 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 ($this->plugin->get('allow_regenerate_recording') === 'true' && $meetingInfo['record'] == 1) {
- if (!empty($recordInfo)) {
- $links[] = Display::url(
- Display::return_icon('reload.png', get_lang('RegenerateRecord')),
- $this->regenerateRecordUrl($meetingInfo, $recordInfo)
- );
- } else {
- $links[] = Display::url(
- Display::return_icon('reload.png', get_lang('RegenerateRecord')),
- $this->regenerateRecordUrlFromMeeting($meetingInfo)
- );
- }
- }
- if (empty($recordInfo)) {
- if (!$isAdminReport) {
- if ($meetingInfo['status'] == 0) {
- $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)
- );
- }
- $hide = $this->plugin->get('disable_download_conference_link') === 'true' ? true : false;
- if ($hide == false) {
- 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;
- }
-
- public function updateMeetingVideoUrl($meetingId, $videoUrl)
- {
- return Database::update(
- 'plugin_bbb_meeting',
- ['video_url' => $videoUrl],
- ['id = ?' => intval($meetingId)]
- );
- }
-
- 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;
- }
-
- public static function showGlobalConferenceLink($userInfo)
- {
- if (empty($userInfo)) {
- return false;
- }
- $setting = api_get_plugin_setting('bbb', 'enable_global_conference');
- $settingLink = api_get_plugin_setting('bbb', 'enable_global_conference_link');
- if ($setting === 'true' && $settingLink === 'true') {
-
- $allowedRoles = api_get_plugin_setting(
- 'bbb',
- 'global_conference_allow_roles'
- );
- if (api_is_platform_admin()) {
- $userInfo['status'] = PLATFORM_ADMIN;
- }
- $showGlobalLink = true;
- if (!empty($allowedRoles)) {
- if (!in_array($userInfo['status'], $allowedRoles)) {
- $showGlobalLink = false;
- }
- }
- return $showGlobalLink;
- }
- }
- }
|