Passed
Pull Request — master (#6161)
by
unknown
08:14
created

bbb::getMaxUsersLimit()   B

Complexity

Conditions 8
Paths 54

Size

Total Lines 41
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 26
c 0
b 0
f 0
nc 54
nop 0
dl 0
loc 41
rs 8.4444
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Component\Utils\ActionIcon;
6
use Chamilo\CoreBundle\Component\Utils\ObjectIcon;
7
use Chamilo\CoreBundle\Component\Utils\StateIcon;
8
use Chamilo\CoreBundle\Entity\ConferenceActivity;
9
use Chamilo\CoreBundle\Entity\ConferenceMeeting;
10
use Chamilo\CoreBundle\Entity\ConferenceRecording;
11
use Chamilo\CoreBundle\Repository\ConferenceActivityRepository;
12
use Chamilo\CoreBundle\Repository\ConferenceMeetingRepository;
13
use Chamilo\CoreBundle\Repository\ConferenceRecordingRepository;
14
use Chamilo\UserBundle\Entity\User;
15
16
/**
17
 * Class bbb
18
 * This script initiates a video conference session, calling the BigBlueButton
19
 * API BigBlueButton-Chamilo connector class
20
 */
21
class bbb
22
{
23
    public $url;
24
    public $salt;
25
    public $api;
26
    public $userCompleteName = '';
27
    public $protocol = 'http://';
28
    public $debug = false;
29
    public $logoutUrl = '';
30
    public $pluginEnabled = false;
31
    public $enableGlobalConference = false;
32
    public $enableGlobalConferencePerUser = false;
33
    public $isGlobalConference = false;
34
    public $groupSupport = false;
35
    public $userSupport = false;
36
    public $accessUrl = 1;
37
    public $userId = 0;
38
    public $plugin;
39
    private $courseCode;
40
    private $courseId;
41
    private $sessionId;
42
    private $groupId;
43
    private $maxUsersLimit;
44
45
    /**
46
     * Constructor (generates a connection to the API and the Chamilo settings
47
     * required for the connection to the video conference server)
48
     *
49
     * @param string $host
50
     * @param string $salt
51
     * @param bool   $isGlobalConference
52
     * @param int    $isGlobalPerUser
53
     */
54
    public function __construct(
55
        $host = '',
56
        $salt = '',
57
        $isGlobalConference = false,
58
        $isGlobalPerUser = 0
59
    ) {
60
        $this->courseCode = api_get_course_id();
61
        $this->courseId = api_get_course_int_id();
62
        $this->sessionId = api_get_session_id();
63
        $this->groupId = api_get_group_id();
64
65
        // Initialize video server settings from global settings
66
        $this->plugin = BBBPlugin::create();
67
        $bbbPluginEnabled = $this->plugin->get('tool_enable');
68
69
        $bbb_host = !empty($host) ? $host : $this->plugin->get('host');
70
        $bbb_salt = !empty($salt) ? $salt : $this->plugin->get('salt');
71
72
        $this->table = Database::get_main_table('conference_meeting');
73
        $this->enableGlobalConference = $this->plugin->get('enable_global_conference') === 'true';
74
        $this->isGlobalConference = (bool) $isGlobalConference;
75
76
        $columns = Database::listTableColumns($this->table);
77
        $this->groupSupport = isset($columns['group_id']) ? true : false;
78
        $this->userSupport = isset($columns['user_id']) ? true : false;
79
        $this->accessUrl = api_get_current_access_url_id();
80
81
        $this->enableGlobalConferencePerUser = false;
82
        if ($this->userSupport && !empty($isGlobalPerUser)) {
83
            $this->enableGlobalConferencePerUser = $this->plugin->get('enable_global_conference_per_user') === 'true';
84
            $this->userId = $isGlobalPerUser;
85
        }
86
87
        if ($this->groupSupport) {
88
            // Plugin check
89
            $this->groupSupport = $this->plugin->get('enable_conference_in_course_groups') === 'true' ? true : false;
90
            if ($this->groupSupport) {
91
                // Platform check
92
                $bbbSetting = api_get_plugin_setting('bbb', 'enable_conference_in_course_groups');
93
                $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
94
95
                if ($bbbSetting) {
96
                    // Course check
97
                    $courseInfo = api_get_course_info();
98
                    if ($courseInfo) {
99
                        $this->groupSupport = api_get_course_plugin_setting(
100
                                'bbb',
101
                                'bbb_enable_conference_in_groups',
102
                                $courseInfo
103
                            ) === '1';
104
                    }
105
                }
106
            }
107
        }
108
        $this->maxUsersLimit = $this->plugin->get('max_users_limit');
109
110
        if ($bbbPluginEnabled === 'true') {
111
            $userInfo = api_get_user_info();
112
            if (empty($userInfo) && !empty($isGlobalPerUser)) {
113
                // If we are following a link to a global "per user" conference
114
                // then generate a random guest name to join the conference
115
                // because there is no part of the process where we give a name
116
                //$this->userCompleteName = 'Guest'.rand(1000, 9999);
117
            } else {
118
                $this->userCompleteName = $userInfo['complete_name'];
119
            }
120
121
            if (api_is_anonymous()) {
122
                $this->userCompleteName = get_lang('Guest').'_'.rand(1000, 9999);
123
            }
124
125
            $this->salt = $bbb_salt;
126
            if (!empty($bbb_host)) {
127
                if (substr($bbb_host, -1, 1) !== '/') {
128
                    $bbb_host .= '/';
129
                }
130
                $this->url = $bbb_host;
131
                if (!preg_match('#/bigbluebutton/$#', $bbb_host)) {
132
                    $this->url = $bbb_host.'bigbluebutton/';
133
                }
134
            }
135
            $info = parse_url($bbb_host);
136
137
            if (isset($info['scheme'])) {
138
                $this->protocol = $info['scheme'].'://';
139
                $this->url = str_replace($this->protocol, '', $this->url);
140
                $urlWithProtocol = $bbb_host;
141
            } else {
142
                // We assume it's an http, if user wants to use https, the host *must* include the protocol.
143
                $this->protocol = 'http://';
144
                $urlWithProtocol = $this->protocol.$bbb_host;
145
            }
146
147
            // Setting BBB api
148
            define('CONFIG_SECURITY_SALT', $this->salt);
149
            define('CONFIG_SERVER_URL_WITH_PROTOCOL', $urlWithProtocol);
150
            define('CONFIG_SERVER_BASE_URL', $this->url);
151
            define('CONFIG_SERVER_PROTOCOL', $this->protocol);
152
153
            $this->api = new BigBlueButtonBN();
154
            $this->pluginEnabled = true;
155
            $this->logoutUrl = $this->getListingUrl();
156
        }
157
    }
158
159
    /**
160
     * @param int $courseId  Optional. Course ID.
161
     * @param int $sessionId Optional. Session ID.
162
     * @param int $groupId   Optional. Group ID.
163
     *
164
     * @return string
165
     */
166
    public function getListingUrl($courseId = 0, $sessionId = 0, $groupId = 0)
167
    {
168
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'
169
            .$this->getUrlParams($courseId, $sessionId, $groupId);
170
    }
171
172
    /**
173
     * @param int $courseId  Optional. Course ID.
174
     * @param int $sessionId Optional. Session ID.
175
     * @param int $groupId   Optional. Group ID.
176
     *
177
     * @return string
178
     */
179
    public function getUrlParams($courseId = 0, $sessionId = 0, $groupId = 0)
180
    {
181
        if (empty($this->courseId) && !$courseId) {
182
            if ($this->isGlobalConferencePerUserEnabled()) {
183
                return 'global=1&user_id='.$this->userId;
184
            }
185
186
            if ($this->isGlobalConference()) {
187
                return 'global=1';
188
            }
189
190
            return '';
191
        }
192
193
        $defaultCourseId = (int) $this->courseId;
194
        if (!empty($courseId)) {
195
            $defaultCourseId = (int) $courseId;
196
        }
197
198
        return http_build_query(
199
            [
200
                'cid' => $defaultCourseId,
201
                'sid' => (int) $sessionId ?: $this->sessionId,
202
                'gid' => (int) $groupId ?: $this->groupId,
203
            ]
204
        );
205
    }
206
207
    /**
208
     * @return bool
209
     */
210
    public function isGlobalConferencePerUserEnabled()
211
    {
212
        return $this->enableGlobalConferencePerUser;
213
    }
214
215
    /**
216
     * @return bool
217
     */
218
    public function isGlobalConference()
219
    {
220
        if ($this->isGlobalConferenceEnabled() === false) {
221
            return false;
222
        }
223
224
        return (bool) $this->isGlobalConference;
225
    }
226
227
    /**
228
     * @return bool
229
     */
230
    public function isGlobalConferenceEnabled()
231
    {
232
        return $this->enableGlobalConference;
233
    }
234
235
    /**
236
     * @param array $userInfo
237
     *
238
     * @return bool
239
     */
240
    public static function showGlobalConferenceLink($userInfo)
241
    {
242
        if (empty($userInfo)) {
243
            return false;
244
        }
245
        $setting = api_get_plugin_setting('bbb', 'enable_global_conference');
246
        $settingLink = api_get_plugin_setting('bbb', 'enable_global_conference_link');
247
        if ($setting === 'true' && $settingLink === 'true') {
248
            //$content = Display::url(get_lang('LaunchVideoConferenceRoom'), $url);
249
            $allowedRoles = api_get_plugin_setting(
250
                'bbb',
251
                'global_conference_allow_roles'
252
            );
253
254
            if (api_is_platform_admin()) {
255
                $userInfo['status'] = PLATFORM_ADMIN;
256
            }
257
258
            $showGlobalLink = true;
259
            if (!empty($allowedRoles)) {
260
                if (!in_array($userInfo['status'], $allowedRoles)) {
261
                    $showGlobalLink = false;
262
                }
263
            }
264
265
            return $showGlobalLink;
266
        }
267
    }
268
269
    /**
270
     * Gets the global limit of users in a video-conference room.
271
     * This value can be overridden by course-specific values
272
     * @return  int Maximum number of users set globally
273
     */
274
    public function getMaxUsersLimit()
275
    {
276
        $limit = $this->maxUsersLimit;
277
        if ($limit <= 0) {
278
            $limit = 0;
279
        }
280
        $courseLimit = 0;
281
        $sessionLimit = 0;
282
        // Check the extra fields for this course and session
283
        // Session limit takes priority over course limit
284
        // Course limit takes priority over global limit
285
        if (!empty($this->courseId)) {
286
            $extraField = new ExtraField('course');
287
            $fieldId = $extraField->get_all(
288
                array('variable = ?' => 'plugin_bbb_course_users_limit')
289
            );
290
            $extraValue = new ExtraFieldValue('course');
291
            $value = $extraValue->get_values_by_handler_and_field_id($this->courseId, $fieldId[0]['id']);
292
            if (!empty($value['value'])) {
293
                $courseLimit = (int) $value['value'];
294
            }
295
        }
296
        if (!empty($this->sessionId)) {
297
            $extraField = new ExtraField('session');
298
            $fieldId = $extraField->get_all(
299
                array('variable = ?' => 'plugin_bbb_session_users_limit')
300
            );
301
            $extraValue = new ExtraFieldValue('session');
302
            $value = $extraValue->get_values_by_handler_and_field_id($this->sessionId, $fieldId[0]['id']);
303
            if (!empty($value['value'])) {
304
                $sessionLimit = (int) $value['value'];
305
            }
306
        }
307
308
        if (!empty($sessionLimit)) {
309
            return $sessionLimit;
310
        } elseif (!empty($courseLimit)) {
311
            return $courseLimit;
312
        }
313
314
        return (int) $limit;
315
    }
316
317
    /**
318
     * Sets the global limit of users in a video-conference room.
319
     *
320
     * @param int Maximum number of users (globally)
321
     */
322
    public function setMaxUsersLimit($max)
323
    {
324
        if ($max < 0) {
325
            $max = 0;
326
        }
327
        $this->maxUsersLimit = (int) $max;
328
    }
329
330
    /**
331
     * See this file in you BBB to set up default values
332
     *
333
     * @param array $params Array of parameters that will be completed if not containing all expected variables
334
     *
335
     * /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
336
     *
337
     * More record information:
338
     * http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
339
     *
340
     * Default maximum number of users a meeting can have.
341
     * Doesn't get enforced yet but is the default value when the create
342
     * API doesn't pass a value.
343
     * defaultMaxUsers=20
344
     *
345
     * Default duration of the meeting in minutes.
346
     * Current default is 0 (meeting doesn't end).
347
     * defaultMeetingDuration=0
348
     *
349
     * Remove the meeting from memory when the end API is called.
350
     * This allows 3rd-party apps to recycle the meeting right-away
351
     * instead of waiting for the meeting to expire (see below).
352
     * removeMeetingWhenEnded=false
353
     *
354
     * The number of minutes before the system removes the meeting from memory.
355
     * defaultMeetingExpireDuration=1
356
     *
357
     * The number of minutes the system waits when a meeting is created and when
358
     * a user joins. If after this period, a user hasn't joined, the meeting is
359
     * removed from memory.
360
     * defaultMeetingCreateJoinDuration=5
361
     *
362
     * @return mixed
363
     */
364
    public function createMeeting($params)
365
    {
366
        $params['c_id'] = api_get_course_int_id();
367
        $params['session_id'] = api_get_session_id();
368
369
        if ($this->hasGroupSupport()) {
370
            $params['group_id'] = api_get_group_id();
371
        }
372
373
        if ($this->isGlobalConferencePerUserEnabled() && !empty($this->userId)) {
374
            $params['user_id'] = (int) $this->userId;
375
        }
376
377
        $params['attendee_pw'] = $params['attendee_pw'] ?? $this->getUserMeetingPassword();
378
        $attendeePassword = $params['attendee_pw'];
379
        $params['moderator_pw'] = $params['moderator_pw'] ?? $this->getModMeetingPassword();
380
        $moderatorPassword = $params['moderator_pw'];
381
382
        $params['record'] = api_get_course_plugin_setting('bbb', 'big_blue_button_record_and_store') == 1 ? 1 : 0;
383
        $max = api_get_course_plugin_setting('bbb', 'big_blue_button_max_students_allowed');
384
        $max = isset($max) ? $max : -1;
385
386
        $params['status'] = 1;
387
        // Generate a pseudo-global-unique-id to avoid clash of conferences on
388
        // the same BBB server with several Chamilo portals
389
        $params['remote_id'] = uniqid(true, true);
390
        // Each simultaneous conference room needs to have a different
391
        // voice_bridge composed of a 5 digits number, so generating a random one
392
        $params['voice_bridge'] = rand(10000, 99999);
393
        $params['created_at'] = api_get_utc_datetime();
394
        $params['access_url'] = $this->accessUrl;
395
396
        $em = Database::getManager();
397
        $meeting = new ConferenceMeeting();
398
399
        $meeting
400
            ->setCourse(api_get_course_entity($params['c_id']))
401
            ->setSession(api_get_session_entity($params['session_id']))
402
            ->setAccessUrl(api_get_url_entity($params['access_url']))
403
            ->setGroup($this->hasGroupSupport() ? api_get_group_entity($params['group_id']) : null)
404
            ->setUser($this->isGlobalConferencePerUserEnabled() ? api_get_user_entity($params['user_id']) : null)
405
            ->setRemoteId($params['remote_id'])
406
            ->setTitle($params['meeting_name'] ?? $this->getCurrentVideoConferenceName())
407
            ->setAttendeePw($attendeePassword)
408
            ->setModeratorPw($moderatorPassword)
409
            ->setRecord((bool)$params['record'])
410
            ->setStatus($params['status'])
411
            ->setVoiceBridge($params['voice_bridge'])
412
            ->setWelcomeMsg($params['welcome_msg'] ?? null)
413
            ->setVisibility(1)
414
            ->setHasVideoM4v(false)
415
            ->setServiceProvider('bbb');
416
417
        $em->persist($meeting);
418
        $em->flush();
419
420
        $id = $meeting->getId();
421
422
        Event::addEvent(
0 ignored issues
show
Bug introduced by
The method addEvent() does not exist on Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

422
        Event::/** @scrutinizer ignore-call */ 
423
               addEvent(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
423
            'bbb_create_meeting',
424
            'meeting_id',
425
            (int)$id,
426
            null,
427
            api_get_user_id(),
428
            api_get_course_int_id(),
429
            api_get_session_id()
430
        );
431
432
        $meetingName = $meeting->getTitle();
433
        $record = $meeting->isRecord() ? 'true' : 'false';
434
        $duration = 300;
435
        $meetingDuration = (int) $this->plugin->get('meeting_duration');
436
        if (!empty($meetingDuration)) {
437
            $duration = $meetingDuration;
438
        }
439
440
        $bbbParams = [
441
            'meetingId' => $meeting->getRemoteId(),
442
            'meetingName' => $meetingName,
443
            'attendeePw' => $attendeePassword,
444
            'moderatorPw' => $moderatorPassword,
445
            'welcomeMsg' => $meeting->getWelcomeMsg(),
446
            'dialNumber' => '',
447
            'voiceBridge' => $meeting->getVoiceBridge(),
448
            'webVoice' => '',
449
            'logoutUrl' => $this->logoutUrl . '&action=logout&remote_id=' . $meeting->getRemoteId(),
450
            'maxParticipants' => $max,
451
            'record' => $record,
452
            'duration' => $duration,
453
        ];
454
455
        $status = false;
456
        $finalMeetingUrl = null;
457
458
        while ($status === false) {
459
            $result = $this->api->createMeetingWithXmlResponseArray($bbbParams);
460
            if (isset($result) && strval($result['returncode']) === 'SUCCESS') {
461
                if ($this->plugin->get('allow_regenerate_recording') === 'true') {
462
                    $meeting->setInternalMeetingId($result['internalMeetingID']);
463
                    $em->flush();
464
                }
465
466
                $finalMeetingUrl = $this->joinMeeting($meetingName, true);
467
                return $finalMeetingUrl;
468
            }
469
        }
470
471
        return false;
472
    }
473
474
    /**
475
     * @return bool
476
     */
477
    public function hasGroupSupport()
478
    {
479
        return $this->groupSupport;
480
    }
481
482
    /**
483
     * Gets the password for a specific meeting for the current user
484
     *
485
     * @param string $courseCode
486
     *
487
     * @return string A moderator password if user is teacher, or the course code otherwise
488
     *
489
     */
490
    public function getUserMeetingPassword($courseCode = null)
491
    {
492
        if ($this->isGlobalConferencePerUserEnabled()) {
493
            return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
494
        }
495
496
        if ($this->isGlobalConference()) {
497
            return 'url_'.api_get_current_access_url_id();
498
        }
499
500
        return empty($courseCode) ? api_get_course_id() : $courseCode;
501
    }
502
503
    /**
504
     * Generated a moderator password for the meeting.
505
     *
506
     * @param string $courseCode
507
     *
508
     * @return string A password for the moderation of the videoconference
509
     */
510
    public function getModMeetingPassword($courseCode = null)
511
    {
512
        if ($this->isGlobalConferencePerUserEnabled()) {
513
            return 'url_'.$this->userId.'_'.api_get_current_access_url_id().'_mod';
514
        }
515
516
        if ($this->isGlobalConference()) {
517
            return 'url_'.api_get_current_access_url_id().'_mod';
518
        }
519
520
        $courseCode = empty($courseCode) ? api_get_course_id() : $courseCode;
521
522
        return $courseCode.'mod';
523
    }
524
525
    /**
526
     * @return string
527
     */
528
    public function getCurrentVideoConferenceName()
529
    {
530
        if ($this->isGlobalConferencePerUserEnabled()) {
531
            return 'url_'.$this->userId.'_'.api_get_current_access_url_id();
532
        }
533
534
        if ($this->isGlobalConference()) {
535
            return 'url_'.api_get_current_access_url_id();
536
        }
537
538
        if ($this->hasGroupSupport()) {
539
            return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
540
        }
541
542
        return api_get_course_id().'-'.api_get_session_id();
543
    }
544
545
    /**
546
     * Returns a meeting "join" URL
547
     *
548
     * @param string The name of the meeting (usually the course code)
549
     *
550
     * @return mixed The URL to join the meeting, or false on error
551
     * @todo implement moderator pass
552
     * @assert ('') === false
553
     * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
554
     */
555
    public function joinMeeting($meetingName)
556
    {
557
        if ($this->debug) {
558
            error_log("joinMeeting: $meetingName");
559
        }
560
561
        if (empty($meetingName)) {
562
            return false;
563
        }
564
565
        $manager = $this->isConferenceManager();
566
        $pass = $manager ? $this->getModMeetingPassword() : $this->getUserMeetingPassword();
567
568
        $meetingData = Database::getManager()
569
            ->getRepository(ConferenceMeeting::class)
570
            ->findOneBy([
571
                'title' => $meetingName,
572
                'status' => 1,
573
                'accessUrl' => api_get_url_entity($this->accessUrl),
574
            ]);
575
576
        if (empty($meetingData)) {
577
            if ($this->debug) {
578
                error_log("meeting does not exist: $meetingName");
579
            }
580
581
            return false;
582
        }
583
584
        $params = [
585
            'meetingId' => $meetingData->getRemoteId(),
586
            'password' => $this->getModMeetingPassword(),
587
        ];
588
589
        $meetingInfoExists = false;
590
        $meetingIsRunningInfo = $this->getMeetingInfo($params);
591
        if ($this->debug) {
592
            error_log('Searching meeting with params:');
593
            error_log(print_r($params, 1));
594
            error_log('Result:');
595
            error_log(print_r($meetingIsRunningInfo, 1));
596
        }
597
598
        if ($meetingIsRunningInfo === false) {
599
            $params['meetingId'] = $meetingData->getId();
600
            $meetingIsRunningInfo = $this->getMeetingInfo($params);
601
            if ($this->debug) {
602
                error_log('Searching meetingId with params:');
603
                error_log(print_r($params, 1));
604
                error_log('Result:');
605
                error_log(print_r($meetingIsRunningInfo, 1));
606
            }
607
        }
608
609
        if (
610
            strval($meetingIsRunningInfo['returncode']) === 'SUCCESS' &&
611
            isset($meetingIsRunningInfo['meetingName']) &&
612
            !empty($meetingIsRunningInfo['meetingName'])
613
        ) {
614
            $meetingInfoExists = true;
615
        }
616
617
        if ($this->debug) {
618
            error_log("meeting is running: " . intval($meetingInfoExists));
619
        }
620
621
        if ($meetingInfoExists) {
622
            $joinParams = [
623
                'meetingId' => $meetingData->getRemoteId(),
624
                'username' => $this->userCompleteName,
625
                'password' => $pass,
626
                'userID' => api_get_user_id(),
627
                'webVoiceConf' => '',
628
            ];
629
            $url = $this->api->getJoinMeetingURL($joinParams);
630
            return $this->protocol . $url;
631
        }
632
633
        return false;
634
    }
635
636
637
    /**
638
     * Checks whether a user is teacher in the current course
639
     * @return bool True if the user can be considered a teacher in this course, false otherwise
640
     */
641
    public function isConferenceManager()
642
    {
643
        if (api_is_coach() || api_is_platform_admin(false, true)) {
644
            return true;
645
        }
646
647
        if ($this->isGlobalConferencePerUserEnabled()) {
648
            $currentUserId = api_get_user_id();
649
            if ($this->userId === $currentUserId) {
650
                return true;
651
            } else {
652
                return false;
653
            }
654
        }
655
656
        $courseInfo = api_get_course_info();
657
        $groupId = api_get_group_id();
658
        if (!empty($groupId) && !empty($courseInfo)) {
659
            $groupEnabled = api_get_course_plugin_setting('bbb', 'bbb_enable_conference_in_groups') === '1';
660
            if ($groupEnabled) {
661
                $studentCanStartConference = api_get_course_plugin_setting(
662
                        'bbb',
663
                        'big_blue_button_students_start_conference_in_groups'
664
                    ) === '1';
665
666
                if ($studentCanStartConference) {
667
                    $isSubscribed = GroupManager::is_user_in_group(
0 ignored issues
show
Bug introduced by
The method is_user_in_group() does not exist on GroupManager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

667
                    /** @scrutinizer ignore-call */ 
668
                    $isSubscribed = GroupManager::is_user_in_group(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
668
                        api_get_user_id(),
669
                        GroupManager::get_group_properties($groupId)
670
                    );
671
                    if ($isSubscribed) {
672
                        return true;
673
                    }
674
                }
675
            }
676
        }
677
678
        if (!empty($courseInfo)) {
679
            return api_is_course_admin();
680
        }
681
682
        return false;
683
    }
684
685
    /**
686
     * Get information about the given meeting
687
     *
688
     * @param array ...?
689
     *
690
     * @return mixed Array of information on success, false on error
691
     * @assert (array()) === false
692
     */
693
    public function getMeetingInfo($params)
694
    {
695
        try {
696
            $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
697
            if ($result == null) {
698
                if ($this->debug) {
699
                    error_log("Failed to get any response. Maybe we can't contact the BBB server.");
700
                }
701
            }
702
703
            return $result;
704
        } catch (Exception $e) {
705
            if ($this->debug) {
706
                error_log('Caught exception: ', $e->getMessage(), "\n");
707
            }
708
        }
709
710
        return false;
711
    }
712
713
714
    /**
715
     * @param int $meetingId
716
     * @param int $userId
717
     *
718
     * @return array
719
     */
720
    public function getMeetingParticipantInfo($meetingId, $userId): array
721
    {
722
        $em = Database::getManager();
723
        /** @var ConferenceActivityRepository $repo */
724
        $repo = $em->getRepository(ConferenceActivity::class);
725
726
        $activity = $repo->createQueryBuilder('a')
727
            ->join('a.meeting', 'm')
728
            ->join('a.participant', 'u')
729
            ->where('m.id = :meetingId')
730
            ->andWhere('u.id = :userId')
731
            ->setParameter('meetingId', $meetingId)
732
            ->setParameter('userId', $userId)
733
            ->setMaxResults(1)
734
            ->getQuery()
735
            ->getOneOrNullResult();
736
737
        if (!$activity) {
738
            return [];
739
        }
740
741
        return [
742
            'id' => $activity->getId(),
743
            'meeting_id' => $activity->getMeeting()?->getId(),
744
            'participant_id' => $activity->getParticipant()?->getId(),
745
            'in_at' => $activity->getInAt()?->format('Y-m-d H:i:s'),
746
            'out_at' => $activity->getOutAt()?->format('Y-m-d H:i:s'),
747
            'close' => $activity->isClose(),
748
            'type' => $activity->getType(),
749
            'event' => $activity->getEvent(),
750
            'activity_data' => $activity->getActivityData(),
751
            'signature_file' => $activity->getSignatureFile(),
752
            'signed_at' => $activity->getSignedAt()?->format('Y-m-d H:i:s'),
753
        ];
754
    }
755
756
    /**
757
     * Save a participant in a meeting room
758
     *
759
     * @param int $meetingId
760
     * @param int $participantId
761
     *
762
     * @return false|int The last inserted ID. Otherwise return false
763
     */
764
    public function saveParticipant(int $meetingId, int $participantId): false|int
765
    {
766
        $em = Database::getManager();
767
768
        /** @var ConferenceActivityRepository $repo */
769
        $repo = $em->getRepository(ConferenceActivity::class);
770
771
        $meeting = $em->getRepository(ConferenceMeeting::class)->find($meetingId);
772
        $user = $em->getRepository(User::class)->find($participantId);
773
774
        if (!$meeting || !$user) {
775
            return false;
776
        }
777
778
        $existing = $repo->createQueryBuilder('a')
779
            ->where('a.meeting = :meeting')
780
            ->andWhere('a.participant = :participant')
781
            ->andWhere('a.close = :open')
782
            ->setParameter('meeting', $meeting)
783
            ->setParameter('participant', $user)
784
            ->setParameter('open', \BBBPlugin::ROOM_OPEN)
785
            ->getQuery()
786
            ->getResult();
787
788
        foreach ($existing as $activity) {
789
            if ($activity->getInAt() != $activity->getOutAt()) {
790
                $activity->setClose(\BBBPlugin::ROOM_CLOSE);
791
            } else {
792
                $activity->setOutAt(new \DateTime());
793
                $activity->setClose(\BBBPlugin::ROOM_CLOSE);
794
            }
795
            $em->persist($activity);
796
        }
797
798
        $newActivity = new ConferenceActivity();
799
        $newActivity->setMeeting($meeting);
800
        $newActivity->setParticipant($user);
801
        $newActivity->setInAt(new \DateTime());
802
        $newActivity->setOutAt(new \DateTime());
803
        $newActivity->setClose(\BBBPlugin::ROOM_OPEN);
804
805
        $em->persist($newActivity);
806
        $em->flush();
807
808
        return $newActivity->getId();
809
    }
810
811
    /**
812
     * Tells whether the given meeting exists and is running
813
     * (using course code as name)
814
     *
815
     * @param string $meetingName Meeting name (usually the course code)
816
     *
817
     * @return bool True if meeting exists, false otherwise
818
     * @assert ('') === false
819
     * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
820
     */
821
    public function meetingExists($meetingName)
822
    {
823
        $meetingData = $this->getMeetingByName($meetingName);
824
825
        return !empty($meetingData);
826
    }
827
828
    /**
829
     * @param string $meetingName
830
     *
831
     * @return array
832
     */
833
    public function getMeetingByName($meetingName)
834
    {
835
        if (empty($meetingName)) {
836
            return [];
837
        }
838
839
        $courseEntity = api_get_course_entity();
840
        $sessionEntity = api_get_session_entity();
841
        $accessUrlEntity = api_get_url_entity($this->accessUrl);
842
843
        $criteria = [
844
            'course' => $courseEntity,
845
            'session' => $sessionEntity,
846
            'title' => $meetingName,
847
            'status' => 1,
848
            'accessUrl' => $accessUrlEntity,
849
        ];
850
851
        if ($this->hasGroupSupport()) {
852
            $groupEntity = api_get_group_entity(api_get_group_id());
853
            $criteria['group'] = $groupEntity;
854
        }
855
856
        $meeting = Database::getManager()
857
            ->getRepository(ConferenceMeeting::class)
858
            ->findOneBy($criteria);
859
860
        if ($this->debug) {
861
            error_log('meeting_exists '.print_r($meeting ? ['id' => $meeting->getId()] : [], 1));
0 ignored issues
show
Bug introduced by
Are you sure print_r($meeting ? array...>getId()) : array(), 1) of type string|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

861
            error_log('meeting_exists './** @scrutinizer ignore-type */ print_r($meeting ? ['id' => $meeting->getId()] : [], 1));
Loading history...
862
        }
863
864
        if (!$meeting) {
865
            return [];
866
        }
867
868
        return [
869
            'id' => $meeting->getId(),
870
            'c_id' => $meeting->getCourse()?->getId(),
871
            'session_id' => $meeting->getSession()?->getId(),
872
            'meeting_name' => $meeting->getTitle(),
873
            'status' => $meeting->getStatus(),
874
            'access_url' => $meeting->getAccessUrl()?->getId(),
875
            'group_id' => $meeting->getGroup()?->getIid(),
876
            'remote_id' => $meeting->getRemoteId(),
877
            'moderator_pw' => $meeting->getModeratorPw(),
878
            'attendee_pw' => $meeting->getAttendeePw(),
879
            'created_at' => $meeting->getCreatedAt()->format('Y-m-d H:i:s'),
880
            'closed_at' => $meeting->getClosedAt()?->format('Y-m-d H:i:s'),
881
            'visibility' => $meeting->getVisibility(),
882
            'video_url' => $meeting->getVideoUrl(),
883
            'has_video_m4v' => $meeting->isHasVideoM4v(),
884
            'record' => $meeting->isRecord(),
885
            'internal_meeting_id' => $meeting->getInternalMeetingId(),
886
        ];
887
    }
888
889
    /**
890
     * Gets a list from the database of all meetings attached to a course with the given status
891
     * @param int $courseId
892
     * @param int $sessionId
893
     * @param int $status 0 for closed meetings, 1 for open meetings
894
     *
895
     * @return array
896
     */
897
    public function getAllMeetingsInCourse($courseId, $sessionId, $status)
898
    {
899
        $em = Database::getManager();
900
        $courseEntity = api_get_course_entity($courseId);
901
        $sessionEntity = api_get_session_entity($sessionId);
902
903
        $meetings = $em->getRepository(ConferenceMeeting::class)->findBy([
904
            'course' => $courseEntity,
905
            'session' => $sessionEntity,
906
            'status' => $status,
907
        ]);
908
909
        $results = [];
910
        foreach ($meetings as $meeting) {
911
            $results[] = [
912
                'id' => $meeting->getId(),
913
                'c_id' => $meeting->getCourse()?->getId(),
914
                'session_id' => $meeting->getSession()?->getId(),
915
                'meeting_name' => $meeting->getTitle(),
916
                'status' => $meeting->getStatus(),
917
                'access_url' => $meeting->getAccessUrl()?->getId(),
918
                'group_id' => $meeting->getGroup()?->getIid(),
919
                'remote_id' => $meeting->getRemoteId(),
920
                'moderator_pw' => $meeting->getModeratorPw(),
921
                'attendee_pw' => $meeting->getAttendeePw(),
922
                'created_at' => $meeting->getCreatedAt()->format('Y-m-d H:i:s'),
923
                'closed_at' => $meeting->getClosedAt()?->format('Y-m-d H:i:s'),
924
                'visibility' => $meeting->getVisibility(),
925
                'video_url' => $meeting->getVideoUrl(),
926
                'has_video_m4v' => $meeting->isHasVideoM4v(),
927
                'record' => $meeting->isRecord(),
928
                'internal_meeting_id' => $meeting->getInternalMeetingId(),
929
            ];
930
        }
931
932
        return $results;
933
    }
934
935
    /**
936
     * Gets all the course meetings saved in the plugin_bbb_meeting table and
937
     * generate actionable links (join/close/delete/etc)
938
     *
939
     * @param int   $courseId
940
     * @param int   $sessionId
941
     * @param int   $groupId
942
     * @param bool  $isAdminReport Optional. Set to true then the report is for admins
943
     * @param array $dateRange     Optional
944
     *
945
     * @return array Array of current open meeting rooms
946
     * @throws Exception
947
     */
948
    public function getMeetings(
949
        $courseId = 0,
950
        $sessionId = 0,
951
        $groupId = 0,
952
        $isAdminReport = false,
953
        $dateRange = []
954
    ) {
955
        $em = Database::getManager();
956
        $repo = $em->getRepository(ConferenceMeeting::class);
957
        $manager = $this->isConferenceManager();
958
        $isGlobal = $this->isGlobalConference();
959
        $meetings = [];
960
961
        if (!empty($dateRange)) {
962
            $dateStart = (new \DateTime($dateRange['search_meeting_start']))->setTime(0, 0, 0);
963
            $dateEnd = (new \DateTime($dateRange['search_meeting_end']))->setTime(23, 59, 59);
964
            $meetings = $repo->findByDateRange($dateStart, $dateEnd);
965
        } elseif ($this->isGlobalConference()) {
966
            $meetings = $repo->findBy([
967
                'course' => null,
968
                'user' => api_get_user_entity($this->userId),
969
                'status' => 1,
970
                'accessUrl' => api_get_url_entity($this->accessUrl),
971
            ]);
972
        } elseif ($this->isGlobalConferencePerUserEnabled()) {
973
            $meetings = $repo->findBy([
974
                'course' => api_get_course_entity($courseId),
975
                'session' => api_get_session_entity($sessionId),
976
                'user' => api_get_user_entity($this->userId),
977
                'status' => 1,
978
                'accessUrl' => api_get_url_entity($this->accessUrl),
979
            ]);
980
        } else {
981
            $criteria = [
982
                'course' => api_get_course_entity($courseId),
983
                'session' => api_get_session_entity($sessionId),
984
                'status' => 1,
985
                'accessUrl' => api_get_url_entity($this->accessUrl),
986
            ];
987
            if ($this->hasGroupSupport() && $groupId) {
988
                $criteria['group'] = api_get_group_entity($groupId);
989
            }
990
            $meetings = $repo->findBy($criteria, ['createdAt' => 'ASC']);
991
        }
992
993
        $result = [];
994
        foreach ($meetings as $meeting) {
995
            $meetingArray = $this->convertMeetingToArray($meeting);
996
            $recordLink = $this->plugin->get_lang('NoRecording');
997
            $meetingBBB = $this->getMeetingInfo([
998
                'meetingId' => $meeting->getRemoteId(),
999
                'password' => $manager ? $meeting->getModeratorPw() : $meeting->getAttendeePw(),
1000
            ]);
1001
1002
            if (!$meetingBBB && $meeting->getId()) {
1003
                $meetingBBB = $this->getMeetingInfo([
1004
                    'meetingId' => $meeting->getId(),
1005
                    'password' => $manager ? $meeting->getModeratorPw() : $meeting->getAttendeePw(),
1006
                ]);
1007
            }
1008
1009
            if (!$meeting->isVisible() && !$manager) {
1010
                continue;
1011
            }
1012
1013
            $meetingBBB['end_url'] = $this->endUrl(['id' => $meeting->getId()]);
1014
            if (isset($meetingBBB['returncode']) && (string) $meetingBBB['returncode'] === 'FAILED') {
1015
                if ($meeting->getStatus() === 1 && $manager) {
1016
                    $this->endMeeting($meeting->getId(), $meeting->getCourse()?->getCode());
1017
                }
1018
            } else {
1019
                $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingArray);
1020
            }
1021
1022
            if ($meeting->isRecord()) {
1023
                $recordings = $this->api->getRecordingsWithXmlResponseArray(['meetingId' => $meeting->getRemoteId()]);
1024
                if (!empty($recordings) && (!isset($recordings['messageKey']) || $recordings['messageKey'] !== 'noRecordings')) {
1025
                    $record = end($recordings);
1026
                    if (isset($record['playbackFormatUrl'])) {
1027
                        $recordLink = Display::url(
1028
                            $this->plugin->get_lang('ViewRecord'),
1029
                            $record['playbackFormatUrl'],
1030
                            ['target' => '_blank', 'class' => 'btn btn--plain']
1031
                        );
1032
                        $this->updateMeetingVideoUrl($meeting->getId(), $record['playbackFormatUrl']);
1033
                    }
1034
                }
1035
            }
1036
1037
            $actionLinks = $this->getActionLinks($meetingArray, $record ?? [], $isGlobal, $isAdminReport);
1038
1039
            $item = array_merge($meetingArray, [
1040
                'go_url' => '',
1041
                'show_links' => $recordLink,
1042
                'action_links' => implode(PHP_EOL, $actionLinks),
1043
                'publish_url' => $this->publishUrl(['id' => $meeting->getId()]),
1044
                'unpublish_url' => $this->unPublishUrl(['id' => $meeting->getId()]),
1045
            ]);
1046
1047
            if ($meeting->getStatus() === 1) {
1048
                $joinParams = [
1049
                    'meetingId' => $meeting->getRemoteId(),
1050
                    'username' => $this->userCompleteName,
1051
                    'password' => $manager ? $meeting->getModeratorPw() : $meeting->getAttendeePw(),
1052
                    'createTime' => '',
1053
                    'userID' => '',
1054
                    'webVoiceConf' => '',
1055
                ];
1056
                $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
1057
            }
1058
1059
            $result[] = array_merge($item, $meetingBBB);
1060
        }
1061
1062
        return $result;
1063
    }
1064
1065
    private function convertMeetingToArray(ConferenceMeeting $meeting): array
1066
    {
1067
        return [
1068
            'id' => $meeting->getId(),
1069
            'remote_id' => $meeting->getRemoteId(),
1070
            'internal_meeting_id' => $meeting->getInternalMeetingId(),
1071
            'meeting_name' => $meeting->getTitle(),
1072
            'status' => $meeting->getStatus(),
1073
            'visibility' => $meeting->getVisibility(),
1074
            'created_at' => $meeting->getCreatedAt() instanceof \DateTime ? $meeting->getCreatedAt()->format('Y-m-d H:i:s') : '',
0 ignored issues
show
introduced by
$meeting->getCreatedAt() is always a sub-type of DateTime.
Loading history...
1075
            'closed_at' => $meeting->getClosedAt() instanceof \DateTime ? $meeting->getClosedAt()->format('Y-m-d H:i:s') : '',
1076
            'record' => $meeting->isRecord() ? 1 : 0,
1077
            'c_id' => $meeting->getCourse()?->getId() ?? 0,
1078
            'session_id' => $meeting->getSession()?->getId() ?? 0,
1079
            'group_id' => $meeting->getGroup()?->getIid() ?? 0,
1080
            'course' => $meeting->getCourse(),
1081
            'session' => $meeting->getSession(),
1082
            'title' => $meeting->getTitle(),
1083
        ];
1084
    }
1085
1086
    public function getMeetingsLight(
1087
        $courseId = 0,
1088
        $sessionId = 0,
1089
        $groupId = 0,
1090
        $dateRange = []
1091
    ): array {
1092
        $em = Database::getManager();
1093
        $repo = $em->getRepository(ConferenceMeeting::class);
1094
        $meetings = [];
1095
1096
        if (!empty($dateRange)) {
1097
            $dateStart = (new \DateTime($dateRange['search_meeting_start']))->setTime(0, 0, 0);
1098
            $dateEnd = (new \DateTime($dateRange['search_meeting_end']))->setTime(23, 59, 59);
1099
            $meetings = $repo->findByDateRange($dateStart, $dateEnd);
1100
        } else {
1101
            $criteria = [
1102
                'course' => api_get_course_entity($courseId),
1103
                'session' => api_get_session_entity($sessionId),
1104
                'accessUrl' => api_get_url_entity($this->accessUrl),
1105
            ];
1106
            if ($this->hasGroupSupport() && $groupId) {
1107
                $criteria['group'] = api_get_group_entity($groupId);
1108
            }
1109
            $meetings = $repo->findBy($criteria, ['createdAt' => 'DESC']);
1110
        }
1111
1112
        $result = [];
1113
        foreach ($meetings as $meeting) {
1114
            $meetingArray = $this->convertMeetingToArray($meeting);
1115
1116
            $item = array_merge($meetingArray, [
1117
                'go_url' => '',
1118
                'show_links' => $this->plugin->get_lang('NoRecording'),
1119
                'action_links' => '',
1120
                'publish_url' => $this->publishUrl(['id' => $meeting->getId()]),
1121
                'unpublish_url' => $this->unPublishUrl(['id' => $meeting->getId()]),
1122
            ]);
1123
1124
            $result[] = $item;
1125
        }
1126
1127
        return $result;
1128
    }
1129
1130
    /**
1131
     * @param array $meeting
1132
     *
1133
     * @return string
1134
     */
1135
    public function endUrl($meeting)
1136
    {
1137
        if (!isset($meeting['id'])) {
1138
            return '';
1139
        }
1140
1141
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id'];
1142
    }
1143
1144
    /**
1145
     * Closes a meeting (usually when the user click on the close button from
1146
     * the conferences listing.
1147
     *
1148
     * @param string The internal ID of the meeting (id field for this meeting)
1149
     * @param string $courseCode
1150
     *
1151
     * @return void
1152
     * @assert (0) === false
1153
     */
1154
    public function endMeeting($id, $courseCode = null)
1155
    {
1156
        if (empty($id)) {
1157
            return false;
1158
        }
1159
1160
        $em = Database::getManager();
1161
1162
        /** @var ConferenceMeetingRepository $repo */
1163
        $repo = $em->getRepository(ConferenceMeeting::class);
1164
1165
        $meetingData = $repo->findOneAsArrayById((int) $id);
1166
        if (!$meetingData) {
1167
            return false;
1168
        }
1169
1170
        $manager = $this->isConferenceManager();
1171
        $pass = $manager ? $meetingData['moderatorPw'] : $meetingData['attendeePw'];
1172
1173
        Event::addEvent(
1174
            'bbb_end_meeting',
1175
            'meeting_id',
1176
            (int) $id,
1177
            null,
1178
            api_get_user_id(),
1179
            api_get_course_int_id(),
1180
            api_get_session_id()
1181
        );
1182
1183
        $endParams = [
1184
            'meetingId' => $meetingData['remoteId'],
1185
            'password' => $pass,
1186
        ];
1187
        $this->api->endMeetingWithXmlResponseArray($endParams);
1188
1189
        $repo->closeMeeting((int) $id, new \DateTime());
1190
1191
        /** @var ConferenceActivityRepository $activityRepo */
1192
        $activityRepo = $em->getRepository(ConferenceActivity::class);
1193
1194
        $activities = $activityRepo->findOpenWithSameInAndOutTime((int) $id);
1195
1196
        foreach ($activities as $activity) {
1197
            $activity->setOutAt(new \DateTime());
1198
            $activity->setClose(BBBPlugin::ROOM_CLOSE);
1199
            $em->persist($activity);
1200
        }
1201
1202
        $activityRepo->closeAllByMeetingId((int) $id);
1203
1204
        $em->flush();
1205
1206
        return true;
1207
    }
1208
1209
    /**
1210
     * @param array $meeting
1211
     * @param array $record
1212
     *
1213
     * @return string
1214
     */
1215
    public function addToCalendarUrl($meeting, $record = []): string
1216
    {
1217
        $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
1218
1219
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams(
1220
            ).'&action=add_to_calendar&id='.$meeting['id'].'&start='.api_strtotime($meeting['created_at']).'&url='.$url;
1221
    }
1222
1223
    /**
1224
     * @param int    $meetingId
1225
     * @param string $videoUrl
1226
     *
1227
     * @return bool|int
1228
     */
1229
    public function updateMeetingVideoUrl(int $meetingId, string $videoUrl): void
1230
    {
1231
        $em = Database::getManager();
1232
        /** @var ConferenceMeetingRepository $repo */
1233
        $repo = $em->getRepository(ConferenceMeeting::class);
1234
        $repo->updateVideoUrl($meetingId, $videoUrl);
1235
    }
1236
1237
    /**
1238
     * Force the course, session and/or group IDs
1239
     *
1240
     * @param string $courseCode
1241
     * @param int    $sessionId
1242
     * @param int    $groupId
1243
     */
1244
    public function forceCIdReq($courseCode, $sessionId = 0, $groupId = 0)
1245
    {
1246
        $this->courseCode = $courseCode;
1247
        $this->sessionId = (int) $sessionId;
1248
        $this->groupId = (int) $groupId;
1249
    }
1250
1251
    /**
1252
     * @param array $meetingInfo
1253
     * @param array $recordInfo
1254
     * @param bool  $isGlobal
1255
     * @param bool  $isAdminReport
1256
     *
1257
     * @return array
1258
     */
1259
    private function getActionLinks(
1260
        $meetingInfo,
1261
        $recordInfo,
1262
        $isGlobal = false,
1263
        $isAdminReport = false
1264
    ) {
1265
        $isVisible = $meetingInfo['visibility'] != 0;
1266
        $linkVisibility = $isVisible
1267
            ? Display::url(
1268
                Display::getMdiIcon(StateIcon::ACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('MakeInvisible')),
1269
                $this->unPublishUrl($meetingInfo)
1270
            )
1271
            : Display::url(
1272
                Display::getMdiIcon(StateIcon::INACTIVE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('MakeVisible')),
1273
                $this->publishUrl($meetingInfo)
1274
            );
1275
1276
        $links = [];
1277
        if ($this->plugin->get('allow_regenerate_recording') === 'true' && $meetingInfo['record'] == 1) {
1278
            if (!empty($recordInfo)) {
1279
                $links[] = Display::url(
1280
                    Display::getMdiIcon(ActionIcon::REFRESH, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('RegenerateRecord')),
1281
                    $this->regenerateRecordUrl($meetingInfo, $recordInfo)
1282
                );
1283
            } else {
1284
                $links[] = Display::url(
1285
                    Display::getMdiIcon(ActionIcon::REFRESH, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('RegenerateRecord')),
1286
                    $this->regenerateRecordUrlFromMeeting($meetingInfo)
1287
                );
1288
            }
1289
        }
1290
1291
        if (empty($recordInfo)) {
1292
            if (!$isAdminReport) {
1293
                if ($meetingInfo['status'] == 0) {
1294
                    $links[] = Display::url(
1295
                        Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')),
1296
                        $this->deleteRecordUrl($meetingInfo)
1297
                    );
1298
                    $links[] = $linkVisibility;
1299
                }
1300
1301
                return $links;
1302
            } else {
1303
                $links[] = Display::url(
1304
                    Display::getMdiIcon(ObjectIcon::HOME, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('GoToCourse')),
1305
                    $this->getListingUrl($meetingInfo['c_id'], $meetingInfo['session_id'], $meetingInfo['group_id'])
1306
                );
1307
1308
                return $links;
1309
            }
1310
        }
1311
1312
        if (!$isGlobal) {
1313
            $links[] = Display::url(
1314
                Display::getMdiIcon(ObjectIcon::LINK, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('UrlMeetingToShare')),
1315
                $this->copyToRecordToLinkTool($meetingInfo)
1316
            );
1317
            $links[] = Display::url(
1318
                Display::getMdiIcon(ObjectIcon::AGENDA, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('AddToCalendar')),
1319
                $this->addToCalendarUrl($meetingInfo, $recordInfo)
1320
            );
1321
        }
1322
1323
        $hide = $this->plugin->get('disable_download_conference_link') === 'true' ? true : false;
1324
1325
        if ($hide == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1326
            if ($meetingInfo['has_video_m4v']) {
1327
                $links[] = Display::url(
1328
                    Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('DownloadFile')),
1329
                    $recordInfo['playbackFormatUrl'].'/capture.m4v',
1330
                    ['target' => '_blank']
1331
                );
1332
            } else {
1333
                $links[] = Display::url(
1334
                    Display::getMdiIcon(ActionIcon::SAVE_FORM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('DownloadFile')),
1335
                    '#',
1336
                    [
1337
                        'id' => "btn-check-meeting-video-{$meetingInfo['id']}",
1338
                        'class' => 'check-meeting-video',
1339
                        'data-id' => $meetingInfo['id'],
1340
                    ]
1341
                );
1342
            }
1343
        }
1344
1345
1346
        if (!$isAdminReport) {
1347
            $links[] = Display::url(
1348
                Display::getMdiIcon(ActionIcon::DELETE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')),
1349
                $this->deleteRecordUrl($meetingInfo)
1350
            );
1351
            $links[] = $linkVisibility;
1352
        } else {
1353
            $links[] = Display::url(
1354
                Display::getMdiIcon(ObjectIcon::HOME, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('GoToCourse')),
1355
                $this->getListingUrl($meetingInfo['c_id'], $meetingInfo['session_id'], $meetingInfo['group_id'])
1356
            );
1357
        }
1358
1359
1360
        return $links;
1361
    }
1362
1363
    /**
1364
     * @param array $meeting
1365
     *
1366
     * @return string
1367
     */
1368
    public function unPublishUrl($meeting)
1369
    {
1370
        if (!isset($meeting['id'])) {
1371
            return null;
1372
        }
1373
1374
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams(
1375
            ).'&action=unpublish&id='.$meeting['id'];
1376
    }
1377
1378
    /**
1379
     * @param array $meeting
1380
     *
1381
     * @return string
1382
     */
1383
    public function publishUrl($meeting)
1384
    {
1385
        if (!isset($meeting['id'])) {
1386
            return '';
1387
        }
1388
1389
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams(
1390
            ).'&action=publish&id='.$meeting['id'];
1391
    }
1392
1393
    /**
1394
     * @param array $meeting
1395
     * @param array $recordInfo
1396
     *
1397
     * @return string
1398
     */
1399
    public function regenerateRecordUrl($meeting, $recordInfo)
1400
    {
1401
        if ($this->plugin->get('allow_regenerate_recording') !== 'true') {
1402
            return '';
1403
        }
1404
1405
        if (!isset($meeting['id'])) {
1406
            return '';
1407
        }
1408
1409
        if (empty($recordInfo) || (!empty($recordInfo['recordId']) && !isset($recordInfo['recordId']))) {
1410
            return '';
1411
        }
1412
1413
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().
1414
            '&action=regenerate_record&id='.$meeting['id'].'&record_id='.$recordInfo['recordId'];
1415
    }
1416
1417
    /**
1418
     * @param array $meeting
1419
     *
1420
     * @return string
1421
     */
1422
    public function regenerateRecordUrlFromMeeting($meeting)
1423
    {
1424
        if ($this->plugin->get('allow_regenerate_recording') !== 'true') {
1425
            return '';
1426
        }
1427
1428
        if (!isset($meeting['id'])) {
1429
            return '';
1430
        }
1431
1432
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().
1433
            '&action=regenerate_record&id='.$meeting['id'];
1434
    }
1435
1436
    /**
1437
     * @param array $meeting
1438
     *
1439
     * @return string
1440
     */
1441
    public function deleteRecordUrl($meeting)
1442
    {
1443
        if (!isset($meeting['id'])) {
1444
            return '';
1445
        }
1446
1447
        return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams(
1448
            ).'&action=delete_record&id='.$meeting['id'];
1449
    }
1450
1451
    /**
1452
     * @param array $meeting
1453
     *
1454
     * @return string
1455
     */
1456
    public function copyToRecordToLinkTool($meeting)
1457
    {
1458
        if (!isset($meeting['id'])) {
1459
            return '';
1460
        }
1461
1462
        return api_get_path(WEB_PLUGIN_PATH).
1463
            'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
1464
    }
1465
1466
    /**
1467
     * Function disabled
1468
     */
1469
    public function publishMeeting($id)
1470
    {
1471
        if (empty($id)) {
1472
            return false;
1473
        }
1474
1475
        $em = Database::getManager();
1476
        /** @var ConferenceMeetingRepository $repo */
1477
        $repo = $em->getRepository(ConferenceMeeting::class);
1478
1479
        $meeting = $repo->find($id);
1480
        if (!$meeting) {
1481
            return false;
1482
        }
1483
1484
        $meeting->setVisibility(1);
1485
        $em->flush();
1486
1487
        return true;
1488
    }
1489
1490
    /**
1491
     * Function disabled
1492
     */
1493
    public function unpublishMeeting($id)
1494
    {
1495
        if (empty($id)) {
1496
            return false;
1497
        }
1498
1499
        $em = Database::getManager();
1500
        /** @var ConferenceMeetingRepository $repo */
1501
        $repo = $em->getRepository(ConferenceMeeting::class);
1502
1503
        $meeting = $repo->find($id);
1504
        if (!$meeting) {
1505
            return false;
1506
        }
1507
1508
        $meeting->setVisibility(0);
1509
        $em->flush();
1510
1511
        return true;
1512
    }
1513
1514
    /**
1515
     * Get users online in the current course room.
1516
     *
1517
     * @return int The number of users currently connected to the videoconference
1518
     * @assert () > -1
1519
     */
1520
    public function getUsersOnlineInCurrentRoom()
1521
    {
1522
        $courseId = api_get_course_int_id();
1523
        $sessionId = api_get_session_id();
1524
1525
        $em = Database::getManager();
1526
        $repo = $em->getRepository(ConferenceMeeting::class);
1527
1528
        $qb = $repo->createQueryBuilder('m')
1529
            ->where('m.status = 1')
1530
            ->andWhere('m.accessUrl = :accessUrl')
1531
            ->setParameter('accessUrl', $this->accessUrl)
1532
            ->setMaxResults(1);
1533
1534
        if ($this->hasGroupSupport()) {
1535
            $groupId = api_get_group_id();
1536
            $qb->andWhere('m.course = :courseId')
1537
                ->andWhere('m.session = :sessionId')
1538
                ->andWhere('m.group = :groupId')
1539
                ->setParameter('courseId', $courseId)
1540
                ->setParameter('sessionId', $sessionId)
1541
                ->setParameter('groupId', $groupId);
1542
        } elseif ($this->isGlobalConferencePerUserEnabled()) {
1543
            $qb->andWhere('m.user = :userId')
1544
                ->setParameter('userId', $this->userId);
1545
        } else {
1546
            $qb->andWhere('m.course = :courseId')
1547
                ->andWhere('m.session = :sessionId')
1548
                ->setParameter('courseId', $courseId)
1549
                ->setParameter('sessionId', $sessionId);
1550
        }
1551
1552
        $meetingData = $qb->getQuery()->getOneOrNullResult();
1553
1554
        if (!$meetingData) {
1555
            return 0;
1556
        }
1557
        $pass = $meetingData->getModeratorPw();
1558
        $info = $this->getMeetingInfo([
1559
            'meetingId' => $meetingData->getRemoteId(),
1560
            'password' => $pass,
1561
        ]);
1562
        if ($info === false) {
1563
            $info = $this->getMeetingInfo([
1564
                'meetingId' => $meetingData->getId(),
1565
                'password' => $pass,
1566
            ]);
1567
        }
1568
1569
        if (!empty($info) && isset($info['participantCount'])) {
1570
            return (int) $info['participantCount'];
1571
        }
1572
1573
        return 0;
1574
    }
1575
1576
    /**
1577
     * @param int    $id
1578
     * @param string $recordId
1579
     *
1580
     * @return bool
1581
     */
1582
    public function regenerateRecording($id, $recordId = '')
1583
    {
1584
        if ($this->plugin->get('allow_regenerate_recording') !== 'true') {
1585
            return false;
1586
        }
1587
1588
        if (empty($id)) {
1589
            return false;
1590
        }
1591
1592
        $em = Database::getManager();
1593
        /** @var ConferenceMeetingRepository $repo */
1594
        $repo = $em->getRepository(ConferenceMeeting::class);
1595
1596
        $meetingData = $repo->findOneAsArrayById((int) $id);
1597
        if (!$meetingData) {
1598
            return false;
1599
        }
1600
1601
        Event::addEvent(
1602
            'bbb_regenerate_record',
1603
            'record_id',
1604
            (int) $recordId,
1605
            null,
1606
            api_get_user_id(),
1607
            api_get_course_int_id(),
1608
            api_get_session_id()
1609
        );
1610
1611
        /** @var ConferenceRecordingRepository $recordingRepo */
1612
        $recordingRepo = $em->getRepository(ConferenceRecordingRepository::class);
1613
        $recordings = $recordingRepo->findByMeetingRemoteId($meetingData['remoteId']);
1614
1615
        if (!empty($recordings) && isset($recordings['messageKey']) && $recordings['messageKey'] === 'noRecordings') {
1616
            if (!empty($meetingData['internalMeetingId'])) {
1617
                return $this->api->generateRecording(['recordId' => $meetingData['internalMeetingId']]);
1618
            }
1619
1620
            return false;
1621
        }
1622
1623
        if (!empty($recordings['records'])) {
1624
            foreach ($recordings['records'] as $record) {
1625
                if ($recordId == $record['recordId']) {
1626
                    return $this->api->generateRecording(['recordId' => $recordId]);
1627
                }
1628
            }
1629
        }
1630
1631
        return false;
1632
    }
1633
1634
    /**
1635
     * Deletes a recording of a meeting
1636
     *
1637
     * @param int $id ID of the recording
1638
     *
1639
     * @return bool
1640
     *
1641
     * @assert () === false
1642
     * @todo Also delete links and agenda items created from this recording
1643
     */
1644
    public function deleteRecording($id)
1645
    {
1646
        if (empty($id)) {
1647
            return false;
1648
        }
1649
1650
        $em = Database::getManager();
1651
1652
        /** @var ConferenceMeetingRepository $meetingRepo */
1653
        $meetingRepo = $em->getRepository(ConferenceMeeting::class);
1654
        $meetingData = $meetingRepo->findOneAsArrayById((int) $id);
1655
        if (!$meetingData) {
1656
            return false;
1657
        }
1658
1659
        Event::addEvent(
1660
            'bbb_delete_record',
1661
            'meeting_id',
1662
            $id,
1663
            null,
1664
            api_get_user_id(),
1665
            api_get_course_int_id(),
1666
            api_get_session_id()
1667
        );
1668
1669
        $delete = false;
1670
        $recordings = [];
1671
1672
        if (!empty($meetingData['remoteId'])) {
1673
            Event::addEvent(
1674
                'bbb_delete_record',
1675
                'remote_id',
1676
                $meetingData['remoteId'],
1677
                null,
1678
                api_get_user_id(),
1679
                api_get_course_int_id(),
1680
                api_get_session_id()
1681
            );
1682
1683
            /** @var ConferenceRecordingRepository $recordingRepo */
1684
            $recordingRepo = $em->getRepository(ConferenceRecording::class);
1685
            $recordings = $recordingRepo->findByMeetingRemoteId($meetingData['remoteId']);
1686
        }
1687
1688
        if (!empty($recordings) && isset($recordings['messageKey']) && $recordings['messageKey'] === 'noRecordings') {
1689
            $delete = true;
1690
        } elseif (!empty($recordings['records'])) {
1691
            $recordsToDelete = [];
1692
            foreach ($recordings['records'] as $record) {
1693
                $recordsToDelete[] = $record['recordId'];
1694
            }
1695
1696
            if (!empty($recordsToDelete)) {
1697
                $recordingParams = ['recordId' => implode(',', $recordsToDelete)];
1698
                Event::addEvent(
1699
                    'bbb_delete_record',
1700
                    'record_id_list',
1701
                    implode(',', $recordsToDelete),
1702
                    null,
1703
                    api_get_user_id(),
1704
                    api_get_course_int_id(),
1705
                    api_get_session_id()
1706
                );
1707
1708
                $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
1709
1710
                if (!empty($result) && isset($result['deleted']) && $result['deleted'] === 'true') {
1711
                    $delete = true;
1712
                }
1713
            }
1714
        }
1715
1716
        if ($delete) {
1717
            /** @var ConferenceActivityRepository $activityRepo */
1718
            $activityRepo = $em->getRepository(ConferenceActivity::class);
1719
            $activityRepo->closeAllByMeetingId((int) $id);
1720
1721
            $meeting = $meetingRepo->find((int) $id);
1722
            if ($meeting) {
1723
                $em->remove($meeting);
1724
            }
1725
1726
            $em->flush();
1727
        }
1728
1729
        return $delete;
1730
    }
1731
1732
    /**
1733
     * Creates a link in the links tool from the given videoconference recording
1734
     *
1735
     * @param int $id ID of the item in the plugin_bbb_meeting table
1736
     * @param string Hash identifying the recording, as provided by the API
1737
     *
1738
     * @return mixed ID of the newly created link, or false on error
1739
     * @assert (null, null) === false
1740
     * @assert (1, null) === false
1741
     * @assert (null, 'abcdefabcdefabcdefabcdef') === false
1742
     */
1743
    public function copyRecordingToLinkTool($id)
1744
    {
1745
        if (empty($id)) {
1746
            return false;
1747
        }
1748
1749
        $em = Database::getManager();
1750
        /** @var ConferenceMeetingRepository $repo */
1751
        $repo = $em->getRepository(ConferenceMeeting::class);
1752
1753
        $meetingData = $repo->findOneAsArrayById((int) $id);
1754
        if (!$meetingData || empty($meetingData['remoteId'])) {
1755
            return false;
1756
        }
1757
1758
        $records = $this->api->getRecordingsWithXmlResponseArray([
1759
            'meetingId' => $meetingData['remoteId']
1760
        ]);
1761
1762
        if (!empty($records)) {
1763
            if (isset($records['message']) && !empty($records['message'])) {
1764
                if ($records['messageKey'] == 'noRecordings') {
1765
                    return false;
1766
                }
1767
            } else {
1768
                $record = $records[0];
1769
                if (is_array($record) && isset($record['recordId'])) {
1770
                    $url = $record['playbackFormatUrl'];
1771
                    $link = new \Link();
1772
                    $params = [
1773
                        'url' => $url,
1774
                        'title' => $meetingData['title'],
1775
                    ];
1776
                    $id = $link->save($params);
1777
1778
                    return $id;
1779
                }
1780
            }
1781
        }
1782
1783
        return false;
1784
    }
1785
1786
    /**
1787
     * Checks if the video conference server is running.
1788
     * Function currently disabled (always returns 1)
1789
     * @return bool True if server is running, false otherwise
1790
     * @assert () === false
1791
     */
1792
    public function isServerRunning()
1793
    {
1794
        return true;
1795
        //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
1796
    }
1797
1798
    /**
1799
     * Checks if the video conference plugin is properly configured
1800
     * @return bool True if plugin has a host and a salt, false otherwise
1801
     * @assert () === false
1802
     */
1803
    public function isServerConfigured()
1804
    {
1805
        $host = $this->plugin->get('host');
1806
1807
        if (empty($host)) {
1808
            return false;
1809
        }
1810
1811
        $salt = $this->plugin->get('salt');
1812
1813
        if (empty($salt)) {
1814
            return false;
1815
        }
1816
1817
        return true;
1818
        //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
1819
    }
1820
1821
    /**
1822
     * Get active session in the all platform
1823
     */
1824
    public function getActiveSessionsCount(): int
1825
    {
1826
        $em = Database::getManager();
1827
        $qb = $em->createQueryBuilder();
1828
1829
        $qb->select('COUNT(m.id)')
1830
            ->from(ConferenceMeeting::class, 'm')
1831
            ->where('m.status = :status')
1832
            ->andWhere('m.accessUrl = :accessUrl')
1833
            ->setParameter('status', 1)
1834
            ->setParameter('accessUrl', $this->accessUrl);
1835
1836
        return (int) $qb->getQuery()->getSingleScalarResult();
1837
    }
1838
1839
    /**
1840
     * Get active session in the all platform
1841
     */
1842
    public function getActiveSessions(): array
1843
    {
1844
        $em = Database::getManager();
1845
        $repo = $em->getRepository(ConferenceMeeting::class);
1846
1847
        $qb = $repo->createQueryBuilder('m')
1848
            ->where('m.status = :status')
1849
            ->andWhere('m.accessUrl = :accessUrl')
1850
            ->setParameter('status', 1)
1851
            ->setParameter('accessUrl', $this->accessUrl);
1852
1853
        return $qb->getQuery()->getArrayResult();
1854
    }
1855
1856
    /**
1857
     * @param string $url
1858
     */
1859
    public function redirectToBBB($url)
1860
    {
1861
        if (file_exists(__DIR__.'/../config.vm.php')) {
1862
            // Using VM
1863
            echo Display::url($this->plugin->get_lang('ClickToContinue'), $url);
1864
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1865
        } else {
1866
            // Classic
1867
            header("Location: $url");
1868
            exit;
1869
        }
1870
    }
1871
1872
    /**
1873
     * @return string
1874
     */
1875
    public function getConferenceUrl()
1876
    {
1877
        return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
1878
    }
1879
1880
    /**
1881
     * Get the meeting info from DB by its name
1882
     *
1883
     * @param string $name
1884
     *
1885
     * @return array
1886
     */
1887
    public function findMeetingByName(string $name): ?array
1888
    {
1889
        $em = Database::getManager();
1890
        /** @var ConferenceMeetingRepository $repo */
1891
        $repo = $em->getRepository(ConferenceMeeting::class);
1892
1893
        $qb = $repo->createQueryBuilder('m')
1894
            ->where('m.meetingName = :name')
1895
            ->andWhere('m.status = 1')
1896
            ->setParameter('name', $name)
1897
            ->setMaxResults(1);
1898
1899
        $result = $qb->getQuery()->getArrayResult();
1900
1901
        return $result[0] ?? null;
1902
    }
1903
1904
    /**
1905
     * Get the meeting info from DB by its name
1906
     *
1907
     * @param int $id
1908
     *
1909
     * @return array
1910
     */
1911
    public function getMeeting(int $id): ?array
1912
    {
1913
        $em = Database::getManager();
1914
        /** @var ConferenceMeetingRepository $repo */
1915
        $repo = $em->getRepository(ConferenceMeeting::class);
1916
1917
        return $repo->findOneAsArrayById($id);
1918
    }
1919
1920
    /**
1921
     * Get the meeting info.
1922
     *
1923
     * @param int $id
1924
     *
1925
     * @return array
1926
     */
1927
    public function getMeetingByRemoteId(string $id): ?array
1928
    {
1929
        $em = Database::getManager();
1930
        /** @var ConferenceMeetingRepository $repo */
1931
        $repo = $em->getRepository(ConferenceMeeting::class);
1932
1933
        return $repo->findOneByRemoteIdAndAccessUrl($id, $this->accessUrl);
1934
    }
1935
1936
    /**
1937
     * @param int $meetingId
1938
     *
1939
     * @return array
1940
     */
1941
    public function findConnectedMeetingParticipants(int $meetingId): array
1942
    {
1943
        $em = Database::getManager();
1944
        /** @var ConferenceActivityRepository $repo */
1945
        $repo = $em->getRepository(ConferenceActivity::class);
1946
1947
        $activities = $repo->createQueryBuilder('a')
1948
            ->where('a.meeting = :meetingId')
1949
            ->andWhere('a.inAt IS NOT NULL')
1950
            ->setParameter('meetingId', $meetingId)
1951
            ->getQuery()
1952
            ->getResult();
1953
1954
        $participantIds = [];
1955
        $return = [];
1956
1957
        foreach ($activities as $activity) {
1958
            $participant = $activity->getParticipant();
1959
            $participantId = $participant?->getId();
1960
1961
            if (!$participantId || in_array($participantId, $participantIds)) {
1962
                continue;
1963
            }
1964
1965
            $participantIds[] = $participantId;
1966
1967
            $return[] = [
1968
                'id' => $activity->getId(),
1969
                'meeting_id' => $meetingId,
1970
                'participant' => api_get_user_entity($participantId),
1971
                'in_at' => $activity->getInAt()?->format('Y-m-d H:i:s'),
1972
                'out_at' => $activity->getOutAt()?->format('Y-m-d H:i:s'),
1973
            ];
1974
        }
1975
1976
        return $return;
1977
    }
1978
1979
    /**
1980
     * Check if the meeting has a capture.m4v video file. If exists then the has_video_m4v field is updated
1981
     *
1982
     * @param int $meetingId
1983
     *
1984
     * @return bool
1985
     */
1986
    public function checkDirectMeetingVideoUrl(int $meetingId): bool
1987
    {
1988
        $em = Database::getManager();
1989
        /** @var ConferenceMeetingRepository $repo */
1990
        $repo = $em->getRepository(ConferenceMeeting::class);
1991
1992
        $meetingInfo = $repo->findOneAsArrayById($meetingId);
1993
1994
        if (empty($meetingInfo) || !isset($meetingInfo['videoUrl'])) {
1995
            return false;
1996
        }
1997
1998
        $hasCapture = SocialManager::verifyUrl($meetingInfo['videoUrl'].'/capture.m4v');
1999
2000
        if ($hasCapture) {
2001
            $qb = $em->createQueryBuilder();
2002
            $qb->update(ConferenceMeeting::class, 'm')
2003
                ->set('m.hasVideoM4v', ':value')
2004
                ->where('m.id = :id')
2005
                ->setParameter('value', true)
2006
                ->setParameter('id', $meetingId)
2007
                ->getQuery()
2008
                ->execute();
2009
2010
            return true;
2011
        }
2012
2013
        return false;
2014
    }
2015
}
2016