Test Setup Failed
Push — master ( 4e700f...c7183e )
by Julito
63:12
created

bbb   D

Complexity

Total Complexity 193

Size/Duplication

Total Lines 1454
Duplicated Lines 11.83 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 172
loc 1454
rs 4.4102
c 0
b 0
f 0
wmc 193
lcom 1
cbo 8

42 Methods

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 80 16
A forceCIdReq() 0 6 1
A isGlobalConferenceEnabled() 0 4 1
A isGlobalConferencePerUserEnabled() 0 4 1
A isGlobalConference() 0 8 2
A hasGroupSupport() 0 4 1
B isConferenceManager() 0 23 6
C getMaxUsersLimit() 22 39 8
A setMaxUsersLimit() 0 6 2
F createMeeting() 0 99 21
A saveParticipant() 0 12 1
B meetingExists() 0 45 5
F joinMeeting() 11 101 17
B getMeetingInfo() 0 19 5
A getAllMeetingsInCourse() 0 20 1
F getMeetings() 18 179 29
A publishMeeting() 10 12 2
A unpublishMeeting() 10 12 2
B endMeeting() 0 30 3
A getUserMeetingPassword() 0 13 4
A getModMeetingPassword() 0 14 4
C getUsersOnlineInCurrentRoom() 24 70 7
B deleteRecording() 0 42 5
C copyRecordingToLinkTool() 0 34 8
A isServerRunning() 0 5 1
A getActiveSessionsCount() 0 11 1
A redirectToBBB() 0 12 2
A getUrlParams() 0 21 4
A getCurrentVideoConferenceName() 0 19 4
A getConferenceUrl() 0 4 1
A getListingUrl() 0 4 1
A endUrl() 8 8 2
A addToCalendarUrl() 0 6 2
A publishUrl() 7 7 2
A unPublishUrl() 8 8 2
A deleteRecordUrl() 8 8 2
A copyToRecordToLinkTool() 8 8 2
A findMeetingByName() 0 11 1
B findMeetingParticipants() 0 29 3
C getActionLinks() 38 78 7
A updateMeetingVideoUrl() 0 8 1
B checkDirectMeetingVideoUrl() 0 27 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like bbb often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use bbb, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class bbb
6
 * This script initiates a video conference session, calling the BigBlueButton
7
 * API
8
 * @package chamilo.plugin.bigbluebutton
9
 *
10
 * BigBlueButton-Chamilo connector class
11
 */
12
//namespace Chamilo\Plugin\BBB;
13
14
/**
15
 * Class bbb
16
 * @package Chamilo\Plugin\BBB
17
 */
18
class bbb
19
{
20
    public $url;
21
    public $salt;
22
    public $api;
23
    public $userCompleteName = '';
24
    public $protocol = 'http://';
25
    public $debug = false;
26
    public $logoutUrl = '';
27
    public $pluginEnabled = false;
28
    public $enableGlobalConference = false;
29
    public $enableGlobalConferencePerUser = false;
30
    public $isGlobalConference = false;
31
    public $groupSupport = false;
32
    public $userSupport = false;
33
    public $accessUrl = 1;
34
    public $userId = 0;
35
    public $plugin;
36
    private $courseCode;
37
    private $courseId;
38
    private $sessionId;
39
    private $groupId;
40
    private $maxUsersLimit;
41
42
    /**
43
     * Constructor (generates a connection to the API and the Chamilo settings
44
     * required for the connection to the video conference server)
45
     * @param string $host
46
     * @param string $salt
47
     * @param bool $isGlobalConference
48
     * @param int $isGlobalPerUser
49
     */
50
    public function __construct($host = '', $salt = '', $isGlobalConference = false, $isGlobalPerUser = 0)
51
    {
52
        $this->courseCode = api_get_course_id();
53
        $this->courseId = api_get_course_int_id();
54
        $this->sessionId = api_get_session_id();
55
        $this->groupId = api_get_group_id();
56
57
        // Initialize video server settings from global settings
58
        $this->plugin = BBBPlugin::create();
59
60
        $bbbPluginEnabled = $this->plugin->get('tool_enable');
61
62
        $bbb_host = !empty($host) ? $host : $this->plugin->get('host');
63
        $bbb_salt = !empty($salt) ? $salt : $this->plugin->get('salt');
64
65
        $this->logoutUrl = $this->getListingUrl();
66
        $this->table = Database::get_main_table('plugin_bbb_meeting');
67
        $this->enableGlobalConference = (bool) $this->plugin->get('enable_global_conference');
68
        $this->isGlobalConference = (bool) $isGlobalConference;
69
70
        $columns = Database::listTableColumns($this->table);
71
        $this->groupSupport = isset($columns['group_id']) ? true : false;
72
        $this->userSupport = isset($columns['user_id']) ? true : false;
73
        $this->accessUrl = api_get_current_access_url_id();
74
75
        if ($this->userSupport && !empty($isGlobalPerUser)) {
76
            $this->enableGlobalConferencePerUser = (bool) $this->plugin->get('enable_global_conference_per_user');
77
            $this->userId = $isGlobalPerUser;
78
        } else {
79
            $this->enableGlobalConferencePerUser = false;
80
        }
81
82
        if ($this->groupSupport) {
83
            // Plugin check
84
            $this->groupSupport = (bool) $this->plugin->get('enable_conference_in_course_groups');
85
            if ($this->groupSupport) {
86
87
                // Platform check
88
                $bbbSetting = api_get_plugin_setting('bbb', 'enable_conference_in_course_groups');
89
                $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
90
91
                if ($bbbSetting) {
92
                    // Course check
93
                    $courseInfo = api_get_course_info();
94
                    if ($courseInfo) {
95
                        $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups', $courseInfo['code']) === '1';
96
                    }
97
                }
98
            }
99
        }
100
        $this->maxUsersLimit = $this->plugin->get('max_users_limit');
101
102
        if ($bbbPluginEnabled === 'true') {
103
            $userInfo = api_get_user_info();
104
            if (empty($userInfo) && !empty($isGlobalPerUser)) {
105
                // If we are following a link to a global "per user" conference
106
                // then generate a random guest name to join the conference
107
                // because there is no part of the process where we give a name
108
                $this->userCompleteName = 'Guest'.rand(1000, 9999);
109
            } else {
110
                $this->userCompleteName = $userInfo['complete_name'];
111
            }
112
113
114
            $this->salt = $bbb_salt;
115
            $info = parse_url($bbb_host);
116
            $this->url = $bbb_host.'/bigbluebutton/';
117
            if (isset($info['scheme'])) {
118
                $this->protocol = $info['scheme'].'://';
119
                $this->url = str_replace($this->protocol, '', $this->url);
120
            }
121
122
            // Setting BBB api
123
            define('CONFIG_SECURITY_SALT', $this->salt);
124
            define('CONFIG_SERVER_BASE_URL', $this->url);
125
126
            $this->api = new BigBlueButtonBN();
127
            $this->pluginEnabled = true;
128
        }
129
    }
130
131
    /**
132
     * Force the course, session and/or group IDs
133
     * @param string $courseCode
134
     * @param int $sessionId
135
     * @param int $groupId
136
     */
137
    public function forceCIdReq($courseCode, $sessionId = 0, $groupId = 0)
138
    {
139
        $this->courseCode = $courseCode;
140
        $this->sessionId = intval($sessionId);
141
        $this->groupId = intval($groupId);
142
    }
143
144
    /**
145
     * @return bool
146
     */
147
    public function isGlobalConferenceEnabled()
148
    {
149
        return $this->enableGlobalConference;
150
    }
151
152
    /**
153
     * @return bool
154
     */
155
    public function isGlobalConferencePerUserEnabled()
156
    {
157
        return $this->enableGlobalConferencePerUser;
158
    }
159
160
    /**
161
     * @return bool
162
     */
163
    public function isGlobalConference()
164
    {
165
        if ($this->isGlobalConferenceEnabled() === false) {
166
            return false;
167
        }
168
169
        return (bool) $this->isGlobalConference;
170
    }
171
172
    /**
173
     * @return bool
174
     */
175
    public function hasGroupSupport()
176
    {
177
        return $this->groupSupport;
178
    }
179
180
    /**
181
     * Checks whether a user is teacher in the current course
182
     * @return bool True if the user can be considered a teacher in this course, false otherwise
183
     */
184
    public function isConferenceManager()
185
    {
186
        if (api_is_coach() || api_is_platform_admin()) {
187
            return true;
188
        }
189
190
        if ($this->isGlobalConferencePerUserEnabled()) {
191
            $currentUserId = api_get_user_id();
192
            if ($this->userId === $currentUserId) {
193
                return true;
194
            } else {
195
                return false;
196
            }
197
        }
198
199
        $courseInfo = api_get_course_info();
200
201
        if (!empty($courseInfo)) {
202
            return api_is_course_admin();
203
        }
204
205
        return false;
206
    }
207
    /**
208
     * Gets the global limit of users in a video-conference room.
209
     * This value can be overridden by course-specific values
210
     * @return  int Maximum number of users set globally
211
     */
212
    public function getMaxUsersLimit() {
213
        $limit = $this->maxUsersLimit;
214
        if ($limit <= 0) {
215
            $limit = 0;
216
        }
217
        $courseLimit = 0;
218
        $sessionLimit = 0;
219
        // Check the extra fields for this course and session
220
        // Session limit takes priority over course limit
221
        // Course limit takes priority over global limit
222 View Code Duplication
        if (!empty($this->courseId)) {
223
            $extraField = new ExtraField('course');
224
            $fieldId = $extraField->get_all(
225
                array('variable = ?' => 'plugin_bbb_course_users_limit')
226
            );
227
            $extraValue = new ExtraFieldValue('course');
228
            $value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId[0]['id']);
229
            if (!empty($value['value'])) {
230
                $courseLimit = $value['value'];
231
            }
232
        }
233 View Code Duplication
        if (!empty($this->sessionId)) {
234
            $extraField = new ExtraField('session');
235
            $fieldId = $extraField->get_all(
236
                array('variable = ?' => 'plugin_bbb_session_users_limit')
237
            );
238
            $extraValue = new ExtraFieldValue('session');
239
            $value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId[0]['id']);
240
            if (!empty($value['value'])) {
241
                $sessionLimit = $value['value'];
242
            }
243
        }
244
        if (!empty($sessionLimit)) {
245
            return $sessionLimit;
246
        } elseif (!empty($courseLimit)) {
247
            return $courseLimit;
248
        }
249
        return $limit;
250
    }
251
    /**
252
     * Sets the global limit of users in a video-conference room.
253
     * @param   int Maximum number of users (globally)
254
     */
255
    public function setMaxUsersLimit($max) {
256
        if ($max < 0) {
257
            $max = 0;
258
        }
259
        $this->maxUsersLimit = intval($max);
260
    }
261
262
    /**
263
     * See this file in you BBB to set up default values
264
     * @param   array $params Array of parameters that will be completed if not containing all expected variables
265
266
    /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
267
     *
268
    More record information:
269
    http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
270
271
    # Default maximum number of users a meeting can have.
272
    # Doesn't get enforced yet but is the default value when the create
273
    # API doesn't pass a value.
274
    defaultMaxUsers=20
275
276
    # Default duration of the meeting in minutes.
277
    # Current default is 0 (meeting doesn't end).
278
    defaultMeetingDuration=0
279
280
    # Remove the meeting from memory when the end API is called.
281
    # This allows 3rd-party apps to recycle the meeting right-away
282
    # instead of waiting for the meeting to expire (see below).
283
    removeMeetingWhenEnded=false
284
285
    # The number of minutes before the system removes the meeting from memory.
286
    defaultMeetingExpireDuration=1
287
288
    # The number of minutes the system waits when a meeting is created and when
289
    # a user joins. If after this period, a user hasn't joined, the meeting is
290
    # removed from memory.
291
    defaultMeetingCreateJoinDuration=5
292
     *
293
     * @return mixed
294
     */
295
    public function createMeeting($params)
296
    {
297
        $courseCode = api_get_course_id();
298
        $params['c_id'] = api_get_course_int_id();
299
        $params['session_id'] = api_get_session_id();
300
301
        if ($this->hasGroupSupport()) {
302
            $params['group_id'] = api_get_group_id();
303
        }
304
305
        if ($this->isGlobalConferencePerUserEnabled()) {
306
            $currentUserId = api_get_user_id();
307
            if ($this->userId === $currentUserId) {
308
                $params['user_id'] = $this->userId;
309
            }
310
        }
311
312
        $params['attendee_pw'] = isset($params['attendee_pw']) ? $params['attendee_pw'] : $this->getUserMeetingPassword();
313
        $attendeePassword = $params['attendee_pw'];
314
        $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
315
        $moderatorPassword = $params['moderator_pw'];
316
317
        $params['record'] = api_get_course_setting('big_blue_button_record_and_store', $courseCode) == 1 ? 1 : 0;
318
        $max = api_get_course_setting('big_blue_button_max_students_allowed', $courseCode);
319
        $max = isset($max) ? $max : -1;
320
321
        $params['status'] = 1;
322
        // Generate a pseudo-global-unique-id to avoid clash of conferences on
323
        // the same BBB server with several Chamilo portals
324
        $params['remote_id'] = uniqid(true, true);
325
        // Each simultaneous conference room needs to have a different
326
        // voice_bridge composed of a 5 digits number, so generating a random one
327
        $params['voice_bridge'] = rand(10000, 99999);
328
329
        if ($this->debug) {
330
            error_log("enter create_meeting ".print_r($params, 1));
331
        }
332
333
        $params['created_at'] = api_get_utc_datetime();
334
        $params['access_url'] = $this->accessUrl;
335
        $params['closed_at'] = '';
336
337
        $id = Database::insert($this->table, $params);
338
339
        if ($id) {
340
            if ($this->debug) {
341
                error_log("create_meeting: $id ");
342
            }
343
344
            $meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : $this->getCurrentVideoConferenceName();
345
            $welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
346
            $record = isset($params['record']) && $params['record'] ? 'true' : 'false';
347
            $duration = isset($params['duration']) ? intval($params['duration']) : 0;
348
            // This setting currently limits the maximum conference duration,
349
            // to avoid lingering sessions on the video-conference server #6261
350
            $duration = 300;
351
352
            $bbbParams = array(
353
                'meetingId' => $params['remote_id'], // REQUIRED
354
                'meetingName' => $meetingName, // REQUIRED
355
                'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee.
356
                'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator.
357
                'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize.
358
                'dialNumber' => '', // The main number to call into. Optional.
359
                'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required.
360
                'webVoice' => '', // Alphanumeric to join voice. Optional.
361
                'logoutUrl' =>  $this->logoutUrl,
362
                'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
363
                'record' => $record, // New. 'true' will tell BBB to record the meeting.
364
                'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
365
                //'meta_category' => '', 				// Use to pass additional info to BBB server. See API docs.
366
            );
367
368
            if ($this->debug) {
369
                error_log("create_meeting params: ".print_r($bbbParams, 1));
370
            }
371
372
            $status = false;
373
            $meeting = null;
374
375
            while ($status === false) {
376
                $result = $this->api->createMeetingWithXmlResponseArray(
377
                    $bbbParams
378
                );
379
                if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
380
                    if ($this->debug) {
381
                        error_log(
382
                            "create_meeting result: ".print_r($result, 1)
383
                        );
384
                    }
385
                    $meeting = $this->joinMeeting($meetingName, true);
386
387
                    return $meeting;
388
                }
389
            }
390
391
            return $this->logoutUrl;
392
        }
393
    }
394
395
    /**
396
     * Save a participant in a meeting room
397
     * @param int $meetingId
398
     * @param int $participantId
399
     * @return false|int The last inserted ID. Otherwise return false
400
     */
401
    public function saveParticipant($meetingId, $participantId)
402
    {
403
        return Database::insert(
404
            'plugin_bbb_room',
405
            [
406
                'meeting_id' => $meetingId,
407
                'participant_id' => $participantId,
408
                'in_at' => api_get_utc_datetime(),
409
                'out_at' => api_get_utc_datetime()
410
            ]
411
        );
412
    }
413
414
    /**
415
     * Tells whether the given meeting exists and is running
416
     * (using course code as name)
417
     * @param string $meetingName Meeting name (usually the course code)
418
     *
419
     * @return bool True if meeting exists, false otherwise
420
     * @assert ('') === false
421
     * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
422
     */
423
    public function meetingExists($meetingName)
424
    {
425
        if (empty($meetingName)) {
426
427
            return false;
428
        }
429
430
        $courseId = api_get_course_int_id();
431
        $sessionId = api_get_session_id();
432
        $conditions = array(
433
            'where' => array(
434
                'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 AND access_url = ?' =>
435
                    array($courseId, $sessionId, $meetingName, $this->accessUrl)
436
            )
437
        );
438
439
        if ($this->hasGroupSupport()) {
440
            $groupId = api_get_group_id();
441
            $conditions = array(
442
                'where' => array(
443
                    'c_id = ? AND session_id = ? AND meeting_name = ? AND group_id = ? AND status = 1 AND access_url = ?' =>
444
                        array($courseId, $sessionId, $meetingName, $groupId, $this->accessUrl)
445
                )
446
            );
447
        }
448
449
        $meetingData = Database::select(
450
            '*',
451
            $this->table,
452
            $conditions,
453
            'first'
454
        );
455
456
457
        if ($this->debug) {
458
            error_log("meeting_exists ".print_r($meetingData, 1));
459
        }
460
461
        if (empty($meetingData)) {
462
463
            return false;
464
        } else {
465
            return true;
466
        }
467
    }
468
469
    /**
470
     * Returns a meeting "join" URL
471
     * @param string The name of the meeting (usually the course code)
472
     * @return mixed The URL to join the meeting, or false on error
473
     * @todo implement moderator pass
474
     * @assert ('') === false
475
     * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
476
     */
477
    public function joinMeeting($meetingName, $loop = false)
478
    {
479
        if (empty($meetingName)) {
480
            return false;
481
        }
482
483
        $manager = $this->isConferenceManager();
484
        if ($manager) {
485
            $pass = $this->getModMeetingPassword();
486
        } else {
487
            $pass = $this->getUserMeetingPassword();
488
        }
489
490
        $meetingData = Database::select(
491
            '*',
492
            $this->table,
493
            array('where' => array('meeting_name = ? AND status = 1 AND access_url = ?' => array($meetingName, $this->accessUrl))),
494
            'first'
495
        );
496
497
        if (empty($meetingData) || !is_array($meetingData)) {
498
            if ($this->debug) {
499
                error_log("meeting does not exist: $meetingName");
500
            }
501
502
            return false;
503
        }
504
505
        $params = array(
506
            'meetingId' => $meetingData['remote_id'],
507
            //  -- REQUIRED - The unique id for the meeting
508
            'password' => $this->getModMeetingPassword()
509
            //  -- REQUIRED - The moderator password for the meeting
510
        );
511
512
        $status = false;
513
        $meetingInfoExists = false;
514
        while ($status === false) {
515
516
            $meetingIsRunningInfo = $this->getMeetingInfo($params);
517 View Code Duplication
            if ($meetingIsRunningInfo === false) {
518
                //checking with the remote_id didn't work, so just in case and
519
                // to provide backwards support, check with the id
520
                $params = array(
521
                    'meetingId' => $meetingData['id'],
522
                    //  -- REQUIRED - The unique id for the meeting
523
                    'password' => $this->getModMeetingPassword()
524
                    //  -- REQUIRED - The moderator password for the meeting
525
                );
526
                $meetingIsRunningInfo = $this->getMeetingInfo($params);
527
            }
528
529
            if ($this->debug) {
530
                error_log(print_r($meetingIsRunningInfo, 1));
531
            }
532
533
            if (strval($meetingIsRunningInfo['returncode']) == 'SUCCESS' &&
534
                isset($meetingIsRunningInfo['meetingName']) &&
535
                !empty($meetingIsRunningInfo['meetingName'])
536
                //strval($meetingIsRunningInfo['running']) == 'true'
537
            ) {
538
                $meetingInfoExists = true;
539
            }
540
541
            if ($this->debug) {
542
                error_log(
543
                    "meeting is running: ".intval($meetingInfoExists)
544
                );
545
            }
546
547
            if ($meetingInfoExists) {
548
                $status = true;
549
            }
550
551
            if ($loop) {
552
                continue;
553
            } else {
554
                break;
555
            }
556
        }
557
558
        if ($meetingInfoExists) {
559
            $joinParams = array(
560
                'meetingId' => $meetingData['remote_id'], //	-- REQUIRED - A unique id for the meeting
561
                'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
562
                'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
563
                //'createTime' => api_get_utc_datetime(),			//-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
564
                'userID' => api_get_user_id(), //-- OPTIONAL - string
565
                'webVoiceConf' => ''	//	-- OPTIONAL - string
566
            );
567
            $url = $this->api->getJoinMeetingURL($joinParams);
568
            $url = $this->protocol.$url;
569
        } else {
570
            $url = $this->logoutUrl;
571
        }
572
        if ($this->debug) {
573
            error_log("return url :".$url);
574
        }
575
576
        return $url;
577
    }
578
579
    /**
580
     * Get information about the given meeting
581
     * @param array ...?
582
     * @return mixed Array of information on success, false on error
583
     * @assert (array()) === false
584
     */
585
    public function getMeetingInfo($params)
586
    {
587
        try {
588
            $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
589
            if ($result == null) {
590
                if ($this->debug) {
591
                    error_log("Failed to get any response. Maybe we can't contact the BBB server.");
592
                }
593
            } else {
594
                return $result;
595
            }
596
        } catch (Exception $e) {
597
            if ($this->debug) {
598
                error_log('Caught exception: ', $e->getMessage(), "\n");
599
            }
600
        }
601
602
        return false;
603
    }
604
605
    /**
606
     * @param int $courseId
607
     * @param int $sessionId
608
     * @param int $status
609
     *
610
     * @return array
611
     */
612
    public function getAllMeetingsInCourse($courseId, $sessionId, $status)
613
    {
614
        $conditions = array(
615
            'where' => array(
616
                'status = ? AND c_id = ? AND session_id = ? ' => array(
617
                    $status,
618
                    $courseId,
619
                    $sessionId,
620
                ),
621
            ),
622
        );
623
624
        $meetingList = Database::select(
625
            '*',
626
            $this->table,
627
            $conditions
628
        );
629
630
        return $meetingList;
631
    }
632
633
    /**
634
     * Gets all the course meetings saved in the plugin_bbb_meeting table
635
     * @param int $courseId
636
     * @param int $sessionId
637
     * @param int $groupId
638
     * @param bool $isAdminReport Optional. Set to true then the report is for admins
639
     * @param array $dateRange Optional
640
     * @return array Array of current open meeting rooms
641
     */
642
    public function getMeetings(
643
        $courseId = 0,
644
        $sessionId = 0,
645
        $groupId = 0,
646
        $isAdminReport = false,
647
        $dateRange = []
648
    ) {
649
        $em = Database::getManager();
650
        $manager = $this->isConferenceManager();
651
652
        $conditions = [];
653
        if ($courseId || $sessionId || $groupId) {
654
            $conditions = array(
655
                'where' => array(
656
                    'c_id = ? AND session_id = ? ' => array($courseId, $sessionId),
657
                ),
658
            );
659
660 View Code Duplication
            if ($this->hasGroupSupport()) {
661
                $conditions = array(
662
                    'where' => array(
663
                        'c_id = ? AND session_id = ? AND group_id = ? ' => array($courseId, $sessionId, $groupId)
664
                    )
665
                );
666
            }
667
        }
668
669
        if (!empty($dateRange)) {
670
            $dateStart = date_create($dateRange['search_meeting_start']);
671
            $dateStart = date_format($dateStart, 'Y-m-d H:i:s');
672
            $dateEnd = date_create($dateRange['search_meeting_end']);
673
            $dateEnd = $dateEnd->add(new DateInterval('P1D'));
674
            $dateEnd = date_format($dateEnd, 'Y-m-d H:i:s');
675
676
            $conditions = array(
677
                'where' => array(
678
                    'created_at BETWEEN ? AND ? ' => array($dateStart, $dateEnd),
679
                ),
680
            );
681
        }
682
683
        $meetingList = Database::select(
684
            '*',
685
            $this->table,
686
            $conditions
687
        );
688
        $isGlobal = $this->isGlobalConference();
689
        $newMeetingList = array();
690
        foreach ($meetingList as $meetingDB) {
691
            $item = array();
692
            $courseId = $meetingDB['c_id'];
693
            $courseInfo = api_get_course_info_by_id($courseId);
694
            $courseCode = $courseInfo['code'];
695
696
            if ($manager) {
697
                $pass = $this->getUserMeetingPassword($courseCode);
698
            } else {
699
                $pass = $this->getModMeetingPassword($courseCode);
700
            }
701
702
            $meetingBBB = $this->getMeetingInfo(
703
                [
704
                    'meetingId' => $meetingDB['remote_id'],
705
                    'password' => $pass
706
                ]
707
            );
708
709 View Code Duplication
            if ($meetingBBB === false) {
710
                //checking with the remote_id didn't work, so just in case and
711
                // to provide backwards support, check with the id
712
                $params = array(
713
                    'meetingId' => $meetingDB['id'],
714
                    //  -- REQUIRED - The unique id for the meeting
715
                    'password' => $pass
716
                    //  -- REQUIRED - The moderator password for the meeting
717
                );
718
                $meetingBBB = $this->getMeetingInfo($params);
719
            }
720
721
            if ($meetingDB['visibility'] == 0 && $this->isConferenceManager() === false) {
722
                continue;
723
            }
724
725
            $meetingBBB['end_url'] = $this->endUrl($meetingDB);
726
727
            if (isset($meetingBBB['returncode']) && (string) $meetingBBB['returncode'] == 'FAILED') {
728
                if ($meetingDB['status'] == 1 && $this->isConferenceManager()) {
729
                    $this->endMeeting($meetingDB['id'], $courseCode);
730
                }
731
            } else {
732
                $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB);
733
            }
734
735
            $item['action_links'] = '';
736
737
            if ($meetingDB['record'] == 1) {
738
                // backwards compatibility (when there was no remote ID)
739
                $mId = $meetingDB['remote_id'];
740
                if (empty($mId)) {
741
                    $mId = $meetingDB['id'];
742
                }
743
                if (empty($mId)) {
744
                    // if the id is still empty (should *never* occur as 'id' is
745
                    // the table's primary key), skip this conference
746
                    continue;
747
                }
748
749
                $record = [];
750
                if (empty($meetingDB['video_url'])) {
751
                    $recordingParams = ['meetingId' => $mId];
752
                    $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
753
754
                    if (!empty($records)) {
755
                        if (!isset($records['messageKey']) || $records['messageKey'] != 'noRecordings') {
756
                            $record = end($records);
757
                            if (!is_array($record) || !isset($record['recordId'])) {
758
                                continue;
759
                            }
760
761
                            $this->updateMeetingVideoUrl($meetingDB['id'], $record['playbackFormatUrl']);
762
763
                            if (!$this->isConferenceManager()) {
764
                                $record = [];
765
                            }
766
                        }
767
                    }
768
                } else {
769
                    $record['playbackFormatUrl'] = $meetingDB['video_url'];
770
                }
771
772
                $recordLink = isset($record['playbackFormatUrl']) && !empty($record['playbackFormatUrl'])
773
                    ? Display::url(
774
                        $this->plugin->get_lang('ViewRecord'),
775
                        $record['playbackFormatUrl'],
776
                        ['target' => '_blank']
777
                    )
778
                    : get_lang('NoRecording');
779
780
                if ($isAdminReport) {
781
                    $this->forceCIdReq($courseInfo['code'], $meetingDB['session_id'], $meetingDB['group_id']);
782
                }
783
784
                $actionLinks = $this->getActionLinks($meetingDB, $record, $isGlobal, $isAdminReport);
785
                $item['show_links'] = $recordLink;
786
            } else {
787
                $actionLinks = $this->getActionLinks($meetingDB, [], $isGlobal, $isAdminReport);
788
789
                $item['show_links'] = get_lang('NoRecording');
790
            }
791
792
            $item['action_links'] = implode(PHP_EOL, $actionLinks);
793
794
            $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
795
            // created_at
796
            $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
797
798
            $item['publish_url'] = $this->publishUrl($meetingDB);
799
            $item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
800
801
            if ($meetingDB['status'] == 1) {
802
                $joinParams = array(
803
                    'meetingId' => $meetingDB['remote_id'], //-- REQUIRED - A unique id for the meeting
804
                    'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
805
                    'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
806
                    'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
807
                    'userID' => '', //	-- OPTIONAL - string
808
                    'webVoiceConf' => ''	//	-- OPTIONAL - string
809
                );
810
                $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
811
            }
812
            $item = array_merge($item, $meetingDB, $meetingBBB);
813
814
            $item['course'] = $em->find('ChamiloCoreBundle:Course', $item['c_id']);
815
            $item['session'] = $em->find('ChamiloCoreBundle:Session', $item['session_id']);
816
            $newMeetingList[] = $item;
817
        }
818
819
        return $newMeetingList;
820
    }
821
822
    /**
823
     * Function disabled
824
     */
825 View Code Duplication
    public function publishMeeting($id)
826
    {
827
        //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
828
        if (empty($id)) {
829
830
            return false;
831
        }
832
        $id = intval($id);
833
        Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
834
835
        return true;
836
    }
837
838
    /**
839
     * Function disabled
840
     */
841 View Code Duplication
    public function unpublishMeeting($id)
842
    {
843
        //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
844
        if (empty($id)) {
845
846
            return false;
847
        }
848
        $id = intval($id);
849
        Database::update($this->table, array('visibility' => 0), array('id = ?' => $id));
850
851
        return true;
852
    }
853
854
    /**
855
     * Closes a meeting (usually when the user click on the close button from
856
     * the conferences listing.
857
     * @param string The internal ID of the meeting (id field for this meeting)
858
     * @param string $courseCode
859
     *
860
     * @return void
861
     * @assert (0) === false
862
     */
863
    public function endMeeting($id, $courseCode = null)
864
    {
865
        if (empty($id)) {
866
            return false;
867
        }
868
869
        $meetingData = Database::select(
870
            '*',
871
            $this->table,
872
            array('where' => array('id = ?' => array($id))),
873
            'first'
874
        );
875
        $manager = $this->isConferenceManager();
876
        if ($manager) {
877
            $pass = $this->getUserMeetingPassword($courseCode);
878
        } else {
879
            $pass = $this->getModMeetingPassword($courseCode);
880
        }
881
882
        $endParams = array(
883
            'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end.
884
            'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
885
        );
886
        $this->api->endMeetingWithXmlResponseArray($endParams);
887
        Database::update(
888
            $this->table,
889
            array('status' => 0, 'closed_at' => api_get_utc_datetime()),
890
            array('id = ? ' => $id)
891
        );
892
    }
893
894
    /**
895
     * Gets the password for a specific meeting for the current user
896
     * @param string $courseCode
897
     * @return string A moderator password if user is teacher, or the course code otherwise
898
     *
899
     */
900
    public function getUserMeetingPassword($courseCode = null)
901
    {
902
        if ($this->isGlobalConferencePerUserEnabled()) {
903
            return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
904
        }
905
906
        if ($this->isGlobalConference()) {
907
            return 'url_'.api_get_current_access_url_id();
908
        }
909
        $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
910
911
        return $courseCode;
912
    }
913
914
    /**
915
     * Generated a moderator password for the meeting
916
     * @param string $courseCode
917
     *
918
     * @return string A password for the moderation of the videoconference
919
     */
920
    public function getModMeetingPassword($courseCode = null)
921
    {
922
        if ($this->isGlobalConferencePerUserEnabled()) {
923
            return 'url_'.$this->userId.'_'.api_get_current_access_url_id().'_mod';
924
        }
925
926
        if ($this->isGlobalConference()) {
927
            return 'url_'.api_get_current_access_url_id().'_mod';
928
        }
929
930
        $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
931
932
        return $courseCode.'mod';
933
    }
934
935
    /**
936
     * Get users online in the current course room
937
     * @return int The number of users currently connected to the videoconference
938
     * @assert () > -1
939
     */
940
    public function getUsersOnlineInCurrentRoom()
941
    {
942
        $courseId = api_get_course_int_id();
943
        $sessionId = api_get_session_id();
944
945
        $conditions = array(
946
            'where' => array(
947
                'c_id = ? AND session_id = ? AND status = 1 AND access_url = ?' => array(
948
                    $courseId,
949
                    $sessionId,
950
                    $this->accessUrl
951
                ),
952
            ),
953
        );
954
955 View Code Duplication
        if ($this->hasGroupSupport()) {
956
            $groupId = api_get_group_id();
957
            $conditions = array(
958
                'where' => array(
959
                    'c_id = ? AND session_id = ? AND group_id = ? AND status = 1 AND access_url = ?' => array(
960
                        $courseId,
961
                        $sessionId,
962
                        $groupId,
963
                        $this->accessUrl
964
                    ),
965
                ),
966
            );
967
        }
968
969
        if ($this->isGlobalConferencePerUserEnabled()) {
970
            $conditions = array(
971
                'where' => array(
972
                    'user_id = ? AND status = 1 AND access_url = ?' => array(
973
                        $this->userId,
974
                        $this->accessUrl
975
                    ),
976
                ),
977
            );
978
        }
979
980
        $meetingData = Database::select(
981
            '*',
982
            $this->table,
983
            $conditions,
984
            'first'
985
        );
986
987
        if (empty($meetingData)) {
988
            return 0;
989
        }
990
        $pass = $this->getModMeetingPassword();
991
        $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass));
992 View Code Duplication
        if ($info === false) {
993
            //checking with the remote_id didn't work, so just in case and
994
            // to provide backwards support, check with the id
995
            $params = array(
996
                'meetingId' => $meetingData['id'],
997
                //  -- REQUIRED - The unique id for the meeting
998
                'password' => $pass
999
                //  -- REQUIRED - The moderator password for the meeting
1000
            );
1001
            $info = $this->getMeetingInfo($params);
1002
        }
1003
1004
        if (!empty($info) && isset($info['participantCount'])) {
1005
            return $info['participantCount'];
1006
1007
        }
1008
        return 0;
1009
    }
1010
1011
    /**
1012
     * Deletes a previous recording of a meeting
1013
     * @param int $id ID of the recording
1014
     * @return array ?
1015
     * @assert () === false
1016
     * @todo Also delete links and agenda items created from this recording
1017
     */
1018
    public function deleteRecording($id)
1019
    {
1020
        if (empty($id)) {
1021
1022
            return false;
1023
        }
1024
1025
        $meetingData = Database::select(
1026
            '*',
1027
            $this->table,
1028
            array('where' => array('id = ?' => array($id))),
1029
            'first'
1030
        );
1031
1032
        $recordingParams = array(
1033
            /*
1034
             * NOTE: Set the recordId below to a valid id after you have
1035
             * created a recorded meeting, and received a real recordID
1036
             * back from your BBB server using the
1037
             * getRecordingsWithXmlResponseArray method.
1038
             */
1039
1040
            // REQUIRED - We have to know which recording:
1041
            'recordId' => $meetingData['remote_id'],
1042
        );
1043
1044
        $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
1045
1046
        if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
1047
            Database::delete(
1048
                'plugin_bbb_room',
1049
                array('meeting_id = ?' => array($id))
1050
            );
1051
1052
            Database::delete(
1053
                $this->table,
1054
                array('id = ?' => array($id))
1055
            );
1056
        }
1057
1058
        return $result;
1059
    }
1060
1061
    /**
1062
     * Creates a link in the links tool from the given videoconference recording
1063
     * @param int $id ID of the item in the plugin_bbb_meeting table
1064
     * @param string Hash identifying the recording, as provided by the API
1065
     * @return mixed ID of the newly created link, or false on error
1066
     * @assert (null, null) === false
1067
     * @assert (1, null) === false
1068
     * @assert (null, 'abcdefabcdefabcdefabcdef') === false
1069
     */
1070
    public function copyRecordingToLinkTool($id)
1071
    {
1072
        if (empty($id)) {
1073
            return false;
1074
        }
1075
        //$records =  BigBlueButtonBN::getRecordingsUrl($id);
1076
        $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
1077
1078
        $records = $this->api->getRecordingsWithXmlResponseArray(array('meetingId' => $meetingData['remote_id']));
1079
1080
        if (!empty($records)) {
1081
            if (isset($records['message']) && !empty($records['message'])) {
1082
                if ($records['messageKey'] == 'noRecordings') {
1083
                    $recordArray[] = $this->plugin->get_lang('NoRecording');
1084
                } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
1085
                    //$recordArray[] = $records['message'];
1086
                }
1087
                return false;
1088
            } else {
1089
                $record = $records[0];
1090
                if (is_array($record) && isset($record['recordId'])) {
1091
                    $url = $record['playbackFormatUrl'];
1092
                    $link = new Link();
1093
                    $params['url'] = $url;
1094
                    $params['title'] = $meetingData['meeting_name'];
1095
                    $id = $link->save($params);
1096
1097
                    return $id;
1098
                }
1099
            }
1100
        }
1101
1102
        return false;
1103
    }
1104
1105
    /**
1106
     * Checks if the video conference server is running.
1107
     * Function currently disabled (always returns 1)
1108
     * @return bool True if server is running, false otherwise
1109
     * @assert () === false
1110
     */
1111
    public function isServerRunning()
1112
    {
1113
        return true;
1114
        //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
1115
    }
1116
1117
    /**
1118
     * Get active session in the all platform
1119
     */
1120
    public function getActiveSessionsCount()
1121
    {
1122
        $meetingList = Database::select(
1123
            'count(id) as count',
1124
            $this->table,
1125
            array('where' => array('status = ? AND access_url = ?' => array(1, $this->accessUrl))),
1126
            'first'
1127
        );
1128
1129
        return $meetingList['count'];
1130
    }
1131
1132
    /**
1133
     * @param string $url
1134
     */
1135
    public function redirectToBBB($url)
1136
    {
1137
        if (file_exists(__DIR__.'/../config.vm.php')) {
1138
            // Using VM
1139
            echo Display::url($this->plugin->get_lang('ClickToContinue'), $url);
1140
            exit;
1141
        } else {
1142
            // Classic
1143
            header("Location: $url");
1144
            exit;
1145
        }
1146
    }
1147
1148
    /**
1149
     * @return string
1150
     */
1151
    public function getUrlParams()
1152
    {
1153
        if (empty($this->courseCode)) {
1154
1155
            if ($this->isGlobalConferencePerUserEnabled()) {
1156
                return 'global=1&user_id='.$this->userId;
1157
            }
1158
1159
            if ($this->isGlobalConference()) {
1160
                return 'global=1';
1161
            }
1162
1163
            return '';
1164
        }
1165
1166
        return http_build_query([
1167
            'cidReq' => $this->courseCode,
1168
            'id_session' => $this->sessionId,
1169
            'gidReq' => $this->groupId
1170
        ]);
1171
    }
1172
1173
    /**
1174
     * @return string
1175
     */
1176
    public function getCurrentVideoConferenceName()
1177
    {
1178
        if ($this->isGlobalConferencePerUserEnabled()) {
1179
1180
            return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
1181
        }
1182
1183
        if ($this->isGlobalConference()) {
1184
1185
            return 'url_'.api_get_current_access_url_id();
1186
        }
1187
1188
        if ($this->hasGroupSupport()) {
1189
1190
            return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
1191
        }
1192
1193
        return api_get_course_id().'-'.api_get_session_id();
1194
    }
1195
1196
    /**
1197
     * @return string
1198
     */
1199
    public function getConferenceUrl()
1200
    {
1201
        return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
1202
    }
1203
1204
    /**
1205
     * @return string
1206
     */
1207
    public function getListingUrl()
1208
    {
1209
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams();
1210
    }
1211
1212
    /**
1213
     * @param array $meeting
1214
     * @return string
1215
     */
1216 View Code Duplication
    public function endUrl($meeting)
1217
    {
1218
        if (!isset($meeting['id'])) {
1219
            return '';
1220
        }
1221
1222
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id'];
1223
    }
1224
1225
    /**
1226
     * @param array $meeting
1227
     * @param array $record
1228
     * @return string
1229
     */
1230
    public function addToCalendarUrl($meeting, $record = [])
1231
    {
1232
        $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
1233
1234
        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;
1235
    }
1236
1237
    /**
1238
     * @param array $meeting
1239
     * @return string
1240
     */
1241 View Code Duplication
    public function publishUrl($meeting)
1242
    {
1243
        if (!isset($meeting['id'])) {
1244
            return '';
1245
        }
1246
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=publish&id='.$meeting['id'];
1247
    }
1248
1249
    /**
1250
     * @param array $meeting
1251
     * @return string
1252
     */
1253 View Code Duplication
    public function unPublishUrl($meeting)
1254
    {
1255
        if (!isset($meeting['id'])) {
1256
            return null;
1257
        }
1258
1259
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=unpublish&id='.$meeting['id'];
1260
    }
1261
1262
    /**
1263
     * @param array $meeting
1264
     * @return string
1265
     */
1266 View Code Duplication
    public function deleteRecordUrl($meeting)
1267
    {
1268
        if (!isset($meeting['id'])) {
1269
            return '';
1270
        }
1271
1272
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=delete_record&id='.$meeting['id'];
1273
    }
1274
1275
    /**
1276
     * @param array $meeting
1277
     * @return string
1278
     */
1279 View Code Duplication
    public function copyToRecordToLinkTool($meeting)
1280
    {
1281
        if (!isset($meeting['id'])) {
1282
            return '';
1283
        }
1284
1285
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
1286
    }
1287
1288
    /**
1289
     * Get the meeting info from DB by its name
1290
     * @param string $name
1291
     * @return array
1292
     */
1293
    public function findMeetingByName($name)
1294
    {
1295
        $meetingData = Database::select(
1296
            '*',
1297
            'plugin_bbb_meeting',
1298
            array('where' => array('meeting_name = ? AND status = 1 ' => $name)),
1299
            'first'
1300
        );
1301
1302
        return $meetingData;
1303
    }
1304
1305
    /**
1306
     * @param int $meetingId
1307
     * @return array
1308
     */
1309
    public function findMeetingParticipants($meetingId)
1310
    {
1311
        $em = Database::getManager();
1312
        $meetingData = Database::select(
1313
            '*',
1314
            'plugin_bbb_room',
1315
            array('where' => array('meeting_id = ?' => intval($meetingId)))
1316
        );
1317
        $participantIds = [];
1318
        $return = [];
1319
1320
        foreach ($meetingData as $participantInfo) {
1321
            if (in_array($participantInfo['participant_id'], $participantIds)) {
1322
                continue;
1323
            }
1324
1325
            $participantIds[] = $participantInfo['participant_id'];
1326
1327
            $return[] = [
1328
                'id' => $participantInfo['id'],
1329
                'meeting_id' => $participantInfo['meeting_id'],
1330
                'participant' => $em->find('ChamiloUserBundle:User', $participantInfo['participant_id']),
1331
                'in_at' => $participantInfo['in_at'],
1332
                'out_at' => $participantInfo['out_at']
1333
            ];
1334
        }
1335
1336
        return $return;
1337
    }
1338
1339
    /**
1340
     * @param array $meetingInfo
1341
     * @param array $recordInfo
1342
     * @param bool $isGlobal
1343
     * @param bool $isAdminReport
1344
     * @return array
1345
     */
1346
    private function getActionLinks($meetingInfo, $recordInfo, $isGlobal = false, $isAdminReport = false)
1347
    {
1348
        $isVisible = $meetingInfo['visibility'] != 0;
1349
        $linkVisibility = $isVisible
1350
            ? Display::url(
1351
                Display::return_icon('visible.png', get_lang('MakeInvisible')),
1352
                $this->unPublishUrl($meetingInfo)
1353
            )
1354
            : Display::url(
1355
                Display::return_icon('invisible.png', get_lang('MakeVisible')),
1356
                $this->publishUrl($meetingInfo)
1357
            );
1358
1359
        $links = [];
1360
1361
        if (empty($recordInfo)) {
1362 View Code Duplication
            if (!$isAdminReport) {
1363
                $links[] = Display::url(
1364
                    Display::return_icon('delete.png', get_lang('Delete')),
1365
                    $this->deleteRecordUrl($meetingInfo)
1366
                );
1367
                $links[] = $linkVisibility;
1368
1369
                return $links;
1370
            } else {
1371
                $links[] = Display::url(
1372
                    Display::return_icon('course_home.png', get_lang('GoToCourse')),
1373
                    $this->getListingUrl()
1374
                );
1375
1376
                return $links;
1377
            }
1378
        }
1379
1380 View Code Duplication
        if (!$isGlobal) {
1381
            $links[] = Display::url(
1382
                Display::return_icon('link.gif', get_lang('UrlMeetingToShare')),
1383
                $this->copyToRecordToLinkTool($meetingInfo)
1384
            );
1385
            $links[] = Display::url(
1386
                Display::return_icon('agenda.png', get_lang('AddToCalendar')),
1387
                $this->addToCalendarUrl($meetingInfo, $recordInfo)
1388
            );
1389
        }
1390
1391
        if ($meetingInfo['has_video_m4v']) {
1392
            $links[] = Display::url(
1393
                Display::return_icon('save.png', get_lang('DownloadFile')),
1394
                $recordInfo['playbackFormatUrl'].'/capture.m4v',
1395
                ['target' => '_blank']
1396
            );
1397
        } else {
1398
            $links[] = Display::url(
1399
                Display::return_icon('save.png', get_lang('DownloadFile')),
1400
                '#',
1401
                [
1402
                    'id' => "btn-check-meeting-video-{$meetingInfo['id']}",
1403
                    'class' => 'check-meeting-video',
1404
                    'data-id' => $meetingInfo['id']
1405
                ]
1406
            );
1407
        }
1408
1409 View Code Duplication
        if (!$isAdminReport) {
1410
            $links[] = Display::url(
1411
                Display::return_icon('delete.png', get_lang('Delete')),
1412
                $this->deleteRecordUrl($meetingInfo)
1413
            );
1414
            $links[] = $linkVisibility;
1415
        } else {
1416
            $links[] = Display::url(
1417
                Display::return_icon('course_home.png', get_lang('GoToCourse')),
1418
                $this->getListingUrl()
1419
            );
1420
        }
1421
1422
        return $links;
1423
    }
1424
1425
    /**
1426
     * @param int $meetingId
1427
     * @param string $videoUrl
1428
     * @return bool|int
1429
     */
1430
    public function updateMeetingVideoUrl($meetingId, $videoUrl)
1431
    {
1432
        return Database::update(
1433
            'plugin_bbb_meeting',
1434
            ['video_url' => $videoUrl],
1435
            ['id = ?' => intval($meetingId)]
1436
        );
1437
    }
1438
1439
    /**
1440
     * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated
1441
     * @param int $meetingId
1442
     * @return bool
1443
     */
1444
    public function checkDirectMeetingVideoUrl($meetingId)
1445
    {
1446
        $meetingInfo = Database::select(
1447
            '*',
1448
            'plugin_bbb_meeting',
1449
            [
1450
                'where' => ['id = ?' => intval($meetingId)]
1451
            ],
1452
            'first'
1453
        );
1454
1455
        if (!isset($meetingInfo['video_url'])) {
1456
            return false;
1457
        }
1458
1459
        $hasCapture = SocialManager::verifyUrl($meetingInfo['video_url'].'/capture.m4v');
1460
1461
        if ($hasCapture) {
1462
            return Database::update(
1463
                'plugin_bbb_meeting',
1464
                ['has_video_m4v' => true],
1465
                ['id = ?' => intval($meetingId)]
1466
            );
1467
        }
1468
1469
        return $hasCapture;
1470
    }
1471
}
1472