From f2109a10a17541f4fc806fbc4f33b29108934e34 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sat, 27 May 2017 00:40:22 -0500 Subject: [PATCH] Plugins: BBB: Add global limit to number of users per room, including extra fields for course and session to define contextual limits --- plugin/bbb/changelog.md | 5 +++ plugin/bbb/lang/english.php | 6 +++ plugin/bbb/lang/french.php | 6 +++ plugin/bbb/lang/spanish.php | 6 +++ plugin/bbb/lib/bbb.lib.php | 64 +++++++++++++++++++++++++++-- plugin/bbb/lib/bbb_plugin.class.php | 38 +++++++++++++---- plugin/bbb/listing.php | 13 +++--- plugin/bbb/listing.tpl | 44 ++++++++++++-------- 8 files changed, 150 insertions(+), 32 deletions(-) diff --git a/plugin/bbb/changelog.md b/plugin/bbb/changelog.md index dbafb30042..8b4620b478 100644 --- a/plugin/bbb/changelog.md +++ b/plugin/bbb/changelog.md @@ -1,3 +1,8 @@ +Version 2.6 - 2017-05 +--------------------- +* Add max users limit + * Requires a database change: "CREATE TABLE plugin_bbb_course_limit" (see bbb_plugin.class.php::install() for full query) + Version 2.5 - 2016-07 --------------------- * User global conference support diff --git a/plugin/bbb/lang/english.php b/plugin/bbb/lang/english.php index 72e9f8ea86..4919cc773a 100755 --- a/plugin/bbb/lang/english.php +++ b/plugin/bbb/lang/english.php @@ -60,3 +60,9 @@ $strings['NoGroup'] = 'No group'; $strings['UrlMeetingToShare'] = 'URL to share'; $strings['AdminView'] = 'View for administrators'; +$strings['max_users_limit'] = 'Max users limit'; +$strings['max_users_limit_help'] = 'Set this to the maximum number of users you want to allow by course or session-course. Leave empty or set to 0 to disable this limit.'; +$strings['MaxXUsersWarning'] = 'This conference room has a maximum number of %s simultaneous users.'; +$strings['MaxXUsersReached'] = 'The limit of %s simultaneous users has been reached for this conference room. Please wait for one seat to be freed or for another conference to start in order to join.'; +$strings['MaxXUsersReachedManager'] = 'The limit of %s simultaneous users has been reached for this conference room. To increase this limit, please contact the platform administrator.'; +$strings['MaxUsersInConferenceRoom'] = 'Max simultaneous users in a conference room'; diff --git a/plugin/bbb/lang/french.php b/plugin/bbb/lang/french.php index 324ce1966c..2e3a3fed6c 100755 --- a/plugin/bbb/lang/french.php +++ b/plugin/bbb/lang/french.php @@ -42,3 +42,9 @@ $strings['NoGroup'] = 'Sans groupe'; $strings['UrlMeetingToShare'] = 'URL à partager'; $strings['AdminView'] = 'View for administrators'; +$strings['max_users_limit'] = 'Utilisateurs maximum' ; +$strings['max_users_limit_help'] = 'Nombre maximum d\'utilisateurs simultanés dans une salle de vidéoconférence de cours ou cours-session. Laisser vide ou sur 0 pour ne pas assigner de limite.'; +$strings['MaxXUsersWarning'] = 'Cette salle de conférence est limitée à %s utilisateurs simultanés.'; +$strings['MaxXUsersReached'] = 'La limite de %s utilisateurs simultanés a été atteinte dans cette salle de conférence. Veuillez rafraîchir dans quelque minutes pour voir si un siège s\'est libéré, ou attendre l\'ouverture d\'une nouvelle salle de conférence pour participer.'; +$strings['MaxXUsersReachedManager'] = 'La limite de %s utilisateurs simultanés a été atteinte dans cette salle de conférence. Pour augmenter la limite, prenez contact avec l\'administrateur du portail.'; +$strings['MaxUsersInConferenceRoom'] = 'Nombre max d\'utilisateurs simultanés dans une salle de conférence'; diff --git a/plugin/bbb/lang/spanish.php b/plugin/bbb/lang/spanish.php index a9b5a03e72..ce74f4803c 100755 --- a/plugin/bbb/lang/spanish.php +++ b/plugin/bbb/lang/spanish.php @@ -51,3 +51,9 @@ $strings['ClickToContinue'] = 'Hacer click para continuar'; $strings['UrlMeetingToShare'] = 'URL a compartir'; $strings['AdminView'] = 'Vista para administradores'; +$strings['max_users_limit'] = 'Cantidad máxima de usuarios'; +$strings['max_users_limit_help'] = 'Este valor indica la cantidad máxima de usuarios simultáneos en una conferencia en un curso o curso-sesión. Dejar vacío o en 0 para no poner límite.'; +$strings['MaxXUsersWarning'] = 'Esta sala de conferencia es limitada a un máximo de %s usuarios simultáneos.'; +$strings['MaxXUsersReached'] = 'El límite de %s usuarios simultáneos ha sido alcanzado en esta sala de conferencia. Por favor refresque la página en unos minutos para ver si un asiento se ha liberado, o espere la apertura de una nueva sala para poder participar.'; +$strings['MaxXUsersReachedManager'] = 'El límite de %s usuarios simultáneos ha sido alcanzado en esta sala de conferencia. Para aumentar el límite, contáctese con el administrador del portal.'; +$strings['MaxUsersInConferenceRoom'] = 'Número máximo de usuarios simultáneos en una sala de conferencia'; diff --git a/plugin/bbb/lib/bbb.lib.php b/plugin/bbb/lib/bbb.lib.php index e0643f2c71..54eb8dbcbf 100755 --- a/plugin/bbb/lib/bbb.lib.php +++ b/plugin/bbb/lib/bbb.lib.php @@ -34,8 +34,10 @@ class bbb 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 @@ -48,6 +50,7 @@ class bbb 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(); @@ -94,6 +97,7 @@ class bbb } } } + $this->maxUsersLimit = $this->plugin->get('max_users_limit'); if ($bbbPluginEnabled === 'true') { $userInfo = api_get_user_info(); @@ -125,7 +129,7 @@ class bbb } /** - * Set forced the course, session or group IDs + * Force the course, session and/or group IDs * @param string $courseCode * @param int $sessionId * @param int $groupId @@ -200,6 +204,60 @@ class bbb 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 @@ -954,7 +1012,7 @@ class bbb * @assert () === false * @todo Also delete links and agenda items created from this recording */ - public function deleteRecord($id) + public function deleteRecording($id) { if (empty($id)) { @@ -1006,7 +1064,7 @@ class bbb * @assert (1, null) === false * @assert (null, 'abcdefabcdefabcdefabcdef') === false */ - public function copyRecordToLinkTool($id) + public function copyRecordingToLinkTool($id) { if (empty($id)) { return false; diff --git a/plugin/bbb/lib/bbb_plugin.class.php b/plugin/bbb/lib/bbb_plugin.class.php index 812abd24f7..68552711b4 100755 --- a/plugin/bbb/lib/bbb_plugin.class.php +++ b/plugin/bbb/lib/bbb_plugin.class.php @@ -43,7 +43,8 @@ class BBBPlugin extends Plugin 'enable_global_conference' => 'boolean', 'enable_global_conference_per_user' => 'boolean', 'enable_conference_in_course_groups' => 'boolean', - 'enable_global_conference_link' => 'boolean' + 'enable_global_conference_link' => 'boolean', + 'max_users_limit' => 'text', ] ); @@ -110,14 +111,27 @@ class BBBPlugin extends Plugin Database::query( "CREATE TABLE IF NOT EXISTS plugin_bbb_room ( id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - meeting_id int(10) unsigned NOT NULL, - participant_id int(11) NOT NULL, + meeting_id int unsigned NOT NULL, + participant_id int NOT NULL, in_at datetime NOT NULL, out_at datetime NOT NULL, FOREIGN KEY (meeting_id) REFERENCES plugin_bbb_meeting (id), FOREIGN KEY (participant_id) REFERENCES user (id) );" ); + $fieldLabel = 'plugin_bbb_course_users_limit'; + $fieldType = ExtraField::FIELD_TYPE_INTEGER; + $fieldTitle = 'MaxUsersInConferenceRoom'; + $fieldDefault = '0'; + $extraField = new ExtraField('course'); + $fieldId = CourseManager::create_course_extra_field($fieldLabel, $fieldType, $fieldTitle, $fieldDefault); + $extraField->find($fieldId); + $extraField->update(['id' => $fieldId, 'variable' => 'plugin_bbb_course_users_limit', 'changeable' => 1, 'visible_to_self' => 1, 'visible_to_others' => 0]); + $fieldLabel = 'plugin_bbb_session_users_limit'; + $extraField = new ExtraField('session'); + $fieldId = SessionManager::create_session_extra_field($fieldLabel, $fieldType, $fieldTitle, $fieldDefault); + $extraField->find($fieldId); + $extraField->update(['id' => $fieldId, 'variable' => 'plugin_bbb_session_users_limit', 'changeable' => 1, 'visible_to_self' => 1, 'visible_to_others' => 0]); // Installing course settings $this->install_course_fields_in_all_courses(); @@ -141,13 +155,24 @@ class BBBPlugin extends Plugin 'enable_conference_in_course_groups', 'bbb_plugin', 'bbb_plugin_host', - 'bbb_plugin_salt' + 'bbb_plugin_salt', + 'max_users_limit', ]; foreach ($variables as $variable) { $sql = "DELETE FROM $t_settings WHERE variable = '$variable'"; Database::query($sql); } + $extraField = new ExtraField('course'); + $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable('plugin_bbb_course_users_limit'); + if (!empty($extraFieldInfo)) { + $extraField->delete($extraFieldInfo['id']); + } + $extraField = new ExtraField('session'); + $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable('plugin_bbb_session_users_limit'); + if (!empty($extraFieldInfo)) { + $extraField->delete($extraFieldInfo['id']); + } $sql = "DELETE FROM $t_options WHERE variable = 'bbb_plugin'"; Database::query($sql); @@ -157,10 +182,7 @@ class BBBPlugin extends Plugin Database::query($sql); Database::query('DROP TABLE IF EXISTS plugin_bbb_room'); - - $t = Database::get_main_table('plugin_bbb_meeting'); - $sql = "DROP TABLE IF EXISTS $t"; - Database::query($sql); + Database::query('DROP TABLE IF EXISTS plugin_bbb_meeting'); // Deleting course settings $this->uninstall_course_fields_in_all_courses($this->course_settings); diff --git a/plugin/bbb/listing.php b/plugin/bbb/listing.php index 14f1de610e..26ddcfc6d4 100755 --- a/plugin/bbb/listing.php +++ b/plugin/bbb/listing.php @@ -59,7 +59,7 @@ if ($conferenceManager) { } break; case 'copy_record_to_link_tool': - $result = $bbb->copyRecordToLinkTool($_GET['id']); + $result = $bbb->copyRecordingToLinkTool($_GET['id']); if ($result) { $message = Display::return_message($plugin->get_lang('VideoConferenceAddedToTheLinkTool'), 'success'); } else { @@ -67,7 +67,7 @@ if ($conferenceManager) { } break; case 'delete_record': - $result = $bbb->deleteRecord($_GET['id']); + $result = $bbb->deleteRecording($_GET['id']); if ($result) { $message = Display::return_message(get_lang('Deleted'), 'success'); } else { @@ -124,11 +124,12 @@ $meetings = $bbb->getMeetings( if (!empty($meetings)) { $meetings = array_reverse($meetings); } -$users_online = $bbb->getUsersOnlineInCurrentRoom(); +$usersOnline = $bbb->getUsersOnlineInCurrentRoom(); +$maxUsers = $bbb->getMaxUsersLimit(); $status = $bbb->isServerRunning(); $meetingExists = $bbb->meetingExists($bbb->getCurrentVideoConferenceName()); $showJoinButton = false; -if ($meetingExists || $conferenceManager) { +if (($meetingExists || $conferenceManager) && ($maxUsers == 0 || $maxUsers > $usersOnline)) { $showJoinButton = true; } $conferenceUrl = $bbb->getConferenceUrl(); @@ -179,7 +180,9 @@ $tpl = new Template($tool_name); $tpl->assign('allow_to_edit', $conferenceManager); $tpl->assign('meetings', $meetings); $tpl->assign('conference_url', $conferenceUrl); -$tpl->assign('users_online', $users_online); +$tpl->assign('users_online', $usersOnline); +$tpl->assign('conference_manager', $conferenceManager); +$tpl->assign('max_users_limit', $maxUsers); $tpl->assign('bbb_status', $status); $tpl->assign('show_join_button', $showJoinButton); $tpl->assign('message', $message); diff --git a/plugin/bbb/listing.tpl b/plugin/bbb/listing.tpl index 2517e94f04..c2d83f12bc 100755 --- a/plugin/bbb/listing.tpl +++ b/plugin/bbb/listing.tpl @@ -1,24 +1,36 @@
{% if bbb_status == true %} - {% if show_join_button == true %}
- {{ form }} -

- - {{ 'EnterConference'|get_lang }} - - - {{ 'XUsersOnLine'| get_lang | format(users_online) }} - -

- -
- {{ 'UrlMeetingToShare'|get_lang }} - -
+ {% if show_join_button == true %} + {{ form }} +

+ + {{ 'EnterConference'|get_lang }} + + + {{ 'XUsersOnLine'| get_lang | format(users_online) }} + +

+ {% if max_users_limit > 0 %} + {% if conference_manager == true %} +

{{ 'MaxXUsersWarning' | get_lang | format(max_users_limit) }}

+ {% elseif users_online >= max_users_limit/2 %} +

{{ 'MaxXUsersWarning' | get_lang | format(max_users_limit) }}

+ {% endif %} + {% endif %} +
+ {{ 'UrlMeetingToShare'|get_lang }} + +
+ {% elseif max_users_limit > 0 %} + {% if conference_manager == true %} +

{{ 'MaxXUsersReachedManager' | get_lang | format(max_users_limit) }}

+ {% elseif users_online > 0 %} +

{{ 'MaxXUsersReached' | get_lang | format(max_users_limit) }}

+ {% endif %} + {% endif %}
- {% endif %}