Browse Source

Update plugin with sedra changes

jmontoyaa 8 years ago
parent
commit
5562832a4c

+ 7 - 1
plugin/bbb/changelog.md

@@ -1,4 +1,10 @@
-Version 2.4 2016-05
+Version 2.5 - 2016-07
+---------------------
+* User global conference support
+   * Requires a database change: "ALTER TABLE plugin_bbb_meeting ADD COLUMN user_id INT DEFAULT 0"
+   * Requires a database change: "ALTER TABLE plugin_bbb_meeting ADD COLUMN access_url INT DEFAULT 0"
+   
+Version 2.4 - 2016-05
 ------------------------
 Changes:
 

+ 1 - 0
plugin/bbb/lang/english.php

@@ -46,6 +46,7 @@ $strings['tool_enable_help'] = "Choose whether you want to enable the BigBlueBut
 
 $strings['big_blue_button_welcome_message'] = 'Welcome message';
 $strings['enable_global_conference'] = 'Enable global conference';
+$strings['enable_global_conference_per_user'] = 'Enable global conference per user';
 $strings['enable_conference_in_course_groups'] = 'Enable conference in course groups';
 $strings['enable_global_conference_link'] = 'Enable the link to the global conference in the homepage';
 

+ 83 - 13
plugin/bbb/lib/bbb.lib.php

@@ -26,10 +26,12 @@ class bbb
     public $logoutUrl = '';
     public $pluginEnabled = false;
     public $enableGlobalConference = false;
+    public $enableGlobalConferencePerUser = false;
     public $isGlobalConference = false;
     public $groupSupport = false;
-    public $table;
+    public $userSupport = false;
     public $accessUrl = 1;
+    public $userId = 0;
 
     /**
      * Constructor (generates a connection to the API and the Chamilo settings
@@ -37,8 +39,9 @@ class bbb
      * @param string $host
      * @param string $salt
      * @param bool $isGlobalConference
+     * @param int $isGlobalPerUser
      */
-    public function __construct($host = '', $salt = '', $isGlobalConference = false)
+    public function __construct($host = '', $salt = '', $isGlobalConference = false, $isGlobalPerUser = 0)
     {
         // Initialize video server settings from global settings
         $plugin = BBBPlugin::create();
@@ -50,20 +53,24 @@ class bbb
 
         $this->logoutUrl = $this->getListingUrl();
         $this->table = Database::get_main_table('plugin_bbb_meeting');
-
-        $this->enableGlobalConference = $plugin->get('enable_global_conference');
+        $this->enableGlobalConference = (bool) $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) $plugin->get('enable_global_conference_per_user');
+            $this->userId = $isGlobalPerUser;
+        } else {
+            $this->enableGlobalConferencePerUser = false;
+        }
+
         if ($this->groupSupport) {
             // Plugin check
             $this->groupSupport = (bool) $plugin->get('enable_conference_in_course_groups');
-
             if ($this->groupSupport) {
 
                 // Platform check
@@ -105,7 +112,15 @@ class bbb
      */
     public function isGlobalConferenceEnabled()
     {
-        return (bool) $this->enableGlobalConference;
+        return $this->enableGlobalConference;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isGlobalConferencePerUserEnabled()
+    {
+        return $this->enableGlobalConferencePerUser;
     }
 
     /**
@@ -181,8 +196,14 @@ class bbb
             $params['group_id'] = api_get_group_id();
         }
 
-        $courseCode = is_null($courseCode) ? '' : $courseCode;
-        $params['attendee_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $courseCode;
+        if ($this->isGlobalConferencePerUserEnabled()) {
+            $currentUserId = api_get_user_id();
+            if ($this->userId === $currentUserId) {
+                $params['user_id'] = $this->userId;
+            }
+        }
+
+        $params['attendee_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getUserMeetingPassword();
         $attendeePassword = $params['attendee_pw'];
         $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
         $moderatorPassword = $params['moderator_pw'];
@@ -485,6 +506,9 @@ class bbb
     public function getMeetings()
     {
         $pass = $this->getUserMeetingPassword();
+        $isGlobal = $this->isGlobalConference();
+        $isGlobalPerUser = $this->isGlobalConferencePerUserEnabled();
+
         $courseId = api_get_course_int_id();
         $sessionId = api_get_session_id();
 
@@ -508,6 +532,15 @@ class bbb
             );
         }
 
+        if ($isGlobalPerUser) {
+            $conditions =  array(
+                'where' => array(
+                    'user_id = ? AND access_url = ?' =>
+                        array($this->userId, $this->accessUrl)
+                )
+            );
+        }
+
         $meetingList = Database::select(
             '*',
             $this->table,
@@ -804,6 +837,11 @@ class bbb
             return $this->getModMeetingPassword();
         } else {
 
+            if ($this->isGlobalConferencePerUserEnabled()) {
+
+                return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
+            }
+
             if ($this->isGlobalConference()) {
 
                 return 'url_'.api_get_current_access_url_id();
@@ -819,6 +857,11 @@ class bbb
      */
     public function getModMeetingPassword()
     {
+        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';
@@ -860,6 +903,18 @@ class bbb
                 ),
             );
         }
+
+        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,
@@ -893,7 +948,7 @@ class bbb
 
     /**
      * Deletes a previous recording of a meeting
-     * @param int integral ID of the recording
+     * @param int $id ID of the recording
      * @return array ?
      * @assert () === false
      * @todo Also delete links and agenda items created from this recording
@@ -901,6 +956,7 @@ class bbb
     public function deleteRecord($id)
     {
         if (empty($id)) {
+
             return false;
         }
 
@@ -925,7 +981,7 @@ class bbb
 
         $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
 
-        if (!empty($result) && isset($result['deleted']) && $result['deleted'] == 'true') {
+        if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
             Database::delete(
                 $this->table,
                 array('id = ?' => array($id))
@@ -937,7 +993,7 @@ class bbb
 
     /**
      * Creates a link in the links tool from the given videoconference recording
-     * @param int ID of the item in the plugin_bbb_meeting table
+     * @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
@@ -970,6 +1026,7 @@ class bbb
                     $params['url'] = $url;
                     $params['title'] = $meetingData['meeting_name'];
                     $id = $link->save($params);
+
                     return $id;
                 }
             }
@@ -1030,7 +1087,14 @@ class bbb
 
         if (empty($courseInfo)) {
 
+            if ($this->isGlobalConferencePerUserEnabled()) {
+
+                return 'global=1&user_id='.$this->userId;
+            }
+
+
             if ($this->isGlobalConference()) {
+
                 return 'global=1';
             }
 
@@ -1045,7 +1109,13 @@ class bbb
      */
     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();
         }
 

+ 3 - 1
plugin/bbb/lib/bbb_plugin.class.php

@@ -34,13 +34,14 @@ class BBBPlugin extends Plugin
     protected function __construct()
     {
         parent::__construct(
-            '2.4',
+            '2.5',
             'Julio Montoya, Yannick Warnier',
             [
                 'tool_enable' => 'boolean',
                 'host' => 'text',
                 'salt' => 'text',
                 'enable_global_conference' => 'boolean',
+                'enable_global_conference_per_user' => 'boolean',
                 'enable_conference_in_course_groups' => 'boolean',
                 'enable_global_conference_link' => 'boolean'
             ]
@@ -84,6 +85,7 @@ class BBBPlugin extends Plugin
                 id INT unsigned NOT NULL auto_increment PRIMARY KEY,
                 c_id INT unsigned NOT NULL DEFAULT 0,
                 group_id INT unsigned NOT NULL DEFAULT 0,
+                user_id INT unsigned NOT NULL DEFAULT 0,
                 meeting_name VARCHAR(255) NOT NULL DEFAULT '',
                 attendee_pw VARCHAR(255) NOT NULL DEFAULT '',
                 moderator_pw VARCHAR(255) NOT NULL DEFAULT '',

+ 4 - 2
plugin/bbb/listing.php

@@ -11,9 +11,9 @@ $plugin = BBBPlugin::create();
 $tool_name = $plugin->get_lang('Videoconference');
 
 $isGlobal = isset($_GET['global']) ? true : false;
+$isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id']: false;
 
-$bbb = new bbb('', '', $isGlobal);
-
+$bbb = new bbb('', '', $isGlobal, $isGlobalPerUser);
 $action = isset($_GET['action']) ? $_GET['action'] : null;
 
 $conferenceManager = $bbb->isConferenceManager();
@@ -105,6 +105,7 @@ if ($conferenceManager) {
             break;
     }
 }
+
 $meetings = $bbb->getMeetings();
 if (!empty($meetings)) {
     $meetings = array_reverse($meetings);
@@ -163,6 +164,7 @@ if ($bbb->isGlobalConference() === false &&
 $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('bbb_status', $status);

+ 0 - 2
plugin/bbb/readme.txt

@@ -1,2 +0,0 @@
-This plugin will create a link in existing and new courses for the teachers to start a videoconference room,
-as well as the administration settings to configure this tool.

+ 2 - 1
plugin/bbb/start.php

@@ -16,7 +16,8 @@ $vmIsEnabled = false;
 $host = '';
 $salt = '';
 $isGlobal = isset($_GET['global']) ? true : false;
-$bbb = new bbb('', '', $isGlobal);
+$isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id']: false;
+$bbb = new bbb('', '', $isGlobal, $isGlobalPerUser);
 
 if ($bbb->pluginEnabled) {
     if ($bbb->isServerRunning()) {