Browse Source

Save participants when they join to videoconference - refs BT#11636

Angel Fernando Quiroz Campos 8 years ago
parent
commit
e074abcbad
5 changed files with 101 additions and 17 deletions
  1. 11 0
      plugin/bbb/admin.php
  2. 3 3
      plugin/bbb/admin.tpl
  3. 64 0
      plugin/bbb/lib/bbb.lib.php
  4. 14 0
      plugin/bbb/lib/bbb_plugin.class.php
  5. 9 14
      plugin/bbb/start.php

+ 11 - 0
plugin/bbb/admin.php

@@ -4,6 +4,8 @@
  * @package chamilo.plugin.bigbluebutton
  * @package chamilo.plugin.bigbluebutton
  */
  */
 
 
+use Chamilo\UserBundle\Entity\User;
+
 $course_plugin = 'bbb'; //needed in order to load the plugin lang variables
 $course_plugin = 'bbb'; //needed in order to load the plugin lang variables
 $cidReset = true;
 $cidReset = true;
 
 
@@ -20,6 +22,15 @@ $action = isset($_GET['action']) ? $_GET['action'] : null;
 
 
 $meetings = $bbb->getMeetings();
 $meetings = $bbb->getMeetings();
 
 
+foreach ($meetings as &$meeting) {
+    $participants = $bbb->findMeetingParticipants($meeting['id']);
+
+    /** @var User $participant */
+    foreach ($participants as $participant) {
+        $meeting['participants'][] = $participant['participant']->getCompleteName();
+    }
+}
+
 if ($action) {
 if ($action) {
     switch ($action) {
     switch ($action) {
         case 'export':
         case 'export':

+ 3 - 3
plugin/bbb/admin.tpl

@@ -30,10 +30,10 @@
                         {{ meeting.show_links }}
                         {{ meeting.show_links }}
                     {% endif %}
                     {% endif %}
                 </td>
                 </td>
-                <td>{{ meeting.course ? meeting.course.title : '-' }}</td>
-                <td>{{ meeting.session ? meeting.session.name : '-' }}</td>
+                <td>{{ meeting.course ?: '-' }}</td>
+                <td>{{ meeting.session ?: '-' }}</td>
                 <td>
                 <td>
-                    {{ meeting.participants|join('<br>') }}
+                    {{ meeting.participants ? meeting.participants|join('<br>') : '-' }}
                 </td>
                 </td>
             </tr>
             </tr>
         {% endfor %}
         {% endfor %}

+ 64 - 0
plugin/bbb/lib/bbb.lib.php

@@ -309,6 +309,25 @@ class bbb
         }
         }
     }
     }
 
 
+    /**
+     * 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
      * Tells whether the given meeting exists and is running
      * (using course code as name)
      * (using course code as name)
@@ -1235,4 +1254,49 @@ class bbb
 
 
         return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
         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)))
+        );
+
+        $return = [];
+
+        foreach ($meetingData as $participantInfo) {
+            $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;
+    }
 }
 }

+ 14 - 0
plugin/bbb/lib/bbb_plugin.class.php

@@ -105,6 +105,18 @@ class BBBPlugin extends Plugin
                 )";
                 )";
         Database::query($sql);
         Database::query($sql);
 
 
+        Database::query(
+            "CREATE TABLE plugin_bbb_room (
+                id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
+                meeting_id int(10) unsigned NOT NULL,
+                participant_id int(11) 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)
+            );"
+        );
+
         // Installing course settings
         // Installing course settings
         $this->install_course_fields_in_all_courses();
         $this->install_course_fields_in_all_courses();
     }
     }
@@ -146,6 +158,8 @@ class BBBPlugin extends Plugin
         $sql = "DROP TABLE IF EXISTS $t";
         $sql = "DROP TABLE IF EXISTS $t";
         Database::query($sql);
         Database::query($sql);
 
 
+        Database::query('DROP TABLE IF EXISTS plugin_bbb_room');
+
         // Deleting course settings
         // Deleting course settings
         $this->uninstall_course_fields_in_all_courses($this->course_settings);
         $this->uninstall_course_fields_in_all_courses($this->course_settings);
     }
     }

+ 9 - 14
plugin/bbb/start.php

@@ -50,23 +50,18 @@ if ($bbb->pluginEnabled) {
             $meetingParams = array();
             $meetingParams = array();
             $meetingParams['meeting_name'] = $bbb->getCurrentVideoConferenceName();
             $meetingParams['meeting_name'] = $bbb->getCurrentVideoConferenceName();
 
 
+
+
             if ($bbb->meetingExists($meetingParams['meeting_name'])) {
             if ($bbb->meetingExists($meetingParams['meeting_name'])) {
-                $url = $bbb->joinMeeting($meetingParams['meeting_name']);
-                if ($url) {
-                    $bbb->redirectToBBB($url);
-                } else {
-                    $url = $bbb->createMeeting($meetingParams);
-                    $bbb->redirectToBBB($url);
-                }
+                $url = $bbb->joinMeeting($meetingParams['meeting_name']) ?: $bbb->createMeeting($meetingParams);
             } else {
             } else {
-                if ($bbb->isConferenceManager()) {
-                    $url = $bbb->createMeeting($meetingParams);
-                    $bbb->redirectToBBB($url);
-                } else {
-                    $url = $bbb->getListingUrl();
-                    $bbb->redirectToBBB($url);
-                }
+                $url = $bbb->isConferenceManager() ? $bbb->createMeeting($meetingParams) : $bbb->getListingUrl();
             }
             }
+
+            $meetingInfo = $bbb->findMeetingByName($meetingParams['meeting_name']);
+
+            $bbb->saveParticipant($meetingInfo['id'], api_get_user_id());
+            $bbb->redirectToBBB($url);
         } else {
         } else {
             $url = $bbb->getListingUrl();
             $url = $bbb->getListingUrl();
             header('Location: ' . $url);
             header('Location: ' . $url);