-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
2016 lines (1692 loc) · 77.2 KB
/
Copy pathlib.php
File metadata and controls
2016 lines (1692 loc) · 77.2 KB
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/>.
/**
* kalpanmaps lib.
*
* Class for building scheduled task functions
* for fixing core and third party issues
*
* @package local_kalpanmaps
* @copyright 2021 onwards LSUOnline & Continuing Education
* @copyright 2021 onwards Robert Russo
*/
defined('MOODLE_INTERNAL') or die();
// Building the class for the task to be run during scheduled tasks.
class kalpanmaps {
public $emaillog;
/**
* Master function for moving kaltura video resources to urls.
*
* For every kalvidres, the following will be created:
* A new url in the same course section.
* A link to the corresponding panopto video.
*
* @return boolean
*/
public function run_convert_kalvidres() {
global $CFG, $DB;
// Set up verbose logging preference.
$verbose = $CFG->local_kalpanmaps_verbose;
// Let's be sure the table exists before we do anything.
$tableexists = ($DB->get_manager()->table_exists('local_kalpanmaps'));
// We need this for controlling item visibility.
if (!function_exists('set_coursemodule_visible')) {
require_once($CFG->dirroot . "/course/lib.php");
}
// SQL to grab remaining kaltura items to convert.
$kpsql = 'SELECT kr.id AS krid,
km.kaltura_id AS "kalturaid",
km.panopto_id AS "panoptoid",
kr.course AS "courseid",
km.id AS kmid,
kr.name AS "itemname",
kr.video_title AS "videotitle",
kr.intro AS "intro",
kr.height AS "itemheight",
kr.width AS "itemwidth",
cm.id AS cmid,
cm.visible AS "modvis",
cm.groupmode AS "groupmode",
cm.groupingid AS "groupingid",
cs.section AS "coursesection"
FROM {local_kalpanmaps} km
INNER JOIN {kalvidres} kr ON km.kaltura_id = kr.entry_id
INNER JOIN {course_modules} cm ON cm.course = kr.course AND cm.instance = kr.id
INNER JOIN {modules} m ON m.name = "kalvidres" AND cm.module = m.id
INNER JOIN {course_sections} cs ON cs.course = kr.course AND cs.id = cm.section
LEFT JOIN {url} u ON kr.course = u.course
AND kr.name = u.name
AND u.externalurl LIKE CONCAT("%", km.panopto_id , "%")
WHERE u.id IS NULL
GROUP BY kr.id, kr.course';
// SQL to grab visible previously converted kaltura video resources for future hiding.
$donesql = 'SELECT cm.id AS cmid
FROM {local_kalpanmaps} km
INNER JOIN {kalvidres} kr ON km.kaltura_id = kr.entry_id
INNER JOIN {course_modules} cm ON cm.course = kr.course AND cm.instance = kr.id
INNER JOIN {modules} m ON m.name = "kalvidres" AND cm.module = m.id
INNER JOIN {url} u ON kr.course = u.course
AND kr.name = u.name
AND u.externalurl LIKE CONCAT("%", km.panopto_id , "%")
WHERE cm.visible = 1
GROUP BY cm.id';
// If the table exists, use a standard moodle function to get records from the above SQL.
$kpdata = $tableexists ? $DB->get_records_sql($kpsql) : null;
// Set the start time so we can log how long this takes.
$starttime = microtime(true);
// Start feeding data into the logger.
$this->log("Beginning the process of converting Kaltura Video Resources to Panopto urls.");
// Set up some counts.
$converted = 0;
$hidden = 0;
// Don't do anything if we don't have any items to work with.
if ($kpdata) {
$this->log(" Converting Kaltura Video Resource to Panoptp url.");
// Loops through and actually does the conversions.
foreach ($kpdata as $kalturaitem) {
// Increment the converted count.
$converted++;
// Log stuff depending on the verbosity preferences.
if ($verbose) {
$this->log(" Converting Kaltura itemid: " . $kalturaitem->kalturaid . ".");
$this->log(" Ceating new url for Kaltura itemid: " . $kalturaitem->kalturaid . ".");
} else {
$eol = ($converted % 50) == 0 ? PHP_EOL : " ";
if ($eol == PHP_EOL) {
mtrace("Created " . $converted . " entries.", $eol);
} else {
mtrace(".", $eol);
}
}
// We have not yet converted all kaltura items in this course, convert the next one.
self::build_url($kalturaitem);
// Hide the corresponding kalura item if configured to do so and it's not already hidden.
if ($kalturaitem->modvis == 1 && $CFG->local_kalpanmaps_kalvidres_conv_hide == 1) {
// Actually hide the item.
set_coursemodule_visible($kalturaitem->cmid, 0, $visibleoncoursepage = 1);
// Increment the hidden count.
$hidden++;
if ($verbose) {
$this->log(" Hiding old kaltura item: " . $kalturaitem->kalturaid .
" with already existing url in courseid: " . $kalturaitem->courseid . ".");
}
}
if ($verbose) {
$this->log(" Finished creating the new url with panopto id: " .
$kalturaitem->panoptoid . " and hiding the old kaltura item with id: " .
$kalturaitem->krid . ".");
$this->log(" Panopto url itemid: " . $kalturaitem->panoptoid . " has been created.");
}
}
// We're done with conversions.
$this->log("\n Completed converting Kaltura Video Resource items to Panopto urls.");
$this->log("Finished converting outstanding Kaltura Video Resources to panopto urls.");
// How long in seconds did this conversion job take.
$elapsedtime = round(microtime(true) - $starttime, 3);
$this->log("The process to convert Kaltura Video Resources to Panopto urls took " .
$elapsedtime . " seconds.");
} else {
// We did not have anything to do.
$this->log("No outstanding Kaltura Video Resources.");
}
// Grab an array of objects with previously converted kaltura item's courseids.
$dones = $DB->get_records_sql($donesql);
// If we're hiding previously converted kalvidres, let's do it.
if ($CFG->local_kalpanmaps_kalvidres_postconv_hide == 1 && $dones) {
// Loop through the converted visible items.
foreach ($dones as $done) {
// Hide them.
set_coursemodule_visible($done->cmid, 0, $visibleoncoursepage = 1);
// Increment the hidden value for our count later.
$hidden++;
}
}
// Get some counts in the logs depending if we hide KalVidRes items or not.
if (($CFG->local_kalpanmaps_kalvidres_conv_hide == 1
|| $CFG->local_kalpanmaps_kalvidres_postconv_hide == 1)
&& ($hidden - $converted > 0)) {
$this->log("Converted " . $converted . " KalVidRes items and hid " . $hidden . " KalVidRes items.");
} else if ($CFG->local_kalpanmaps_kalvidres_conv_hide == 1) {
$this->log("Converted " . $converted . " Kaltura Video Resources and hid them.");
} else {
$this->log("Converted " . $converted . " Kaltura Video Resources.");
}
// Send an email to administrators regarding this.
if ($converted + $hidden > 0) {
$this->email_clog_report_to_admins();
}
}
/**
* Function for building the cm for the new url.
*
* For every url created, a new course module
* will be built here.
*
* @return $newcm
*/
public static function build_course_module($kalturaitem) {
global $DB;
// Gets the course object from the courseid.
$course = get_course($kalturaitem->courseid);
// Get the id for the url module.
$moduleid = $DB->get_field('modules', 'id', array('name' => 'url'));
// Build the course module info.
$newcm = new stdClass;
$newcm->course = $course->id;
$newcm->module = $moduleid;
$newcm->instance = 0;
$newcm->section = 0;
$newcm->idnumber = '';
$newcm->visible = $kalturaitem->modvis;
$newcm->visibleoncoursepage = $kalturaitem->modvis;
$newcm->visibleold = $kalturaitem->modvis;
$newcm->groupmode = $kalturaitem->groupmode;
$newcm->groupmembersonly = 0;
$newcm->groupingid = $kalturaitem->groupingid;
$newcm->completion = 0;
$newcm->completionview = 0;
$newcm->completionexpected = 0;
$newcm->showdescription = 0;
$newcm->availability = null;
// Build the course module itself.
$newcm->id = self::add_cm($newcm);
return $newcm;
}
/**
* Function for adding the cm to moodle for the new url.
*
* For every url created, a new course module
* will be added here.
*
* @return $cmid
*/
public static function add_cm($newcm) {
global $DB;
// Set the time for the new course module.
$newcm->added = time();
// Make sure we have no preconceptions about a cmid.
unset($newcm->id);
// Add the record and set / store the id.
$cmid = $DB->insert_record("course_modules", $newcm);
// Rebuild the course cache.
rebuild_course_cache($newcm->course, true);
return $cmid;
}
/**
* Function for building and adding the new url to moodle.
*
* @return $module
*/
public static function build_url($kalturaitem) {
global $CFG, $DB;
// Prerequisites.
if (!function_exists('url_add_instance')) {
require_once($CFG->dirroot . '/mod/url/lib.php');
}
if (!function_exists('set_coursemodule_visible')) {
require_once($CFG->dirroot . "/course/lib.php");
}
// Set some variables up for later.
$panoptourl = get_config('block_panopto', 'server_name1');
$config = get_config('url');
$parms = '" width="' . $kalturaitem->itemwidth . '" height="' . $kalturaitem->itemheight . '"';
$link = '/Panopto/Pages/Viewer.aspx?id=';
// Build the course module and set the cmid.
$cm = self::build_course_module($kalturaitem);
// Build the module here.
$module = new stdClass;
$module->course = $kalturaitem->courseid;
$module->name = $kalturaitem->itemname;
$module->intro = '<p>' . $kalturaitem->videotitle . '</p>' . $kalturaitem->intro;
$module->externalurl = 'https://' . $panoptourl . $link . $kalturaitem->panoptoid;
$module->introformat = FORMAT_HTML;
$module->coursemodule = $cm->id;
$module->section = $kalturaitem->coursesection;
$module->display = $config->display;
$module->popupwidth = $config->popupwidth;
$module->popupheight = $config->popupheight;
$module->printintro = $config->printintro;
// Build the url and set the url id.
$module->id = url_add_instance($module, null);
// Now that we have the url, we can finish setting up the cm.
$cm->instance = $module->id;
// Add the course module to a specific section matching the old kalvidres.
$cm->section = course_add_cm_to_section($module->course, $module->coursemodule, $module->section, $kalturaitem->cmid);
// Update the cm.
$DB->update_record('course_modules', $cm);
return $module;
}
/**
* Master function for moving kaltura video iframes and links to panotpo.
*
* For every kaltura embed in the DB
* A new panopto iframe or link will be created
* To replace the existing kaltura iframe or link
* In the same resource or activity.
*
* @return boolean $success
*/
public function run_convert_kalembeds() {
global $CFG, $DB;
// Set up verbose logging preference.
$verbose = $CFG->local_kalpanmaps_verbose;
// Start the log.
if ($verbose) {
mtrace("We are in verbose mode and have begun converting kaltura embeds.");
} else {
mtrace("Converting kaltura iframe embeds.");
}
// Let's be sure the table exists before we do anything.
$tableexists = ($DB->get_manager()->table_exists('local_kalpanmaps'));
// If the table exists, convert any outstanding embeds.
$success = $tableexists ? self::conv_panitems($verbose) : false;
// Log out what happened.
if ($success) {
mtrace("Successfully converted all remaining kaltura embeds.");
} else {
mtrace("The process has completed. Any errors would be listed above.");
}
return $success;
}
/**
* Function for checking if the tool is supported in for a given course category.
*
* @return @bool
*/
public static function is_supported($cid) {
global $CFG;
// Get the course object from the id.
$course = get_course($cid);
// Check to see if this course is in a supported category.
$enabled = $CFG->local_kalpanmaps_categorylimit;
$ccats = $CFG->local_kalpanmaps_cats;
$cats = explode(',', $ccats);
$is_cat = ($enabled == 1 ? (empty($cats) or in_array($course->category, $cats)) : true);
// Return true or not based on above.
return ($is_cat);
}
/**
* Function for grabbing label data where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_label($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT l.id AS id,
l.course AS courseid,
l.intro AS itemdata,
"label" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_label l
INNER JOIN mdl_course c ON c.id = l.course
WHERE (l.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR l.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR l.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing page data where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_page_content($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT p.id AS id,
p.course AS courseid,
p.content AS itemdata,
"page" AS tble,
"content" AS dataitem,
"faculty" AS usertype
FROM mdl_page p
INNER JOIN mdl_course c ON c.id = p.course
WHERE (p.content LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR p.content LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR p.content LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing page intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_page_intro($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT p.id AS id,
p.course AS courseid,
p.intro AS itemdata,
"page" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_page p
INNER JOIN mdl_course c ON c.id = p.course
WHERE (p.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR p.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR p.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing assignment intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_assign($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT a.id AS id,
a.course AS courseid,
a.intro AS itemdata,
"assign" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_assign a
INNER JOIN mdl_course c ON c.id = a.course
WHERE (a.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR a.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR a.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing assignment submissions where kaltura filter links are present.
*
* @return array $kalitems
*/
public static function get_kal_assignsubmission_onlinetext($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT aso.id AS id,
a.course AS courseid,
aso.onlinetext AS itemdata,
"assignsubmission_onlinetext" AS tble,
"onlinetext" AS dataitem,
"student" AS usertype
FROM mdl_assignsubmission_onlinetext aso
INNER JOIN mdl_assign a ON a.id = aso.assignment
INNER JOIN mdl_course c ON c.id = a.course
WHERE aso.onlinetext LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing course sections where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_course_sections($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT cs.id AS id,
cs.course AS courseid,
cs.summary AS itemdata,
"course_sections" AS tble,
"summary" AS dataitem,
"faculty" AS usertype
FROM mdl_course_sections cs
INNER JOIN mdl_course c ON c.id = cs.course
WHERE (cs.summary LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR cs.summary LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR cs.summary LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing quiz intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_quiz($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT q.id AS id,
q.course AS courseid,
q.intro AS itemdata,
"quiz" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_quiz q
INNER JOIN mdl_course c ON c.id = q.course
WHERE (q.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR q.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR q.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing book intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_book($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT b.id AS id,
b.course AS courseid,
b.intro AS itemdata,
"book" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_book b
INNER JOIN mdl_course c ON c.id = b.course
WHERE (b.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR b.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR b.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing book chapter content where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_book_chapters($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT bc.id AS id,
b.course AS courseid,
bc.content AS itemdata,
"book_chapters" AS tble,
"content" AS dataitem,
"faculty" AS usertype
FROM mdl_book_chapters bc
INNER JOIN mdl_book b ON b.id = bc.bookid
INNER JOIN mdl_course c ON c.id = b.course
WHERE (bc.content LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR bc.content LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR bc.content LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing forum intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_forum($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT f.id AS id,
f.course AS courseid,
f.intro AS itemdata,
"forum" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_forum f
INNER JOIN mdl_course c ON c.id = f.course
WHERE (f.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR f.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR f.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing forum posts where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_forum_posts($limit = 0, $students) {
global $DB;
// Set these up if we are NOT converting studen submissions.
$usertype = $students == 0 ? '"faculty" AS usertype' : '"student" AS usertype';
$joins = $students == 0 ? 'INNER JOIN mdl_context ctx ON f.course = ctx.instanceid
AND ctx.contextlevel = 50
INNER JOIN mdl_role_assignments mra ON mra.contextid = ctx.id
AND fp.userid = mra.userid' : '';
$wheres = $students == 0 ? 'AND mra.roleid NOT IN (' . $CFG->gradebookroles . ')' : '';
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT fp.id AS id,
f.course AS courseid,
fp.message AS itemdata,
"forum_posts" AS tble,
"message" AS dataitem,
' . $usertype . '
FROM mdl_forum_posts fp
INNER JOIN mdl_forum_discussions fd ON fd.id = fp.discussion
INNER JOIN mdl_forum f ON f.id = fd.forum
INNER JOIN mdl_course c ON c.id = f.course
' . $joins . '
WHERE fp.message LIKE "%browseandembed/index/media/entryid/%"
' . $wheres;
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing lesson intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_lesson($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT l.id AS id,
l.course AS courseid,
l.intro AS itemdata,
"lesson" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_lesson l
INNER JOIN mdl_course c ON c.id = l.course
WHERE (l.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR l.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR l.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing lesson page contents where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_lesson_pages($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT lp.id AS id,
l.course AS courseid,
lp.contents AS itemdata,
"lesson_pages" AS tble,
"contents" AS dataitem,
"faculty" AS usertype
FROM mdl_lesson_pages lp
INNER JOIN mdl_lesson l ON l.id = lp.lessonid
INNER JOIN mdl_course c ON c.id = l.course
WHERE (lp.contents LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR lp.contents LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR lp.contents LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing lesson answers where kaltura links are present.
*
* @return array $kalitems
*/
public static function get_kal_lesson_attempts($limit = 0) {
global $DB;
// Set these up if we are NOT converting studen submissions.
$usertype = '"student" AS usertype';
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT la.id AS id,
l.course AS courseid,
la.useranswer AS itemdata,
"lesson_attempts" AS tble,
"useranswer" AS dataitem,
' . $usertype . '
FROM mdl_lesson_attempts la
INNER JOIN mdl_lesson l ON l.id = la.lessonid
INNER JOIN mdl_course c ON c.id = l.course
WHERE la.useranswer LIKE "%browseandembed/index/media/entryid/%"';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing lesson answers where kaltura links are present.
*
* @return array $kalitems
*/
public static function get_kal_lesson_answers($limit = 0) {
global $DB;
// Set these up if we are NOT converting studen submissions.
$usertype = '"faculty" AS usertype';
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT la.id AS id,
l.course AS courseid,
la.answer AS itemdata,
"lesson_answer" AS tble,
"answer" AS dataitem,
' . $usertype . '
FROM mdl_lesson_answers la
INNER JOIN mdl_lesson l ON l.id = la.lessonid
INNER JOIN mdl_course c ON c.id = l.course
WHERE la.answer LIKE "%browseandembed/index/media/entryid/%"';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing journal intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_journal($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT j.id AS id,
j.course AS courseid,
j.intro AS itemdata,
"journal" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_journal j
INNER JOIN mdl_course c ON c.id = j.course
WHERE (j.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR j.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR j.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing journal entries where kaltura filtered links are present.
*
* @return array $kalitems
*/
public static function get_kal_journal_entries($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT je.id AS id,
j.course AS courseid,
je.text AS itemdata,
"journal_entries" AS tble,
"text" AS dataitem,
"student" AS usertype
FROM mdl_journal j
INNER JOIN mdl_journal_entries je ON je.journal = j.id
INNER JOIN mdl_course c ON c.id = j.course
WHERE je.text LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing choice intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_choice($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT c.id AS id,
c.course AS courseid,
c.intro AS itemdata,
"choice" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_choice c
INNER JOIN mdl_course cou ON cou.id = c.course
WHERE (c.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR c.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR c.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing feedback intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_feedback($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT f.id AS id,
f.course AS courseid,
f.intro AS itemdata,
"feedback" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_feedback f
INNER JOIN mdl_course c ON c.id = f.course
WHERE (f.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR f.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR f.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing glossary intros where kaltura iframes are present.
*
* @return array $kalitems
*/
public static function get_kal_glossary($limit = 0) {
global $DB;
// Build the SQL to grab items that have kaltura iframes in them.
$gksql = 'SELECT g.id AS id,
g.course AS courseid,
g.intro AS itemdata,
"glossary" AS tble,
"intro" AS dataitem,
"faculty" AS usertype
FROM mdl_glossary g
INNER JOIN mdl_course c ON c.id = g.course
WHERE (g.intro LIKE "%<iframe id=\"kaltura_player\" src=\"%"
OR g.intro LIKE "%<a href=\"%/browseandembed/index/media/entryid/%"
OR g.intro LIKE "%<iframe src=\"https://www.kaltura.com%")';
// Build the array of objects.
$kalitems = array();
$kalitems = $DB->get_records_sql($gksql, array(null, $limitfrom = 0, $limit));
// Return the array of objects.
return $kalitems;
}
/**
* Function for grabbing glosarry entries where kaltura items are present.
*
* @return array $kalitems
*/
public static function get_kal_glossary_entries($limit = 0, $students) {