Procházet zdrojové kódy

Merge branch 'bbb-plugin-limit' into 1.11.x

Yannick Warnier před 7 roky
rodič
revize
4fe908257d

+ 9 - 1
plugin/bbb/README.md

@@ -25,7 +25,7 @@ You need execute this SQL query in your database after making the Chamilo migrat
 ALTER TABLE plugin_bbb_meeting ADD user_id int unsigned NOT NULL DEFAULT 0;
 ALTER TABLE plugin_bbb_meeting ADD access_url int NOT NULL DEFAULT 1;
 ```
-For the version 2.5 you need execute these SQL queries
+For version 2.5 you need execute these SQL queries
 ```sql
 CREATE TABLE plugin_bbb_room (
     id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -38,4 +38,12 @@ CREATE TABLE plugin_bbb_room (
 );
 ALTER TABLE plugin_bbb_meeting ADD video_url TEXT NULL;
 ALTER TABLE plugin_bbb_meeting ADD has_video_m4v TINYINT NOT NULL DEFAULT 0;
+ALTER TABLE plugin_bbb_meeting ADD COLUMN user_id INT DEFAULT 0;
+ALTER TABLE plugin_bbb_meeting ADD COLUMN access_url INT DEFAULT 0;
+```
+For version 2.6 (adding limits) you need execute these SQL queries
+```sql
+INSERT INTO chamilo111x.settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) VALUES ('bbb_max_users_limit', 'bbb', 'setting', 'Plugins', '3', 'bbb', null, null, null, 1, 1, 0);
+INSERT INTO chamilo111x.extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES (2, 15, 'plugin_bbb_course_users_limit', 'MaxUsersInConferenceRoom', '0', 1, 1, 0, 1, null, '2017-05-28 01:19:32');
+INSERT INTO chamilo111x.extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES (3, 15, 'plugin_bbb_session_users_limit', 'MaxUsersInConferenceRoom', null, 1, 1, 0, 1, null, '2017-05-28 01:19:32');
 ```

+ 8 - 0
plugin/bbb/changelog.md

@@ -1,3 +1,11 @@
+Version 2.6 - 2017-05
+---------------------
+* Add max users limit
+  * Requires the following database changes
+    * INSERT INTO chamilo111x.settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) VALUES ('bbb_max_users_limit', 'bbb', 'setting', 'Plugins', '3', 'bbb', null, null, null, 1, 1, 0);
+    * INSERT INTO chamilo111x.extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES (2, 15, 'plugin_bbb_course_users_limit', 'MaxUsersInConferenceRoom', '0', 1, 1, 0, 1, null, '2017-05-28 01:19:32');
+    * INSERT INTO chamilo111x.extra_field (extra_field_type, field_type, variable, display_text, default_value, field_order, visible_to_self, visible_to_others, changeable, filter, created_at) VALUES (3, 15, 'plugin_bbb_session_users_limit', 'MaxUsersInConferenceRoom', null, 1, 1, 0, 1, null, '2017-05-28 01:19:32');
+
 Version 2.5 - 2016-07
 ---------------------
 * User global conference support

+ 6 - 0
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';

+ 6 - 0
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';

+ 6 - 0
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';

+ 61 - 3
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;

+ 30 - 8
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);

+ 8 - 5
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);

+ 28 - 16
plugin/bbb/listing.tpl

@@ -1,24 +1,36 @@
 <div class ="row">
 
 {% if bbb_status == true %}
-  {% if show_join_button == true %}
     <div class ="span12" style="text-align:center">
-        {{ form }}
-        <p>
-            <a href="{{ conference_url }}" target="_blank" class="btn btn-primary btn-large">
-                {{ 'EnterConference'|get_lang }}
-            </a>
-            <span id="users_online" class="label label-warning">
-                {{ 'XUsersOnLine'| get_lang | format(users_online) }}
-            </span>
-        </p>
-
-        <div class="well">
-            <strong>{{ 'UrlMeetingToShare'|get_lang }}</strong>
-            <input type="text" class="form-control text-center" readonly value="{{ conference_url }}">
-        </div>
+        {% if show_join_button == true %}
+            {{ form }}
+            <p>
+                <a href="{{ conference_url }}" target="_blank" class="btn btn-primary btn-large">
+                    {{ 'EnterConference'|get_lang }}
+                </a>
+                <span id="users_online" class="label label-warning">
+                    {{ 'XUsersOnLine'| get_lang | format(users_online) }}
+                </span>
+            </p>
+            {% if max_users_limit > 0 %}
+                {% if conference_manager == true %}
+                    <p>{{ 'MaxXUsersWarning' | get_lang | format(max_users_limit) }}</p>
+                {% elseif users_online >= max_users_limit/2 %}
+                    <p>{{ 'MaxXUsersWarning' | get_lang | format(max_users_limit) }}</p>
+                {% endif %}
+            {% endif %}
+            <div class="well">
+                <strong>{{ 'UrlMeetingToShare'|get_lang }}</strong>
+                <input type="text" class="form-control text-center" readonly value="{{ conference_url }}">
+            </div>
+        {% elseif max_users_limit > 0 %}
+            {% if conference_manager == true %}
+                <p>{{ 'MaxXUsersReachedManager' | get_lang | format(max_users_limit) }}</p>
+            {% elseif users_online > 0 %}
+                <p>{{ 'MaxXUsersReached' | get_lang | format(max_users_limit) }}</p>
+            {% endif %}
+        {% endif %}
     </div>
-  {% endif %}
 
     <div class ="span12">
         <div class="page-header">