forked from blindsidenetworks-ps/moodle-mod_bigbluebuttonbn
-
Notifications
You must be signed in to change notification settings - Fork 3
/
lib.php
1225 lines (1136 loc) · 43.3 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library calls for Moodle and BigBlueButton.
*
* @package mod_bigbluebuttonbn
* @copyright 2010 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com)
*/
defined('MOODLE_INTERNAL') || die;
global $CFG;
// JWT is included in Moodle 3.7 core, but a local package is still needed for backward compatibility.
if (!class_exists('\Firebase\JWT\JWT')) {
if (file_exists($CFG->libdir.'/php-jwt/src/JWT.php')) {
require_once($CFG->libdir.'/php-jwt/src/JWT.php');
} else {
require_once($CFG->dirroot.'/mod/bigbluebuttonbn/vendor/firebase/php-jwt/src/JWT.php');
}
}
// Do not declare new $CFG variables if unit tests are running
// as it can cause "unexpected new $CFG->xxx value" warnings.
if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
if (!isset($CFG->bigbluebuttonbn)) {
$CFG->bigbluebuttonbn = array();
}
if (file_exists(dirname(__FILE__).'/config.php')) {
require_once(dirname(__FILE__).'/config.php');
}
/*
* DURATIONCOMPENSATION: Feature removed by configuration
*/
$CFG->bigbluebuttonbn['scheduled_duration_enabled'] = 0;
/*
* Remove this block when restored
*/
}
/** @var BIGBLUEBUTTONBN_DEFAULT_SERVER_URL string of default bigbluebutton server url */
const BIGBLUEBUTTONBN_DEFAULT_SERVER_URL = 'http://test-install.blindsidenetworks.com/bigbluebutton/';
/** @var BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET string of default bigbluebutton server shared secret */
const BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET = '8cd8ef52e8e101574e400365b55e11a6';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_ADD string defines the bigbluebuttonbn Add event */
const BIGBLUEBUTTONBN_LOG_EVENT_ADD = 'Add';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_EDIT string defines the bigbluebuttonbn Edit event */
const BIGBLUEBUTTONBN_LOG_EVENT_EDIT = 'Edit';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_CREATE string defines the bigbluebuttonbn Create event */
const BIGBLUEBUTTONBN_LOG_EVENT_CREATE = 'Create';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_JOIN string defines the bigbluebuttonbn Join event */
const BIGBLUEBUTTONBN_LOG_EVENT_JOIN = 'Join';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_PLAYED string defines the bigbluebuttonbn Playback event */
const BIGBLUEBUTTONBN_LOG_EVENT_PLAYED = 'Played';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT string defines the bigbluebuttonbn Logout event */
const BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT = 'Logout';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_IMPORT string defines the bigbluebuttonbn Import event */
const BIGBLUEBUTTONBN_LOG_EVENT_IMPORT = 'Import';
/** @var BIGBLUEBUTTONBN_LOG_EVENT_DELETE string defines the bigbluebuttonbn Delete event */
const BIGBLUEBUTTONBN_LOG_EVENT_DELETE = 'Delete';
/** @var BIGBLUEBUTTON_LOG_EVENT_CALLBACK string defines the bigbluebuttonbn Callback event */
const BIGBLUEBUTTON_LOG_EVENT_CALLBACK = 'Callback';
/** @var BIGBLUEBUTTON_LOG_EVENT_SUMMARY string defines the bigbluebuttonbn Summary event */
const BIGBLUEBUTTON_LOG_EVENT_SUMMARY = 'Summary';
/**
* Indicates API features that the bigbluebuttonbn supports.
*
* @uses FEATURE_IDNUMBER
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
* @uses FEATURE_GROUPMEMBERSONLY
* @uses FEATURE_MOD_INTRO
* @uses FEATURE_BACKUP_MOODLE2
* @uses FEATURE_COMPLETION_TRACKS_VIEWS
* @uses FEATURE_COMPLETION_HAS_RULES
* @uses FEATURE_GRADE_HAS_GRADE
* @uses FEATURE_GRADE_OUTCOMES
* @uses FEATURE_SHOW_DESCRIPTION
* @param string $feature
* @return mixed True if yes (some features may use other values)
*/
function bigbluebuttonbn_supports($feature) {
if (!$feature) {
return null;
}
$features = array(
(string) FEATURE_IDNUMBER => true,
(string) FEATURE_GROUPS => true,
(string) FEATURE_GROUPINGS => true,
(string) FEATURE_GROUPMEMBERSONLY => true,
(string) FEATURE_MOD_INTRO => true,
(string) FEATURE_BACKUP_MOODLE2 => true,
(string) FEATURE_COMPLETION_TRACKS_VIEWS => true,
(string) FEATURE_COMPLETION_HAS_RULES => true,
(string) FEATURE_GRADE_HAS_GRADE => false,
(string) FEATURE_GRADE_OUTCOMES => false,
(string) FEATURE_SHOW_DESCRIPTION => true,
);
if (isset($features[(string) $feature])) {
return $features[$feature];
}
return null;
}
/**
* Obtains the automatic completion state for this bigbluebuttonbn based on any conditions
* in bigbluebuttonbn settings.
*
* @param object $course Course
* @param object $cm Course-module
* @param int $userid User ID
* @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
*
* @return bool True if completed, false if not. (If no conditions, then return
* value depends on comparison type)
*/
function bigbluebuttonbn_get_completion_state($course, $cm, $userid, $type) {
global $DB;
// Get bigbluebuttonbn details.
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance), '*',
MUST_EXIST);
if (!$bigbluebuttonbn) {
throw new Exception("Can't find bigbluebuttonbn {$cm->instance}");
}
// Default return value.
$result = $type;
$sql = "SELECT * FROM {bigbluebuttonbn_logs} ";
$sql .= "WHERE bigbluebuttonbnid = ? AND userid = ? AND log = ?";
$logs = $DB->get_records_sql($sql, array($bigbluebuttonbn->id, $userid, BIGBLUEBUTTON_LOG_EVENT_SUMMARY));
if ($bigbluebuttonbn->completionattendance) {
if (!$logs) {
// As completion by attendance was required, the activity hasn't been completed.
return false;
}
$attendancecount = 0;
foreach ($logs as $log) {
$summary = json_decode($log->meta);
$attendancecount += $summary->data->duration;
}
$attendancecount /= 60;
$value = $bigbluebuttonbn->completionattendance <= $attendancecount;
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($bigbluebuttonbn->completionengagementchats) {
if (!$logs) {
// As completion by engagement with chat was required, the activity hasn't been completed.
return false;
}
$engagementchatscount = 0;
foreach ($logs as $log) {
$summary = json_decode($log->meta);
$engagementchatscount += $summary->data->engagement->chats;
}
$value = $bigbluebuttonbn->completionengagementchats <= $engagementchatscount;
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
if ($bigbluebuttonbn->completionengagementtalks) {
if (!$logs) {
// As completion by engagement with talk was required, the activity hasn't been completed.
return false;
}
$engagementtalkscount = 0;
foreach ($logs as $log) {
$summary = json_decode($log->meta);
$engagementtalkscount += $summary->data->engagement->talks;
}
$value = $bigbluebuttonbn->completionengagementtalks <= $engagementtalkscount;
if ($type == COMPLETION_AND) {
$result = $result && $value;
} else {
$result = $result || $value;
}
}
return $result;
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
*
* @param object $bigbluebuttonbn An object from the form in mod_form.php
* @return int The id of the newly inserted bigbluebuttonbn record
*/
function bigbluebuttonbn_add_instance($bigbluebuttonbn) {
global $DB;
// Excecute preprocess.
bigbluebuttonbn_process_pre_save($bigbluebuttonbn);
// Pre-set initial values.
$bigbluebuttonbn->presentation = bigbluebuttonbn_get_media_file($bigbluebuttonbn);
// Insert a record.
$bigbluebuttonbn->id = $DB->insert_record('bigbluebuttonbn', $bigbluebuttonbn);
// Encode meetingid.
$bigbluebuttonbn->meetingid = bigbluebuttonbn_unique_meetingid_seed();
// Set the meetingid column in the bigbluebuttonbn table.
$DB->set_field('bigbluebuttonbn', 'meetingid', $bigbluebuttonbn->meetingid, array('id' => $bigbluebuttonbn->id));
// Log insert action.
bigbluebuttonbn_log($bigbluebuttonbn, BIGBLUEBUTTONBN_LOG_EVENT_ADD);
// Complete the process.
bigbluebuttonbn_process_post_save($bigbluebuttonbn);
return $bigbluebuttonbn->id;
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
* @param object $bigbluebuttonbn An object from the form in mod_form.php
* @return bool Success/Fail
*/
function bigbluebuttonbn_update_instance($bigbluebuttonbn) {
global $DB;
// Excecute preprocess.
bigbluebuttonbn_process_pre_save($bigbluebuttonbn);
// Pre-set initial values.
$bigbluebuttonbn->id = $bigbluebuttonbn->instance;
$bigbluebuttonbn->presentation = bigbluebuttonbn_get_media_file($bigbluebuttonbn);
// Update a record.
$DB->update_record('bigbluebuttonbn', $bigbluebuttonbn);
// Get the meetingid column in the bigbluebuttonbn table.
$bigbluebuttonbn->meetingid = (string)$DB->get_field('bigbluebuttonbn', 'meetingid', array('id' => $bigbluebuttonbn->id));
// Log update action.
bigbluebuttonbn_log($bigbluebuttonbn, BIGBLUEBUTTONBN_LOG_EVENT_EDIT);
// Complete the process.
bigbluebuttonbn_process_post_save($bigbluebuttonbn);
return true;
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @param int $id Id of the module instance
*
* @return bool Success/Failure
*/
function bigbluebuttonbn_delete_instance($id) {
global $DB;
if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $id))) {
return false;
}
// TODO: End the meeting if it is running.
$result = true;
// Delete any dependent records here.
if (!$DB->delete_records('bigbluebuttonbn', array('id' => $bigbluebuttonbn->id))) {
$result = false;
}
if (!$DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id))) {
$result = false;
}
// Log action performed.
bigbluebuttonbn_delete_instance_log($bigbluebuttonbn);
return $result;
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the data that depends on it.
*
* @param object $bigbluebuttonbn Id of the module instance
*
* @return bool Success/Failure
*/
function bigbluebuttonbn_delete_instance_log($bigbluebuttonbn) {
global $DB;
$sql = "SELECT * FROM {bigbluebuttonbn_logs} ";
$sql .= "WHERE bigbluebuttonbnid = ? AND log = ? AND ". $DB->sql_compare_text('meta') . " = ?";
$logs = $DB->get_records_sql($sql, array($bigbluebuttonbn->id, BIGBLUEBUTTONBN_LOG_EVENT_CREATE, "{\"record\":true}"));
$meta = "{\"has_recordings\":" . empty($logs) ? "true" : "false" . "}";
bigbluebuttonbn_log($bigbluebuttonbn, BIGBLUEBUTTONBN_LOG_EVENT_DELETE, [], $meta);
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
*
* @param object $course
* @param object $user
* @param object $mod
* @param object $bigbluebuttonbn
*
* @return bool
*/
function bigbluebuttonbn_user_outline($course, $user, $mod, $bigbluebuttonbn) {
if ($completed = bigbluebuttonbn_user_complete($course, $user, $bigbluebuttonbn)) {
return fullname($user) . ' ' . get_string('view_message_has_joined', 'bigbluebuttonbn') . ' ' .
get_string('view_message_session_for', 'bigbluebuttonbn') . ' ' . (string) $completed . ' ' .
get_string('view_message_times', 'bigbluebuttonbn');
}
return '';
}
/**
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*
* @param object|int $courseorid
* @param object|int $userorid
* @param object $bigbluebuttonbn
*
* @return bool
*/
function bigbluebuttonbn_user_complete($courseorid, $userorid, $bigbluebuttonbn) {
global $DB;
if (is_object($courseorid)) {
$course = $courseorid;
} else {
$course = (object)array('id' => $courseorid);
}
if (is_object($userorid)) {
$user = $userorid;
} else {
$user = (object)array('id' => $userorid);
}
$sql = "SELECT COUNT(*) FROM {bigbluebuttonbn_logs} ";
$sql .= "WHERE courseid = ? AND bigbluebuttonbnid = ? AND userid = ? AND (log = ? OR log = ?)";
$result = $DB->count_records_sql($sql, array($course->id, $bigbluebuttonbn->id, $user->id,
BIGBLUEBUTTONBN_LOG_EVENT_JOIN, BIGBLUEBUTTONBN_LOG_EVENT_PLAYED));
return $result;
}
/**
* Returns all other caps used in module.
*
* @return string[]
*/
function bigbluebuttonbn_get_extra_capabilities() {
return array('moodle/site:accessallgroups');
}
/**
* Define items to be reset by course/reset.php
*
* @return array
*/
function bigbluebuttonbn_reset_course_items() {
$items = array("events" => 0, "tags" => 0, "logs" => 0);
// Include recordings only if enabled.
if ((boolean)\mod_bigbluebuttonbn\locallib\config::recordings_enabled()) {
$items["recordings"] = 0;
}
return $items;
}
/**
* Called by course/reset.php
*
* @param object $mform
* @return void
*/
function bigbluebuttonbn_reset_course_form_definition(&$mform) {
$items = bigbluebuttonbn_reset_course_items();
$mform->addElement('header', 'bigbluebuttonbnheader', get_string('modulenameplural', 'bigbluebuttonbn'));
foreach ($items as $item => $default) {
$mform->addElement(
'advcheckbox',
"reset_bigbluebuttonbn_{$item}",
get_string("reset{$item}", 'bigbluebuttonbn')
);
if ($item == 'logs' || $item == 'recordings') {
$mform->addHelpButton("reset_bigbluebuttonbn_{$item}", "reset{$item}", 'bigbluebuttonbn');
}
}
}
/**
* Course reset form defaults.
*
* @param object $course
* @return array
*/
function bigbluebuttonbn_reset_course_form_defaults($course) {
$formdefaults = array();
$items = bigbluebuttonbn_reset_course_items();
// All unchecked by default.
foreach ($items as $item => $default) {
$formdefaults["reset_bigbluebuttonbn_{$item}"] = $default;
}
return $formdefaults;
}
/**
* This function is used by the reset_course_userdata function in moodlelib.
*
* @param array $data the data submitted from the reset course.
* @return array status array
*/
function bigbluebuttonbn_reset_userdata($data) {
$items = bigbluebuttonbn_reset_course_items();
$status = array();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
if (array_key_exists('recordings', $items) && !empty($data->reset_bigbluebuttonbn_recordings)) {
// Remove all the recordings from a BBB server that are linked to the room/activities in this course.
bigbluebuttonbn_reset_recordings($data->courseid);
unset($items['recordings']);
$status[] = bigbluebuttonbn_reset_getstatus('recordings');
}
if (!empty($data->reset_bigbluebuttonbn_tags)) {
// Remove all the tags linked to the room/activities in this course.
bigbluebuttonbn_reset_tags($data->courseid);
unset($items['tags']);
$status[] = bigbluebuttonbn_reset_getstatus('tags');
}
// TODO : seems to be duplicated code unless we just want to force reset tags.
foreach ($items as $item => $default) {
// Remove instances or elements linked to this course, others than recordings or tags.
if (!empty($data->{"reset_bigbluebuttonbn_{$item}"})) {
call_user_func("bigbluebuttonbn_reset_{$item}", $data->courseid);
$status[] = bigbluebuttonbn_reset_getstatus($item);
}
}
return $status;
}
/**
* Returns status used on every defined reset action.
*
* @param string $item
* @return array status array
*/
function bigbluebuttonbn_reset_getstatus($item) {
return array('component' => get_string('modulenameplural', 'bigbluebuttonbn')
, 'item' => get_string("removed{$item}", 'bigbluebuttonbn')
, 'error' => false);
}
/**
* Used by the reset_course_userdata for deleting events linked to bigbluebuttonbn instances in the course.
*
* @param string $courseid
* @return array status array
*/
function bigbluebuttonbn_reset_events($courseid) {
global $DB;
// Remove all the events.
return $DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'courseid' => $courseid));
}
/**
* Used by the reset_course_userdata for deleting tags linked to bigbluebuttonbn instances in the course.
*
* @param array $courseid
* @return array status array
*/
function bigbluebuttonbn_reset_tags($courseid) {
global $DB;
// Remove all the tags linked to the room/activities in this course.
if ($bigbluebuttonbns = $DB->get_records('bigbluebuttonbn', array('course' => $courseid))) {
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
if (!$cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $courseid)) {
continue;
}
$context = context_module::instance($cm->id);
core_tag_tag::delete_instances('mod_bigbluebuttonbn', null, $context->id);
}
}
}
/**
* Used by the reset_course_userdata for deleting bigbluebuttonbn_logs linked to bigbluebuttonbn instances in the course.
*
* @param string $courseid
* @return array status array
*/
function bigbluebuttonbn_reset_logs($courseid) {
global $DB;
// Remove all the logs.
return $DB->delete_records('bigbluebuttonbn_logs', array('courseid' => $courseid));
}
/**
* Used by the reset_course_userdata for deleting recordings in a BBB server linked to bigbluebuttonbn instances in the course.
*
* @param string $courseid
* @return array status array
*/
function bigbluebuttonbn_reset_recordings($courseid) {
require_once(__DIR__.'/locallib.php');
// Criteria for search [courseid | bigbluebuttonbn=null | subset=false | includedeleted=true].
$recordings = bigbluebuttonbn_get_recordings($courseid, null, false, true);
// Remove all the recordings.
bigbluebuttonbn_delete_recordings(implode(",", array_keys($recordings)));
}
/**
* List of view style log actions.
*
* @return string[]
*/
function bigbluebuttonbn_get_view_actions() {
return array('view', 'view all');
}
/**
* List of update style log actions.
*
* @return string[]
*/
function bigbluebuttonbn_get_post_actions() {
return array('update', 'add', 'delete');
}
/**
* Print an overview of all bigbluebuttonbn instances for the courses.
*
* @param array $courses
* @param array $htmlarray Passed by reference
*
* @return void
*/
function bigbluebuttonbn_print_overview($courses, &$htmlarray) {
if (empty($courses) || !is_array($courses)) {
return array();
}
$bns = get_all_instances_in_courses('bigbluebuttonbn', $courses);
foreach ($bns as $bn) {
$now = time();
if ($bn->openingtime and (!$bn->closingtime or $bn->closingtime > $now)) {
// A bigbluebuttonbn is scheduled.
if (empty($htmlarray[$bn->course]['bigbluebuttonbn'])) {
$htmlarray[$bn->course]['bigbluebuttonbn'] = '';
}
// Make sure we print all bigbluebutton instances.
$htmlarray[$bn->course]['bigbluebuttonbn'] .= bigbluebuttonbn_print_overview_element($bn, $now);
}
}
}
/**
* Print an overview of a bigbluebuttonbn instance.
*
* @param array $bigbluebuttonbn
* @param int $now
*
* @return string
*/
function bigbluebuttonbn_print_overview_element($bigbluebuttonbn, $now) {
global $CFG;
$start = 'started_at';
if ($bigbluebuttonbn->openingtime > $now) {
$start = 'starts_at';
}
$classes = '';
if ($bigbluebuttonbn->visible) {
$classes = 'class="dimmed" ';
}
$str = '<div class="bigbluebuttonbn overview">'."\n";
$str .= ' <div class="name">'.get_string('modulename', 'bigbluebuttonbn').': '."\n";
$str .= ' <a '.$classes.'href="'.$CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bigbluebuttonbn->coursemodule.
'">'.$bigbluebuttonbn->name.'</a>'."\n";
$str .= ' </div>'."\n";
$str .= ' <div class="info">'.get_string($start, 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->openingtime).
'</div>'."\n";
$str .= ' <div class="info">'.get_string('ends_at', 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->closingtime)
.'</div>'."\n";
$str .= '</div>'."\n";
return $str;
}
/**
* Given a course_module object, this function returns any
* "extra" information that may be needed when printing
* this activity in a course listing.
* See get_array_of_activities() in course/lib.php.
*
* @param object $coursemodule
*
* @return null|cached_cm_info
*/
function bigbluebuttonbn_get_coursemodule_info($coursemodule) {
global $DB;
$dbparams = ['id' => $coursemodule->instance];
$fields = 'id, name, intro, introformat, completionattendance';
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', $dbparams, $fields);
if (!$bigbluebuttonbn) {
return false;
}
$info = new cached_cm_info();
$info->name = $bigbluebuttonbn->name;
if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
$info->content = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $coursemodule->id, false);
}
// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$info->customdata['customcompletionrules']['completionattendance'] = $bigbluebuttonbn->completionattendance;
}
return $info;
}
/**
* Callback which returns human-readable strings describing the active completion custom rules for the module instance.
*
* @param cm_info|stdClass $cm object with fields ->completion and ->customdata['customcompletionrules']
* @return array $descriptions the array of descriptions for the custom rules.
*/
function mod_bigbluebuttonbn_get_completion_active_rule_descriptions($cm) {
// Values will be present in cm_info, and we assume these are up to date.
if (empty($cm->customdata['customcompletionrules'])
|| $cm->completion != COMPLETION_TRACKING_AUTOMATIC) {
return [];
}
$descriptions = [];
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionattendance':
if (!empty($val)) {
$descriptions[] = get_string('completionattendancedesc', 'bigbluebuttonbn', $val);
$descriptions[] = get_string('completionengagementdesc', 'bigbluebuttonbn', $val);
}
break;
default:
break;
}
}
return $descriptions;
}
/**
* Runs any processes that must run before a bigbluebuttonbn insert/update.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_pre_save(&$bigbluebuttonbn) {
bigbluebuttonbn_process_pre_save_instance($bigbluebuttonbn);
bigbluebuttonbn_process_pre_save_checkboxes($bigbluebuttonbn);
bigbluebuttonbn_process_pre_save_common($bigbluebuttonbn);
$bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants);
}
/**
* Runs process for defining the instance (insert/update).
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_pre_save_instance(&$bigbluebuttonbn) {
require_once(__DIR__.'/locallib.php');
$bigbluebuttonbn->timemodified = time();
if ((integer)$bigbluebuttonbn->instance == 0) {
$bigbluebuttonbn->meetingid = 0;
$bigbluebuttonbn->timecreated = time();
$bigbluebuttonbn->timemodified = 0;
// As it is a new activity, assign passwords.
$bigbluebuttonbn->moderatorpass = bigbluebuttonbn_random_password(12);
$bigbluebuttonbn->viewerpass = bigbluebuttonbn_random_password(12, $bigbluebuttonbn->moderatorpass);
$bigbluebuttonbn->guestlinkid = bigbluebuttonbn_random_password(12);
}
}
/**
* Runs process for assigning default value to checkboxes.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_pre_save_checkboxes(&$bigbluebuttonbn) {
if (!isset($bigbluebuttonbn->wait)) {
$bigbluebuttonbn->wait = 0;
}
if (!isset($bigbluebuttonbn->record)) {
$bigbluebuttonbn->record = 0;
}
if (!isset($bigbluebuttonbn->recordallfromstart)) {
$bigbluebuttonbn->recordallfromstart = 0;
}
if (!isset($bigbluebuttonbn->recordhidebutton)) {
$bigbluebuttonbn->recordhidebutton = 0;
}
if (!isset($bigbluebuttonbn->recordings_html)) {
$bigbluebuttonbn->recordings_html = 0;
}
if (!isset($bigbluebuttonbn->recordings_deleted)) {
$bigbluebuttonbn->recordings_deleted = 0;
}
if (!isset($bigbluebuttonbn->recordings_imported)) {
$bigbluebuttonbn->recordings_imported = 0;
}
if (!isset($bigbluebuttonbn->recordings_preview)) {
$bigbluebuttonbn->recordings_preview = 0;
}
if (!isset($bigbluebuttonbn->muteonstart)) {
$bigbluebuttonbn->muteonstart = 0;
}
if (!isset($bigbluebuttonbn->recordings_validate_url)) {
$bigbluebuttonbn->recordings_validate_url = 1;
}
}
/**
* Runs process for wipping common settings when 'recordings only'.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_pre_save_common(&$bigbluebuttonbn) {
// Make sure common settings are removed when 'recordings only'.
if ($bigbluebuttonbn->type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) {
$bigbluebuttonbn->groupmode = 0;
$bigbluebuttonbn->groupingid = 0;
}
}
/**
* Runs any processes that must be run after a bigbluebuttonbn insert/update.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_post_save(&$bigbluebuttonbn) {
if (isset($bigbluebuttonbn->notification) && $bigbluebuttonbn->notification) {
bigbluebuttonbn_process_post_save_notification($bigbluebuttonbn);
}
bigbluebuttonbn_process_post_save_event($bigbluebuttonbn);
bigbluebuttonbn_process_post_save_completion($bigbluebuttonbn);
}
/**
* Generates a message on insert/update which is sent to all users enrolled.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_post_save_notification(&$bigbluebuttonbn) {
$action = get_string('mod_form_field_notification_msg_modified', 'bigbluebuttonbn');
if (isset($bigbluebuttonbn->add) && !empty($bigbluebuttonbn->add)) {
$action = get_string('mod_form_field_notification_msg_created', 'bigbluebuttonbn');
}
\mod_bigbluebuttonbn\locallib\notifier::notify_instance_updated($bigbluebuttonbn, $action);
}
/**
* Generates an event after a bigbluebuttonbn insert/update.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_post_save_event(&$bigbluebuttonbn) {
global $CFG, $DB;
require_once($CFG->dirroot.'/calendar/lib.php');
$eventid = $DB->get_field('event', 'id', array('modulename' => 'bigbluebuttonbn',
'instance' => $bigbluebuttonbn->id));
// Delete the event from calendar when/if openingtime is NOT set.
if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) {
if ($eventid) {
$calendarevent = calendar_event::load($eventid);
$calendarevent->delete();
}
return;
}
// Add evento to the calendar as openingtime is set.
$event = new stdClass();
$event->eventtype = BIGBLUEBUTTON_EVENT_MEETING_START;
$event->type = CALENDAR_EVENT_TYPE_ACTION;
$event->name = get_string('calendarstarts', 'bigbluebuttonbn', $bigbluebuttonbn->name);
$event->description = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $bigbluebuttonbn->coursemodule);
$event->courseid = $bigbluebuttonbn->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'bigbluebuttonbn';
$event->instance = $bigbluebuttonbn->id;
$event->timestart = $bigbluebuttonbn->openingtime;
$event->timeduration = 0;
$event->timesort = $event->timestart;
$event->visible = instance_is_visible('bigbluebuttonbn', $bigbluebuttonbn);
$event->priority = null;
// Update the event in calendar when/if eventid was found.
if ($eventid) {
$event->id = $eventid;
$calendarevent = calendar_event::load($eventid);
$calendarevent->update($event);
return;
}
calendar_event::create($event);
}
/**
* Generates an event after a bigbluebuttonbn activity is completed.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return void
**/
function bigbluebuttonbn_process_post_save_completion($bigbluebuttonbn) {
if (!empty($bigbluebuttonbn->completionexpected)) {
\core_completion\api::update_completion_date_event(
$bigbluebuttonbn->coursemodule,
'bigbluebuttonbn',
$bigbluebuttonbn->id,
$bigbluebuttonbn->completionexpected
);
}
}
/**
* Get a full path to the file attached as a preuploaded presentation
* or if there is none, set the presentation field will be set to blank.
*
* @param object $bigbluebuttonbn BigBlueButtonBN form data
*
* @return string
*/
function bigbluebuttonbn_get_media_file(&$bigbluebuttonbn) {
if (!isset($bigbluebuttonbn->presentation) || $bigbluebuttonbn->presentation == '') {
return '';
}
$context = context_module::instance($bigbluebuttonbn->coursemodule);
// Set the filestorage object.
$fs = get_file_storage();
// Save the file if it exists that is currently in the draft area.
file_save_draft_area_files($bigbluebuttonbn->presentation, $context->id, 'mod_bigbluebuttonbn', 'presentation', 0);
// Get the file if it exists.
$files = $fs->get_area_files(
$context->id,
'mod_bigbluebuttonbn',
'presentation',
0,
'itemid, filepath, filename',
false
);
// Check that there is a file to process.
$filesrc = '';
if (count($files) == 1) {
// Get the first (and only) file.
$file = reset($files);
$filesrc = '/'.$file->get_filename();
}
return $filesrc;
}
/**
* Serves the bigbluebuttonbn attachments. Implements needed access control ;-).
*
* @category files
*
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
*
* @return false|null false if file not found, does not return if found - justsend the file
*/
function bigbluebuttonbn_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if (!bigbluebuttonbn_pluginfile_valid($context, $filearea)) {
return false;
}
$file = bigbluebuttonbn_pluginfile_file($course, $cm, $context, $filearea, $args);
if (empty($file)) {
return false;
}
// Finally send the file.
send_stored_file($file, 0, 0, $forcedownload, $options); // download MUST be forced - security!
}
/**
* Helper for validating pluginfile.
* @param stdClass $context context object
* @param string $filearea file area
*
* @return false|null false if file not valid
*/
function bigbluebuttonbn_pluginfile_valid($context, $filearea) {
// Can be in context module or in context_system (if is the presentation by default).
if (!in_array($context->contextlevel, array(CONTEXT_MODULE, CONTEXT_SYSTEM))) {
return false;
}
if (!array_key_exists($filearea, bigbluebuttonbn_get_file_areas())) {
return false;
}
return true;
}
/**
* Helper for getting pluginfile.
*
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param string $filearea file area
* @param array $args extra arguments
*
* @return object
*/
function bigbluebuttonbn_pluginfile_file($course, $cm, $context, $filearea, $args) {
$filename = bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args);
if (!$filename) {
return false;
}
$fullpath = "/$context->id/mod_bigbluebuttonbn/$filearea/0/".$filename;
$fs = get_file_storage();
$file = $fs->get_file_by_hash(sha1($fullpath));
if (!$file || $file->is_directory()) {
return false;
}
return $file;
}
/**
* Helper for give access to the file configured in setting as default presentation.
*
* @param stdClass $course course object
* @param stdClass $cm course module object
* @param stdClass $context context object
* @param array $args extra arguments
*
* @return array
*/
function bigbluebuttonbn_default_presentation_get_file($course, $cm, $context, $args) {
// The difference with the standard bigbluebuttonbn_pluginfile_filename() are.
// - Context is system, so we don't need to check the cmid in this case.
// - The area is "presentationdefault_cache".
if (count($args) > 1) {
$cache = cache::make_from_params(
cache_store::MODE_APPLICATION,
'mod_bigbluebuttonbn',
'presentationdefault_cache'
);
$noncekey = sha1($context->id);
$presentationnonce = $cache->get($noncekey);
$noncevalue = $presentationnonce['value'];
$noncecounter = $presentationnonce['counter'];
if ($args['0'] != $noncevalue) {
return;
}
// The nonce value is actually used twice because BigBlueButton reads the file two times.
$noncecounter += 1;
$cache->set($noncekey, array('value' => $noncevalue, 'counter' => $noncecounter));
if ($noncecounter == 2) {
$cache->delete($noncekey);
}
return($args['1']);
}
require_course_login($course, true, $cm);
if (!has_capability('mod/bigbluebuttonbn:join', $context)) {