forked from intelliboard/intelliboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
externallib.php
executable file
·7339 lines (6588 loc) · 348 KB
/
externallib.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/>.
/**
* This plugin provides access to Moodle data in form of analytics and reports in real time.
*
*
* @package local_intelliboard
* @copyright 2017 IntelliBoard, Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @website https://intelliboard.net/
*/
require_once($CFG->libdir . "/externallib.php");
class local_intelliboard_external extends external_api {
public $params = array();
public $prfx = 0;
/**
* Returns description of method parameters
* @return external_function_parameters
*/
public static function database_query_parameters() {
return new external_function_parameters(
array('params' => new external_multiple_structure(
new external_single_structure(
array(
'function' => new external_value(PARAM_ALPHANUMEXT, 'Main Function name', VALUE_REQUIRED),
'timestart' => new external_value(PARAM_INT, 'Time start param', VALUE_OPTIONAL, 0),
'timefinish' => new external_value(PARAM_INT, 'Time finish param', VALUE_OPTIONAL, 0),
'start' => new external_value(PARAM_INT, 'Pagination start', VALUE_OPTIONAL, 0),
'length' => new external_value(PARAM_INT, 'Pagination length', VALUE_OPTIONAL, 0),
'columns' => new external_value(PARAM_SEQUENCE, 'Profile columns', VALUE_OPTIONAL, 0),
'filter_columns' => new external_value(PARAM_SEQUENCE, 'Filter columns param', VALUE_OPTIONAL, 0),
'filter_profile' => new external_value(PARAM_INT, 'Filter profile column param', VALUE_OPTIONAL, 0),
'order_column' => new external_value(PARAM_INT, 'Order column param', VALUE_OPTIONAL, 0),
'order_dir' => new external_value(PARAM_ALPHA, 'Order direction param', VALUE_OPTIONAL, ''),
'filter' => new external_value(PARAM_RAW, 'Filter var', VALUE_OPTIONAL, ''),
'custom' => new external_value(PARAM_RAW, 'Custom var', VALUE_OPTIONAL, ''),
'custom2' => new external_value(PARAM_RAW, 'Custom2 var', VALUE_OPTIONAL, ''),
'custom3' => new external_value(PARAM_RAW, 'Custom3 var', VALUE_OPTIONAL, ''),
'notification_enrol' => new external_value(PARAM_RAW, 'Notification enrol', VALUE_OPTIONAL, ''),
'notification_auth' => new external_value(PARAM_RAW, 'Notification auth', VALUE_OPTIONAL, ''),
'notification_email' => new external_value(PARAM_RAW, 'Notification email', VALUE_OPTIONAL, ''),
'notification_subject' => new external_value(PARAM_RAW, 'Notification subject', VALUE_OPTIONAL, ''),
'notification_message' => new external_value(PARAM_RAW, 'Notification message', VALUE_OPTIONAL, ''),
'teacher_roles' => new external_value(PARAM_SEQUENCE, 'Teacher roles', VALUE_OPTIONAL, 0),
'learner_roles' => new external_value(PARAM_SEQUENCE, 'Learner roles', VALUE_OPTIONAL, 0),
'users' => new external_value(PARAM_SEQUENCE, 'Users SEQUENCE', VALUE_OPTIONAL, 0),
'userid' => new external_value(PARAM_INT, 'Instuctor ID', VALUE_OPTIONAL, 0),
'sizemode' => new external_value(PARAM_INT, 'Size mode', VALUE_OPTIONAL, 0),
'debug' => new external_value(PARAM_INT, 'Debug mode', VALUE_OPTIONAL, 0),
'courseid' => new external_value(PARAM_SEQUENCE, 'Course IDs SEQUENCE', VALUE_OPTIONAL, 0),
'cohortid' => new external_value(PARAM_SEQUENCE, 'Cohort IDs SEQUENCE', VALUE_OPTIONAL, 0),
'filter_user_deleted' => new external_value(PARAM_INT, 'filter_user_deleted', VALUE_OPTIONAL, 0),
'filter_user_suspended' => new external_value(PARAM_INT, 'filter_user_suspended', VALUE_OPTIONAL, 0),
'filter_user_guest' => new external_value(PARAM_INT, 'filter_user_guest', VALUE_OPTIONAL, 0),
'filter_course_visible' => new external_value(PARAM_INT, 'filter_course_visible', VALUE_OPTIONAL, 0),
'filter_enrolmethod_status' => new external_value(PARAM_INT, 'filter_enrolmethod_status', VALUE_OPTIONAL, 0),
'filter_enrol_status' => new external_value(PARAM_INT, 'filter_enrol_status', VALUE_OPTIONAL, 0),
'filter_enrolled_users' => new external_value(PARAM_INT, 'filter_enrolled_users', VALUE_OPTIONAL, 0),
'filter_module_visible' => new external_value(PARAM_INT, 'filter_module_visible', VALUE_OPTIONAL, 0),
'scales' => new external_value(PARAM_INT, 'custom scales', VALUE_OPTIONAL, 0),
'scale_raw' => new external_value(PARAM_INT, 'custom scale_raw', VALUE_OPTIONAL, 0),
'scale_total' => new external_value(PARAM_FLOAT, 'custom scale_total', VALUE_OPTIONAL, 0),
'scale_value' => new external_value(PARAM_FLOAT, 'custom scale_value', VALUE_OPTIONAL, 0),
'scale_percentage' => new external_value(PARAM_INT, 'custom scale_percentage', VALUE_OPTIONAL, 0)
)
)
)
)
);
}
public static function database_query($params) {
global $CFG, $DB;
require_once($CFG->dirroot .'/local/intelliboard/locallib.php');
$params = self::validate_parameters(self::database_query_parameters(), array('params' => $params));
self::validate_context(context_system::instance());
$transaction = $DB->start_delegated_transaction();
$obj = new local_intelliboard_external();
$params = (object)reset($params['params']);
$params->userid = isset($params->userid) ? $params->userid : 0;
$params->courseid = isset($params->courseid) ? $params->courseid : 0;
$params->cohortid = isset($params->cohortid) ? $params->cohortid : 0;
$params->users = isset($params->users) ? $params->users : 0;
$params->start = isset($params->start) ? $params->start : 0;
$params->length = isset($params->length) ? $params->length : 50;
$params->filter = isset($params->filter) ? clean_raw($params->filter) : '';
$params->custom = isset($params->custom) ? clean_raw($params->custom, false) : '';
$params->custom2 = isset($params->custom2) ? clean_raw($params->custom2) : '';
$params->custom3 = isset($params->custom3) ? clean_raw($params->custom3) : '';
$params->columns = isset($params->columns) ? $params->columns : '';
$params->filter_columns = (isset($params->filter_columns)) ? $params->filter_columns : "0,1";
$params->filter_profile = (isset($params->filter_profile)) ? $params->filter_profile : 0;
$params->timestart = (isset($params->timestart)) ? $params->timestart : 0;
$params->timefinish = (isset($params->timefinish)) ? $params->timefinish : 0;
$params->sizemode = (isset($params->sizemode)) ? $params->sizemode : 0;
$params->debug = (isset($params->debug)) ? $params->debug : 0;
$params->filter_user_deleted = (isset($params->filter_user_deleted)) ? $params->filter_user_deleted : 0;
$params->filter_user_suspended = (isset($params->filter_user_suspended)) ? $params->filter_user_suspended : 0;
$params->filter_user_guest = (isset($params->filter_user_guest)) ? $params->filter_user_guest : 0;
$params->filter_course_visible = (isset($params->filter_course_visible)) ? $params->filter_course_visible : 0;
$params->filter_enrolmethod_status = (isset($params->filter_enrolmethod_status)) ? $params->filter_enrolmethod_status : 0;
$params->filter_enrol_status = (isset($params->filter_enrol_status)) ? $params->filter_enrol_status : 0;
$params->filter_enrolled_users = (isset($params->filter_enrolled_users)) ? $params->filter_enrolled_users : 0;
$params->filter_module_visible = (isset($params->filter_module_visible)) ? $params->filter_module_visible : 0;
$params->teacher_roles = (isset($params->teacher_roles) and $params->teacher_roles) ? $params->teacher_roles : 3;
$params->learner_roles = (isset($params->learner_roles) and $params->learner_roles) ? $params->learner_roles : 5;
$params->notification_enrol = isset($params->notification_enrol) ? clean_raw($params->notification_enrol, false) : '';
$params->notification_auth = isset($params->notification_auth) ? clean_raw($params->notification_auth, false) : '';
$params->notification_email = isset($params->notification_email) ? clean_raw($params->notification_email, false) : '';
$params->notification_subject = isset($params->notification_subject) ? clean_raw($params->notification_subject, false) : '';
$params->notification_message = isset($params->notification_message) ? clean_raw($params->notification_message, false) : '';
$params->scales = (isset($params->scales)) ? $params->scales : 0;
$params->scale_raw = (isset($params->scale_raw)) ? $params->scale_raw : 0;
$params->scale_total = (isset($params->scale_total)) ? $params->scale_total : 0;
$params->scale_value = (isset($params->scale_value)) ? $params->scale_value : 0;
$params->scale_percentage = (isset($params->scale_percentage)) ? $params->scale_percentage : 0;
if($params->debug){
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
}
//Available functions
$functions = array('report1','report2','report3','report4','report5','report6','report7','report8','report9','report10','report11','report12','report13','report14','report15','report16','report17','report18','report18_graph','report19','report20','report21','report22','report23','report24','report25','report26','report27','report28','report29','report30','report31','report32','get_scormattempts','get_competency','get_competency_templates','report33','report34','report35','report36','report37','report38','report39','report40','report41','report43','report44','report45','report42','report46','report47','report58','report66','report72','report73','report75','report76','report77','report79','report80','report81','report82','report83','report84','report85','report86','report87','report88','report89','report90','report91','report92','report93','report94','report95','report96','report97','report98','report99','report99_graph','report100','report101','report102','report103','report104','report105','report106','report107','report108','report109','get_course_modules','report78','report74','report71','report70','report67','report68','report69','get_max_attempts','report56','analytic1','analytic2','get_quizes','analytic3','analytic4','analytic5','analytic5table','analytic6','analytic7','analytic7table','analytic8','analytic8details','get_course_instructors','get_course_discussions','get_cohort_users','get_users','get_grade_letters','get_questions','get_activity','get_total_info','get_system_users','get_system_courses','get_system_load','get_module_visits','get_useragents','get_useros','get_userlang','get_module_timespend','get_users_count','get_most_visited_courses','get_no_visited_courses','get_active_users','get_enrollments_per_course','get_size_courses','get_active_ip_users','get_active_courses_per_day','get_unique_sessions','get_new_courses_per_day','get_users_per_day','get_active_users_per_day','get_countries','get_cohorts','get_elisuset','get_totara_pos','get_scorm_user_attempts','get_course_users','get_info','get_courses','get_modules','get_outcomes','get_roles','get_roles_fix_name','get_tutors','get_cminfo','get_enrols','get_teacher_sql','get_learner','get_learners','get_learner_courses','get_course','get_activity_learners','get_learner_visits_per_day','get_course_visits_per_day','get_userinfo','get_user_info_fields_data','get_user_info_fields','get_reportcard','get_dashboard_avg','get_dashboard_countries','get_dashboard_enrols','get_dashboard_info','get_dashboard_stats','set_notification_enrol','set_notification_auth','count_records','parseFeedbackAnswer','analytic9','get_course_sections','get_course_user_groups','get_all_system_info','get_course_assignments','get_data_question_answers','get_course_databases','get_databases_question');
$function = (isset($params->function)) ? $params->function : '';
if(in_array($function, $functions)){
$data = $obj->{$function}($params);
}else{
$data = null;
}
$transaction->allow_commit();
return json_encode($data);
}
/**
* Returns description of method result value
* @return external_description
*/
public static function database_query_returns() {
return new external_value(PARAM_RAW, 'Moodle DB records');
}
private function get_limit_sql($params)
{
return (isset($params->start) and $params->length != 0 and $params->length != -1) ? "LIMIT $params->start, $params->length" : "";
}
private function get_order_sql($params, $columns)
{
return (isset($params->order_column) and isset($columns[$params->order_column]) and $params->order_dir) ? "ORDER BY ".$columns[$params->order_column]." $params->order_dir" : "";
}
private function get_filter_course_sql($params, $prefix)
{
return ($params->filter_course_visible) ? "" : " AND {$prefix}visible = 1";
}
private function get_filter_enrol_sql($params, $prefix)
{
return ($params->filter_enrol_status) ? "" : " AND {$prefix}status = 0";
}
private function get_filter_enrolled_users_sql($params, $column)
{
$sql = $this->get_filter_course_sql($params, 'c.');
$sql .= $this->get_filter_enrol_sql($params, 'e.');
$sql .= $this->get_filter_enrol_sql($params, 'ue.');
return ($params->filter_enrolled_users) ? " AND {$column} IN (SELECT DISTINCT userid FROM {user_enrolments} ue, {enrol} e, {course} c WHERE ue.enrolid = e.id AND c.id = e.courseid $sql)" : "";
}
private function get_filter_module_sql($params, $prefix)
{
return ($params->filter_module_visible) ? "" : " AND {$prefix}visible = 1";
}
private function get_filter_user_sql($params, $prefix)
{
$filter = ($params->filter_user_deleted) ? "" : " AND {$prefix}deleted = 0";
$filter .= ($params->filter_user_suspended) ? "" : " AND {$prefix}suspended = 0";
$filter .= ($params->filter_user_guest) ? "" : " AND {$prefix}username <> 'guest'";
return $filter;
}
private function get_filter_columns($params)
{
if(!empty($params->columns)){
$data = array();
$columns = explode(",", $params->columns);
foreach($columns as $column){
$data[] = "field$column"; // {$column} defined in each report
}
return $data;
}else{
return array();
}
}
private function get_columns($params, $field = "u.id")
{
if(!empty($params->columns)){
$data = "";
$columns = explode(",", $params->columns);
foreach($columns as $column){
$key = "column$column";
$this->params[$key] = $column;
$data .= ", (SELECT d.data FROM {user_info_data} d, {user_info_field} f WHERE f.id = :$key AND d.fieldid = f.id AND d.userid = $field) AS field$column";
}
return $data;
}else{
return "";
}
}
private function get_filter_sql($params, $columns)
{
global $DB;
$filter = "";
//Filter by report columns
if($params->filter and !empty($columns)){
$sql_arr = array(); $filter_columns = explode(",", $params->filter_columns);
foreach($columns as $i => $column){
if($column and in_array($i, $filter_columns)){
$this->prfx = $this->prfx + 1;
$key = clean_param($column, PARAM_ALPHANUMEXT).$this->prfx;
$sql_arr[] = $DB->sql_like($column, ":$key", false, false);
$this->params[$key] = "%$params->filter%";
}
}
$filter .= ($sql_arr) ? implode(" OR ", $sql_arr) : "";
}
//Filter by User profile fields
if($params->filter_profile){
$params->custom3 = clean_param($params->custom3, PARAM_SEQUENCE);
if($params->custom3 and !empty($params->columns)){
$cols = explode(",", $params->columns);
$fields = $DB->get_records_sql("SELECT id, fieldid, data FROM {user_info_data} WHERE id IN ($params->custom3)");
$fields_filter = array();
foreach($fields as $i => $field){
if(in_array($field->fieldid, $cols)){
$field->fieldid = (int)$field->fieldid; //fieldid -> int
$key = "field$field->fieldid";
$unickey = "field{$field->fieldid}_{$i}";
$fields_filter[] = $DB->sql_like($key, ":$unickey", false, false);
$this->params[$unickey] = "%$field->data%";
}
}
$filter = ($fields_filter and $filter) ? "($filter) AND " : $filter;
$filter .= ($fields_filter) ? " (" . implode(" OR ", $fields_filter) .") " : "";
}
}
return ($filter) ? " HAVING " . $filter : "";
}
private function get_filterdate_sql($params, $column)
{
if($params->timestart and $params->timefinish){
$this->prfx = $this->prfx + 1;
$timestart = 'tmstart'.$this->prfx;
$timefinish = 'tmfinish'.$this->prfx;
$this->params[$timestart] = $params->timestart;
$this->params[$timefinish] = $params->timefinish;
return " AND $column BETWEEN :$timestart AND :$timefinish ";
}
return "";
}
private function get_filter_in_sql($sequence, $column, $sep = true, $equal = true)
{
global $DB;
if($sequence){
$items = explode(",", clean_param($sequence, PARAM_SEQUENCE));
if(!empty($items)){
$this->prfx = $this->prfx + 1;
$key = clean_param($column.$this->prfx, PARAM_ALPHANUM);
list($sql, $params) = $DB->get_in_or_equal($items, SQL_PARAMS_NAMED, $key, $equal);
$this->params = array_merge($this->params, $params);
return ($sep) ? " AND $column $sql ": " $column $sql ";
}
}
return '';
}
private function get_report_data($query, $params, $wrap = true)
{
global $DB;
if(isset($params->start) and $params->length != 0 and $params->length != -1){
$data = $DB->get_records_sql($query, $this->params, $params->start, $params->length);
}else{
$data = $DB->get_records_sql($query, $this->params);
}
return ($wrap) ? array("data" => $data) : $data;
}
private function get_modules_sql($filter)
{
global $DB;
$list = clean_param($filter, PARAM_SEQUENCE);
$sql_mods = $this->get_filter_in_sql($list, "m.id");
$sql_columns = "";
$modules = $DB->get_records_sql("SELECT m.id, m.name FROM {modules} m WHERE m.visible = 1 $sql_mods", $this->params);
foreach($modules as $module){
$sql_columns .= " WHEN m.name='{$module->name}' THEN (SELECT name FROM {".$module->name."} WHERE id = cm.instance)";
}
return ($sql_columns) ? ", CASE $sql_columns ELSE 'NONE' END AS activity" : "'' AS activity";
}
public function report1($params)
{
$columns = array_merge(array("u.firstname","u.lastname", "u.email", "c.fullname", "enrols", "l.visits", "l.timespend", "grade", "cc.timecompleted","ue.timecreated", "ul.timeaccess", "ue.timeend", "cc.timecompleted","u.idnumber","u.phone1", "u.phone2", "u.institution", "u.department", "u.address", "u.city", "u.country"), $this->get_filter_columns($params));
$sql_columns = $this->get_columns($params, "u.id");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "u.id", "users");
$sql_filter .= $this->get_filter_in_sql($params->courseid, "c.id");
$sql_join_filter = ""; $sql_mode = 0;
$grade_single = intelliboard_grade_sql(false, $params);
$sql_join = "";
if(isset($params->custom) and strrpos($params->custom, ',') !== false){
$sql_filter .= $this->get_filter_in_sql($params->custom, "u.id");
$sql_filter_column = "ue.timecreated";
}elseif(isset($params->custom) and $params->custom == 2 and !$params->sizemode){
$sql_filter_column = "l.timepoint";
$sql_mode = 1;
}elseif(isset($params->custom) and $params->custom == 1){
$sql_filter_column = "cc.timecompleted";
}else{
$sql_filter_column = "ue.timecreated";
}
if($sql_mode){
$sql_join_filter .= $this->get_filterdate_sql($params, "$sql_filter_column");
}else{
$sql_filter .= $this->get_filterdate_sql($params, "$sql_filter_column");
}
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$sql_filter .= $this->get_filter_enrol_sql($params, "ue.");
$sql_filter .= $this->get_filter_enrol_sql($params, "e.");
if($params->cohortid){
$sql_join .= " LEFT JOIN {cohort_members} cm ON cm.userid = u.id";
$sql_filter .= $this->get_filter_in_sql($params->cohortid, "cm.cohortid");
}
if($params->sizemode){
$sql_columns .= ", '0' AS timespend, '0' AS visits";
}elseif($sql_mode){
$sql_columns .= ", l.timespend, l.visits";
$sql_join .= " LEFT JOIN (SELECT t.id,t.userid,t.courseid, SUM(l.timespend) AS timespend, SUM(l.visits) AS visits FROM
{local_intelliboard_tracking} t,
{local_intelliboard_logs} l
WHERE l.trackid = t.id $sql_join_filter GROUP BY t.courseid, t.userid) l ON l.courseid = c.id AND l.userid = u.id";
}else{
$sql_columns .= ", l.timespend, l.visits";
$sql_join .= " LEFT JOIN (SELECT t.userid,t.courseid, SUM(t.timespend) AS timespend, SUM(t.visits) AS visits FROM
{local_intelliboard_tracking} t GROUP BY t.courseid, t.userid) l ON l.courseid = c.id AND l.userid = u.id";
}
return $this->get_report_data("
SELECT ue.id,
ue.timecreated AS enrolled,
ue.timeend,
ul.timeaccess,
$grade_single AS grade,
c.enablecompletion,
cc.timecompleted AS complete,
u.id AS uid,
u.email,
u.idnumber,
u.phone1,
u.phone2,
u.institution,
u.department,
u.address,
u.city,
u.country,
u.firstname,
u.lastname,
e.enrol AS enrols,
c.id AS cid,
c.fullname AS course,
c.timemodified AS start_date
$sql_columns
FROM {user_enrolments} ue
LEFT JOIN {enrol} e ON e.id = ue.enrolid
LEFT JOIN {user} u ON u.id = ue.userid
LEFT JOIN {course} c ON c.id = e.courseid
LEFT JOIN {user_lastaccess} ul ON ul.courseid = c.id AND ul.userid = u.id
LEFT JOIN {course_completions} cc ON cc.course = e.courseid AND cc.userid = ue.userid
LEFT JOIN {grade_items} gi ON gi.itemtype = 'course' AND gi.courseid = e.courseid
LEFT JOIN {grade_grades} g ON g.userid = u.id AND g.itemid = gi.id AND g.finalgrade IS NOT NULL
$sql_join
WHERE ue.id > 0 $sql_filter $sql_having $sql_order", $params);
}
public function report2($params)
{
$columns = array_merge(array("c.fullname", "learners", "modules", "completed", "l.visits", "l.timespend", "grade", "c.timecreated"), $this->get_filter_columns($params));
$sql_filter = $this->get_teacher_sql($params, "c.id", "courses");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$sql_filter .= $this->get_filter_enrol_sql($params, "ue.");
$sql_filter .= $this->get_filter_enrol_sql($params, "e.");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$grade_avg = intelliboard_grade_sql(true, $params);
$sql_compl = "";
if ($params->custom == 1) {
$sql_compl = $this->get_filterdate_sql($params, "cc.timecompleted");
} elseif ($params->custom == 2) {
$sql_filter .= $this->get_filterdate_sql($params, "ue.timecreated");
} else {
$sql_filter .= $this->get_filterdate_sql($params, "c.timecreated");
}
if ($params->sizemode) {
$sql_columns = ", '0' AS timespend, '0' AS visits";
$sql_join = "";
} else {
$sql_columns = ", l.timespend, l.visits";
$sql_join = " LEFT JOIN (SELECT courseid, SUM(timespend) AS timespend, SUM(visits) AS visits FROM {local_intelliboard_tracking} GROUP BY courseid) l ON l.courseid = c.id";
$sql_having = ", l.timespend, l.visits " . $sql_having;
}
return $this->get_report_data("
SELECT c.id,
c.fullname AS course,
c.timecreated AS created,
c.enablecompletion,
$grade_avg AS grade,
COUNT(DISTINCT cc.userid) AS completed,
COUNT(DISTINCT ue.userid) AS learners,
(SELECT COUNT(id) FROM {course_modules} WHERE visible = 1 AND course = c.id) AS modules
$sql_columns
FROM {course} c
LEFT JOIN {enrol} e ON e.courseid = c.id
LEFT JOIN {user_enrolments} ue ON ue.enrolid=e.id
LEFT JOIN {course_completions} cc ON cc.timecompleted > 0 AND cc.course = c.id AND cc.userid = ue.userid $sql_compl
LEFT JOIN {grade_items} gi ON gi.itemtype = 'course' AND gi.courseid = c.id
LEFT JOIN {grade_grades} g ON g.userid = ue.userid AND g.itemid = gi.id AND g.finalgrade IS NOT NULL
$sql_join
WHERE c.id > 0 $sql_filter GROUP BY c.id $sql_having $sql_order", $params);
}
public function report3($params)
{
$columns = array_merge(array("activity", "m.name", "completed", "visits", "timespend", "grade", "cm.added"), $this->get_filter_columns($params));
$sql_having = $this->get_filter_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "c.id", "courses");
$sql_filter .= $this->get_filterdate_sql($params, "cm.added");
$sql_filter .= $this->get_filter_module_sql($params, "cm.");
$sql_filter .= $this->get_filter_in_sql($params->courseid, "cm.course");
$sql_filter .= $this->get_filter_in_sql($params->custom, "m.id");
$sql_columns = $this->get_modules_sql($params->custom);
$sql_order = $this->get_order_sql($params, $columns);
$grade_avg = intelliboard_grade_sql(true, $params);
$sql_join = "";
if($params->sizemode){
$sql_columns .= ", '0' as timespend, '0' as visits";
$sql_join = "";
}else{
$sql_columns .= ",
(SELECT SUM(timespend) FROM {local_intelliboard_tracking} WHERE page = 'module' AND param = cm.id) AS timespend,
(SELECT SUM(visits) FROM {local_intelliboard_tracking} WHERE page = 'module' AND param = cm.id) AS visits";
}
return $this->get_report_data("
SELECT
cm.id,
m.name AS moduletype,
cm.added,
cm.completion,
c.fullname,
(SELECT COUNT(id) FROM {course_modules_completion} WHERE coursemoduleid = cm.id AND completionstate = 1) AS completed,
(SELECT $grade_avg FROM {grade_items} gi, {grade_grades} g WHERE gi.itemtype = 'mod' AND gi.itemmodule = m.name AND gi.iteminstance = cm.instance AND g.itemid = gi.id AND g.finalgrade IS NOT NULL) AS grade
$sql_columns
FROM {course_modules} cm
LEFT JOIN {modules} m ON m.id = cm.module
LEFT JOIN {course} c ON c.id = cm.course
WHERE cm.id > 0 $sql_filter $sql_having $sql_order", $params);
}
public function report4($params)
{
$columns = array_merge(array("u.firstname","u.lastname","u.email","registered","courses","completed_activities","completed_courses","lit.visits","lit.timespend","grade", "u.lastaccess"), $this->get_filter_columns($params));
$sql_filter = $this->get_teacher_sql($params, "u.id", "users");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_in_sql($params->custom2, "ra.roleid");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_columns = $this->get_columns($params, "u.id");
$grade_avg = intelliboard_grade_sql(true, $params);
$sql_join = "";
if($params->cohortid){
$sql_join = "LEFT JOIN {cohort_members} chm ON chm.userid = u.id";
$sql_filter .= $this->get_filter_in_sql($params->cohortid, "chm.cohortid");
}
$sql_raw = true;
$sql_join_filter = "";
if(isset($params->custom) and $params->custom == 1){
$sql_join_filter .= $this->get_filterdate_sql($params, "l.timepoint");
$sql_raw = false;
}else{
$sql_filter .= $this->get_filterdate_sql($params, "u.timecreated");
}
if($params->sizemode and $sql_raw){
$sql_columns .= ", '0' as timespend, '0' as visits";
$sql_join = "";
}else{
if($sql_raw){
$sql_columns .= ", lit.timespend, lit.visits";
$sql_join .= " LEFT JOIN (SELECT userid, SUM(timespend) as timespend, SUM(visits) as visits FROM
{local_intelliboard_tracking}
WHERE courseid > 0 GROUP BY userid) as lit ON lit.userid = u.id";
}else{
$sql_columns .= ", lit.timespend, lit.visits";
$sql_join .= " LEFT JOIN (SELECT t.userid, SUM(l.timespend) as timespend, SUM(l.visits) as visits FROM
{local_intelliboard_tracking} t,
{local_intelliboard_logs} l
WHERE l.trackid = t.id AND t.courseid > 0 $sql_join_filter GROUP BY t.userid) as lit ON lit.userid = u.id";
}
$sql_having = ", lit.timespend, lit.visits" . $sql_having;
}
return $this->get_report_data("
SELECT u.id,
u.firstname,
u.lastname,
u.email,
u.lastaccess,
u.timecreated as registered,
$grade_avg as grade,
COUNT(DISTINCT ctx.instanceid) as courses,
COUNT(DISTINCT cc.id) as completed_courses,
(SELECT COUNT(id) FROM {course_modules_completion} WHERE completionstate = 1 AND userid = u.id) AS completed_activities
$sql_columns
FROM {user} u
LEFT JOIN {role_assignments} ra ON ra.userid = u.id
LEFT JOIN {context} ctx ON ctx.id = ra.contextid AND ctx.contextlevel=50
LEFT JOIN {course_completions} cc ON cc.course = ctx.instanceid AND cc.userid = u.id AND cc.timecompleted > 0
LEFT JOIN {grade_items} gi ON gi.courseid = ctx.instanceid AND gi.itemtype = 'course'
LEFT JOIN {grade_grades} g ON g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL
$sql_join
WHERE u.id > 0 $sql_filter GROUP BY u.id $sql_having $sql_order", $params);
}
public function report5($params)
{
$columns = array_merge(array("teacher","courses","ff.videos","l1.urls","l0.evideos","l2.assignments","l3.quizes","l4.forums","l5.attendances"), $this->get_filter_columns($params));
$sql_columns = $this->get_columns($params, "u.id");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "u.id", "users");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_in_sql($params->teacher_roles, "ra.roleid");
return $this->get_report_data("
SELECT u.id,
CONCAT(u.firstname, ' ', u.lastname) as teacher,
COUNT(DISTINCT ctx.instanceid) as courses,
MAX(f1.files) AS files,
MAX(ff.videos) AS videos,
MAX(l1.urls) AS urls,
MAX(l0.evideos) AS evideos,
MAX(l2.assignments) AS assignments,
MAX(l3.quizes) AS quizes,
MAX(l4.forums) AS forums,
MAX(l5.attendances) AS attendances
$sql_columns
FROM {role_assignments} ra
LEFT JOIN {context} AS ctx ON ctx.id = ra.contextid AND ctx.contextlevel = 50
LEFT JOIN {user} u ON u.id = ra.userid
LEFT JOIN (SELECT f.userid, count(distinct(f.filename)) files FROM {files} f WHERE filearea = 'content' GROUP BY f.userid) as f1 ON f1.userid = u.id
LEFT JOIN (SELECT f.userid, count(distinct(f.filename)) videos FROM {files} f WHERE f.mimetype LIKE '%video%' GROUP BY f.userid) as ff ON ff.userid = u.id
LEFT JOIN (SELECT l.userid, count(l.id) urls FROM {logstore_standard_log} l,{course_modules} cm, {modules} m WHERE cm.id = l.objectid AND m.id = cm.module AND m.name = 'url' AND l.action = 'created' GROUP BY l.userid) as l1 ON l1.userid = u.id
LEFT JOIN (SELECT l.userid, count(l.id) evideos FROM {logstore_standard_log} l,{course_modules} cm, {modules} m WHERE cm.id = l.objectid AND m.id = cm.module AND m.name = 'page' AND l.action = 'created'GROUP BY l.userid) as l0 ON l0.userid = u.id
LEFT JOIN (SELECT l.userid, count(l.id) assignments FROM {logstore_standard_log} l,{course_modules} cm, {modules} m WHERE cm.id = l.objectid AND m.id = cm.module AND m.name = 'assignment' AND l.action = 'created'GROUP BY l.userid) as l2 ON l2.userid = u.id
LEFT JOIN (SELECT l.userid, count(l.id) quizes FROM {logstore_standard_log} l,{course_modules} cm, {modules} m WHERE cm.id = l.objectid AND m.id = cm.module AND m.name = 'quiz' AND l.action = 'created'GROUP BY l.userid) as l3 ON l3.userid = u.id
LEFT JOIN (SELECT l.userid, count(l.id) forums FROM {logstore_standard_log} l,{course_modules} cm, {modules} m WHERE cm.id = l.objectid AND m.id = cm.module AND m.name = 'forum' AND l.action = 'created'GROUP BY l.userid) as l4 ON l4.userid = u.id
LEFT JOIN (SELECT l.userid, count(l.id) attendances FROM {logstore_standard_log} l,{course_modules} cm, {modules} m WHERE cm.id = l.objectid AND m.id = cm.module AND m.name = 'attendance' AND l.action = 'created'GROUP BY l.userid) as l5 ON l5.userid = u.id
WHERE u.id > 0 $sql_filter
GROUP BY u.id $sql_having $sql_order", $params);
}
public function report6($params)
{
$columns = array_merge(array("u.firstname", "u.lastname", "email", "c.fullname", "started", "grade", "grade", "completed", "grade", "complete", "visits", "timespend"), $this->get_filter_columns($params));
$sql_filter = $this->get_teacher_sql($params, "c.id", "courses");
$sql_filter .= $this->get_filter_in_sql($params->courseid, "e.courseid");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$sql_filter .= $this->get_filterdate_sql($params, "ue.timecreated");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$grade_avg = intelliboard_grade_sql(true, $params);
$sql_columns = $this->get_columns($params, "u.id");
$sql_join = "";
if($params->cohortid){
$sql_join = " LEFT JOIN {cohort_members} ch ON ch.userid = u.id";
$sql_filter .= $this->get_filter_in_sql($params->cohortid, "ch.cohortid");
}
if($params->sizemode){
$sql_columns .= ", '0' as timespend, '0' as visits";
}else{
$sql_columns .= ", MAX(lit.timespend) AS timespend, MAX(lit.visits) AS visits";
$sql_join .= " LEFT JOIN (SELECT userid, courseid, SUM(timespend) as timespend, SUM(visits) as visits
FROM {local_intelliboard_tracking} GROUP BY courseid, userid) lit ON lit.courseid = c.id AND lit.userid = u.id";
}
return $this->get_report_data("
SELECT MAX(ue.id) AS id,
MAX(cri.gradepass) AS gradepass,
MAX(ue.timecreated) as started,
$grade_avg AS grade,
MAX(cc.timecompleted) as complete,
c.id as cid,
c.fullname,
u.email,
u.id AS userid,
u.firstname,
u.lastname,
c.enablecompletion,
(SELECT COUNT(DISTINCT cmc.id) FROM {course_modules_completion} cmc, {course_modules} cm WHERE cm.visible = 1 AND cmc.coursemoduleid = cm.id AND cmc.completionstate = 1 AND cm.completion > 0 AND cm.course = c.id AND cmc.userid = u.id) AS completed,
(SELECT $grade_avg FROM {grade_items} gi, {grade_grades} g WHERE gi.itemtype = 'course' AND g.itemid = gi.id AND g.finalgrade IS NOT NULL AND gi.courseid=c.id) AS average
$sql_columns
FROM {user_enrolments} ue
LEFT JOIN {user} u ON u.id = ue.userid
LEFT JOIN {enrol} e ON e.id = ue.enrolid
LEFT JOIN {course} c ON c.id = e.courseid
LEFT JOIN {course_completions} cc ON cc.course = e.courseid AND cc.userid = ue.userid
LEFT JOIN {course_completion_criteria} cri ON cri.course = e.courseid AND cri.criteriatype = 6
LEFT JOIN {grade_items} gi ON gi.courseid = c.id AND gi.itemtype = 'course'
LEFT JOIN {grade_grades} g ON g.itemid = gi.id AND g.userid =u.id
$sql_join
WHERE ue.id > 0 $sql_filter GROUP BY u.id, c.id $sql_having $sql_order", $params);
}
public function report7($params)
{
$columns = array_merge(array("u.firstname","u.lastname","email", "course", "visits", "participations", "assignments", "grade"), $this->get_filter_columns($params));
$sql_having = $this->get_filter_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "c.id", "courses");
$sql_filter .= $this->get_filter_in_sql($params->courseid, "e.courseid");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$sql_filter .= $this->get_filterdate_sql($params, "ue.timecreated");
$sql_order = $this->get_order_sql($params, $columns);
$sql_columns = $this->get_columns($params, "u.id");
$grade_single = intelliboard_grade_sql(false, $params);
if($params->sizemode){
$sql_columns .= ", '0' as grade";
$sql_join = "";
}else{
$sql_columns .= ", gc.grade AS grade";
$sql_join = "
LEFT JOIN (SELECT gi.courseid, g.userid, $grade_single AS grade
FROM {grade_items} gi, {grade_grades} g WHERE gi.itemtype = 'course' AND g.itemid = gi.id AND g.finalgrade IS NOT NULL
GROUP BY gi.courseid, g.userid) as gc ON gc.courseid = c.id AND gc.userid = u.id";
}
return $this->get_report_data("
SELECT ue.id, ue.userid,u.email,
((cmca.cmcnuma / cma.cmnuma)*100 ) as assignments,
((cmc.cmcnums / cmx.cmnumx)*100 ) as participations,
((COUNT(DISTINCT lit.id) / cm.cmnums)*100 ) as visits,
cma.cmnuma as assigns,
c.fullname as course,
u.firstname,
u.lastname
$sql_columns
FROM {user_enrolments} ue
LEFT JOIN {user} u ON u.id = ue.userid
LEFT JOIN {enrol} e ON e.id = ue.enrolid
LEFT JOIN {course} c ON c.id = e.courseid
LEFT JOIN {local_intelliboard_tracking} lit ON lit.courseid = c.id AND lit.page = 'module' AND lit.userid = u.id
LEFT JOIN (SELECT course, count(id) as cmnums FROM {course_modules} WHERE visible = 1 GROUP BY course) as cm ON cm.course = c.id
LEFT JOIN (SELECT course, count(id) as cmnumx FROM {course_modules} WHERE visible = 1 and completion > 0 GROUP BY course) cmx ON cmx.course = c.id
LEFT JOIN (SELECT course, count(id) as cmnuma FROM {course_modules} WHERE visible = 1 and module = 1 GROUP BY course) cma ON cma.course = c.id
LEFT JOIN (SELECT cm.course, cmc.userid, count(cmc.id) as cmcnums FROM {course_modules} cm, {course_modules_completion} cmc WHERE cmc.coursemoduleid = cm.id AND cm.visible = 1 AND cmc.completionstate = 1 GROUP BY cm.course, cmc.userid) cmc ON cmc.course = c.id AND cmc.userid = u.id
LEFT JOIN (SELECT cm.course, cmc.userid, count(cmc.id) as cmcnuma FROM {course_modules} cm, {course_modules_completion} cmc WHERE cmc.coursemoduleid = cm.id AND cm.module = 1 AND cm.visible = 1 AND cmc.completionstate = 1 GROUP BY cm.course, cmc.userid) as cmca ON cmca.course = c.id AND cmca.userid = u.id
$sql_join
WHERE ue.id > 0 $sql_filter GROUP BY ue.userid, e.courseid $sql_having $sql_order", $params);
}
public function report8($params)
{
$columns = array_merge(array("teacher","courses","learners","activelearners","completedlearners","grade"), $this->get_filter_columns($params));
$sql_filter = $this->get_teacher_sql($params, "u.id", "users");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_columns = $this->get_columns($params, "u.id");
$grade_avg = intelliboard_grade_sql(true, $params);
$sql1 = $this->get_filter_in_sql($params->learner_roles, "ra.roleid");
$sql2 = $this->get_filter_in_sql($params->learner_roles, "ra.roleid");
$sql3 = $this->get_filter_in_sql($params->teacher_roles, "ra.roleid");
$this->params['tx1'] = strtotime('-30 days');
$this->params['tx2'] = time();
return $this->get_report_data("
SELECT u.id,
CONCAT(u.firstname, ' ', u.lastname) teacher,
COUNT(DISTINCT ctx.instanceid) as courses,
SUM(l.learners) as learners,
SUM(l1.activelearners) as activelearners,
SUM(cc.completed) as completedlearners,
AVG(g.grade) as grade
$sql_columns
FROM {user} u
LEFT JOIN {role_assignments} AS ra ON ra.userid = u.id
LEFT JOIN {context} AS ctx ON ctx.id = ra.contextid
LEFT JOIN (SELECT ctx.instanceid, count(distinct ra.userid) as learners FROM {role_assignments} ra, {context} ctx WHERE ctx.id = ra.contextid AND ctx.contextlevel = 50 $sql1 GROUP BY ctx.instanceid) AS l ON l.instanceid = ctx.instanceid
LEFT JOIN (SELECT ctx.instanceid, count(distinct ra.userid) as activelearners FROM {role_assignments} ra, {user} u, {context} ctx
WHERE ctx.id = ra.contextid AND ctx.contextlevel = 50 AND u.id = ra.userid AND u.lastaccess BETWEEN :tx1 AND :tx2 AND u.deleted = 0 AND u.suspended = 0 $sql2 GROUP BY ctx.instanceid) AS l1 ON l1.instanceid = ctx.instanceid
LEFT JOIN (SELECT course, count(id) as completed FROM {course_completions} WHERE timecompleted > 0 GROUP BY course) cc ON cc.course = ctx.instanceid
LEFT JOIN (SELECT gi.courseid, $grade_avg AS grade FROM {grade_items} gi, {grade_grades} g WHERE gi.itemtype = 'course' AND g.itemid = gi.id AND g.finalgrade IS NOT NULL GROUP BY gi.courseid) g ON g.courseid = ctx.instanceid
WHERE ctx.contextlevel = 50 $sql3 $sql_filter
GROUP BY u.id $sql_having $sql_order", $params);
}
public function report9($params)
{
$columns = array_merge(
array(
"q.name",
"c.fullname",
"ql.questions",
"attempts",
"q.timeopen",
"duration",
"grade",
"q.timemodified"),
$this->get_filter_columns($params)
);
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "q.course", "courses");
$sql_filter .= $this->get_filter_in_sql($params->courseid, "q.course");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
return $this->get_report_data("
SELECT q.id,
q.name,
q.course,
c.fullname,
ql.questions,
q.timemodified,
q.timeopen,
q.timeclose,
avg((qa.sumgrades/q.sumgrades)*100) AS grade,
count(distinct(qa.id)) AS attempts,
sum(qa.timefinish - qa.timestart) AS duration
FROM {quiz} q
LEFT JOIN {course} c ON c.id = q.course
LEFT JOIN {quiz_attempts} qa ON qa.quiz = q.id
LEFT JOIN (SELECT quizid, count(*) questions FROM {quiz_slots} GROUP BY quizid) ql ON ql.quizid = q.id
WHERE q.id > 0 $sql_filter
GROUP BY q.id $sql_having $sql_order", $params);
}
public function report10($params)
{
$columns = array_merge(array("q.name","u.firstname","u.lastname", "u.email", "c.fullname", "qa.state", "qa.timestart", "qa.timefinish", "duration", "grade"), $this->get_filter_columns($params));
$sql_filter = $this->get_teacher_sql($params, "q.course", "courses");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_filter .= $this->get_filter_in_sql($params->courseid, "q.course");
$sql_filter .= $this->get_filter_in_sql($params->learner_roles, "ra.roleid");
$sql_filter .= $this->get_filterdate_sql($params, "qa.timestart");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$sql_order = $this->get_order_sql($params, $columns);
$sql_columns = $this->get_columns($params, "u.id");
$sql_join = "";
if($params->cohortid){
$sql_join = "LEFT JOIN {cohort_members} ch ON ch.userid = u.id";
$sql_filter .= $this->get_filter_in_sql($params->cohortid, "ch.cohortid");
}
return $this->get_report_data("
SELECT qa.id,
q.name, u.email,
q.course,
c.fullname,
qa.timestart,
qa.timefinish,
qa.state,
(qa.timefinish - qa.timestart) as duration,
(qa.sumgrades/q.sumgrades*100) as grade,
u.firstname,
u.lastname
$sql_columns
FROM {quiz_attempts} qa
LEFT JOIN {quiz} q ON q.id = qa.quiz
LEFT JOIN {user} u ON u.id = qa.userid
LEFT JOIN {course} c ON c.id = q.course
LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = 50
LEFT JOIN {role_assignments} ra ON ra.contextid = ctx.id AND ra.userid = u.id
$sql_join
WHERE qa.id > 0 $sql_filter $sql_having $sql_order", $params);
}
public function report11($params)
{
$columns = array_merge(array("u.firstname", "u.lastname", "course", "u.email", "enrolled", "complete", "grade", "complete"), $this->get_filter_columns($params));
$sql_columns = $this->get_columns($params, "u.id");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "c.id", "courses");
$sql_filter .= $this->get_filter_in_sql($params->courseid, "c.id");
$sql_filter .= $this->get_filterdate_sql($params, "ue.timecreated");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$grade_single = intelliboard_grade_sql(false, $params);
$sql_join = "";
if($params->cohortid){
$sql_join = "LEFT JOIN {cohort_members} cm ON cm.userid = u.id";
$sql_filter .= $this->get_filter_in_sql($params->cohortid, "cm.cohortid");
}
return $this->get_report_data("
SELECT ue.id,
ue.timecreated as enrolled,
cc.timecompleted as complete,
$grade_single AS grade,
u.id as uid,
u.email,
u.firstname,
u.lastname,
c.id as cid,
c.enablecompletion,
c.fullname as course
$sql_columns
FROM {user_enrolments} ue
LEFT JOIN {enrol} e ON e.id = ue.enrolid
LEFT JOIN {user} u ON u.id = ue.userid
LEFT JOIN {course} c ON c.id = e.courseid
LEFT JOIN {course_completions} cc ON cc.course = e.courseid AND cc.userid = u.id
LEFT JOIN {grade_items} gi ON gi.courseid = e.courseid AND gi.itemtype = 'course'
LEFT JOIN {grade_grades} g ON g.itemid = gi.id AND g.userid = u.id
$sql_join
WHERE ue.id > 0 $sql_filter $sql_having $sql_order", $params);
}
public function report12($params)
{
$columns = array_merge(
array(
"c.fullname",
"learners",
"completed",
"visits",
"timespend",
"grade"),
$this->get_filter_columns($params)
);
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "e.courseid", "courses");
$sql_filter .= $this->get_filter_in_sql($params->learner_roles, "ra.roleid");
$sql_filter .= $this->get_filter_course_sql($params, "c.");
$grade_avg = intelliboard_grade_sql(true, $params);
if($params->sizemode){
$sql_columns = ", '0' as timespend, '0' as visits";
$sql_join = "";
}else{
$sql_columns = ", lit.timespend AS timespend, lit.visits AS visits";
$sql_join = "
LEFT JOIN (SELECT userid, courseid, SUM(timespend) as timespend, SUM(visits) as visits
FROM {local_intelliboard_tracking} GROUP BY courseid, userid) lit ON lit.courseid = c.id AND lit.userid = ra.userid";
}
return $this->get_report_data("
SELECT c.id,
c.fullname,
COUNT(DISTINCT ra.userid) as learners,
COUNT(DISTINCT cc.userid) as completed,
$grade_avg AS grade
$sql_columns
FROM {role_assignments} ra
LEFT JOIN {context} AS ctx ON ctx.id = ra.contextid AND ctx.contextlevel = 50
LEFT JOIN {course} c ON c.id = ctx.instanceid
LEFT JOIN {grade_items} gi ON gi.courseid = c.id AND gi.itemtype = 'course'
LEFT JOIN {grade_grades} g ON g.itemid = gi.id AND g.userid = ra.userid
LEFT JOIN {course_completions} cc ON cc.course = c.id AND cc.userid = ra.userid
$sql_join
WHERE c.id $sql_filter
GROUP BY c.id $sql_having $sql_order", $params);
}
public function report13($params)
{
$columns = array_merge(
array(
"name",
"visits",
"timespend",
"courses",
"learners"),
$this->get_filter_columns($params)
);
$sql_columns = $this->get_columns($params, "u.id");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "u.id", "users");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_in_sql($params->teacher_roles, "ra.roleid");
$sql_filter .= $this->get_filterdate_sql($params, "u.timecreated");
$sql1 = $this->get_filter_in_sql($params->learner_roles, "r.roleid");
if($params->sizemode){
$sql_columns .= ", '0' as timespend, '0' as visits";
$sql_join = "";
}else{
$sql_columns .= ", lit.timespend AS timespend, lit.visits AS visits";
$sql_join = "
LEFT JOIN (SELECT userid, SUM(timespend) as timespend, SUM(visits) as visits
FROM {local_intelliboard_tracking} GROUP BY userid) lit ON lit.userid = ra.userid";
}
return $this->get_report_data("
SELECT u.id,
CONCAT(u.firstname, ' ', u.lastname) name,
COUNT(DISTINCT ctx.instanceid) as courses,
SUM(v.learners) as learners
$sql_columns
FROM {role_assignments} ra
LEFT JOIN {context} AS ctx ON ctx.id = ra.contextid AND ctx.contextlevel = 50
LEFT JOIN {user} u ON u.id = ra.userid
LEFT JOIN (SELECT c.instanceid, COUNT(DISTINCT r.userid) as learners
FROM {role_assignments} r, {context} AS c WHERE c.id = r.contextid $sql1 GROUP BY c.instanceid) v ON v.instanceid = ctx.instanceid
$sql_join
WHERE u.id > 0 $sql_filter
GROUP BY ra.userid $sql_having $sql_order", $params);
}
public function report14($params)
{
$columns = array_merge(
array(
"u.firstname",
"u.lastname",
"u.email",
"u.lastaccess",
"visits",
"timespend",
"courses",
"grade"),
$this->get_filter_columns($params)
);
$sql_columns = $this->get_columns($params, "u.id");
$sql_having = $this->get_filter_sql($params, $columns);
$sql_order = $this->get_order_sql($params, $columns);
$sql_filter = $this->get_teacher_sql($params, "u.id", "users");
$sql_filter .= $this->get_filter_user_sql($params, "u.");
$sql_filter .= $this->get_filter_in_sql($params->learner_roles, "ra.roleid");
$sql_filter .= $this->get_filterdate_sql($params, "u.timecreated");
$grade_avg = intelliboard_grade_sql(true, $params);
if($params->sizemode){
$sql_columns .= ", '0' as timespend, '0' as visits";
$sql_join = "";
}else{
$sql_columns .= ", lit.timespend AS timespend, lit.visits AS visits";
$sql_join = "
LEFT JOIN (SELECT userid, SUM(timespend) as timespend, SUM(visits) as visits
FROM {local_intelliboard_tracking} GROUP BY userid) lit ON lit.userid = ra.userid";
}