-
Notifications
You must be signed in to change notification settings - Fork 466
/
myspace.lib.php
3371 lines (3076 loc) · 126 KB
/
myspace.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
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
use CpChart\Cache as pCache;
use CpChart\Data as pData;
use CpChart\Image as pImage;
/**
* Class MySpace.
*/
class MySpace
{
/**
* Get admin actions.
*
* @return string
*/
public static function getAdminActions()
{
$actions = [
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=coaches',
'content' => get_lang('DisplayCoaches'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=user',
'content' => get_lang('DisplayUserOverview'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=session',
'content' => get_lang('DisplaySessionOverview'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=course',
'content' => get_lang('DisplayCourseOverview'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin',
'content' => get_lang('LPQuestionListResults'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin',
'content' => get_lang('LPExerciseResultsBySession'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=accessoverview',
'content' => get_lang('DisplayAccessOverview').' ('.get_lang('Beta').')',
],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/exercise_category_report.php',
'content' => get_lang('ExerciseCategoryAllSessionsReport'),
],
[
'url' => api_get_path(WEB_CODE_PATH).'mySpace/survey_report.php',
'content' => get_lang('SurveysReport'),
],
];
return Display::actions($actions, null);
}
/**
* @return string
*/
public static function getTopMenu()
{
$menuItems = [];
$menuItems[] = Display::url(
Display::return_icon(
'statistics.png',
get_lang('MyStats'),
'',
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
);
$menuItems[] = Display::url(
Display::return_icon(
'teacher.png',
get_lang('TeacherInterface'),
[],
32
),
api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher'
);
$menuItems[] = Display::url(
Display::return_icon(
'star_na.png',
get_lang('AdminInterface'),
[],
32
),
'#'
);
$menuItems[] = Display::url(
Display::return_icon('quiz.png', get_lang('ExamTracking'), [], 32),
api_get_path(WEB_CODE_PATH).'tracking/exams.php'
);
$menu = '';
foreach ($menuItems as $item) {
$menu .= $item;
}
$menu .= '<br />';
return $menu;
}
/**
* This function serves exporting data in CSV format.
*
* @param array $header the header labels
* @param array $data the data array
* @param string $file_name the name of the file which contains exported data
*
* @return string mixed Returns a message (string) if an error occurred
*/
public function export_csv($header, $data, $file_name = 'export.csv')
{
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
$archive_url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive=';
$message = '';
if (!$open = fopen($archive_path.$file_name, 'w+')) {
$message = get_lang('noOpen');
} else {
$info = '';
foreach ($header as $value) {
$info .= $value.';';
}
$info .= "\r\n";
foreach ($data as $row) {
foreach ($row as $value) {
$info .= $value.';';
}
$info .= "\r\n";
}
fwrite($open, $info);
fclose($open);
@chmod($file_name, api_get_permissions_for_new_files());
header("Location:".$archive_url.$file_name);
exit;
}
return $message;
}
/**
* Gets the connections to a course as an array of login and logout time.
*
* @param int $userId User id
* @param array $courseInfo
* @param int $sessionId Session id (optional, default = 0)
*
* @return array Connections
*/
public static function get_connections_to_course(
$userId,
$courseInfo,
$sessionId = 0
) {
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
// protect data
$userId = (int) $userId;
$courseId = (int) $courseInfo['real_id'];
$sessionId = (int) $sessionId;
$sessionCondition = api_get_session_condition($sessionId);
$sql = 'SELECT login_course_date, logout_course_date
FROM '.$table.'
WHERE
user_id = '.$userId.' AND
c_id = '.$courseId.'
'.$sessionCondition.'
ORDER BY login_course_date ASC';
$rs = Database::query($sql);
$connections = [];
while ($row = Database::fetch_array($rs)) {
$connections[] = [
'login' => $row['login_course_date'],
'logout' => $row['logout_course_date'],
];
}
return $connections;
}
/**
* @param $user_id
* @param $course_list
* @param int $session_id
*
* @return array|bool
*/
public static function get_connections_from_course_list(
$user_id,
$course_list,
$session_id = 0
) {
// Database table definitions
$tbl_track_course = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
if (empty($course_list)) {
return false;
}
// protect data
$user_id = (int) $user_id;
$session_id = (int) $session_id;
$new_course_list = [];
foreach ($course_list as $course_item) {
$courseInfo = api_get_course_info($course_item['code']);
if ($courseInfo) {
$courseId = $courseInfo['real_id'];
$new_course_list[] = '"'.$courseId.'"';
}
}
$course_list = implode(', ', $new_course_list);
if (empty($course_list)) {
return false;
}
$sql = 'SELECT login_course_date, logout_course_date, c_id
FROM '.$tbl_track_course.'
WHERE
user_id = '.$user_id.' AND
c_id IN ('.$course_list.') AND
session_id = '.$session_id.'
ORDER BY login_course_date ASC';
$rs = Database::query($sql);
$connections = [];
while ($row = Database::fetch_array($rs)) {
$timestamp_login_date = api_strtotime($row['login_course_date'], 'UTC');
$timestamp_logout_date = api_strtotime($row['logout_course_date'], 'UTC');
$connections[] = [
'login' => $timestamp_login_date,
'logout' => $timestamp_logout_date,
'c_id' => $row['c_id'],
];
}
return $connections;
}
/**
* Creates a small table in the last column of the table with the user overview.
*
* @param int $user_id the id of the user
*
* @return array List course
*/
public static function returnCourseTracking($user_id)
{
$user_id = (int) $user_id;
if (empty($user_id)) {
return [];
}
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
// getting all the courses of the user
$sql = "SELECT * FROM $tbl_course_user
WHERE
user_id = $user_id AND
relation_type <> ".COURSE_RELATION_TYPE_RRHH;
$result = Database::query($sql);
$list = [];
while ($row = Database::fetch_array($result)) {
$courseInfo = api_get_course_info_by_id($row['c_id']);
$courseId = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
if (empty($courseInfo)) {
continue;
}
$avg_score = Tracking::get_avg_student_score($user_id, $courseCode);
if (is_numeric($avg_score)) {
$avg_score = round($avg_score, 2);
} else {
$avg_score = '-';
}
// Student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
$exercisesResults = self::exercises_results($user_id, $courseCode);
$resultToString = '';
if (!is_null($exercisesResults['percentage'])) {
$resultToString = $exercisesResults['score_obtained'].'/'.$exercisesResults['score_possible'].' ( '.$exercisesResults['percentage'].'% )';
}
$item = [
'code' => $courseInfo['code'],
'real_id' => $courseInfo['real_id'],
'title' => $courseInfo['title'],
'category' => $courseInfo['categoryName'],
'image_small' => $courseInfo['course_image'],
'image_large' => $courseInfo['course_image_large'],
'time_spent' => api_time_to_hms(Tracking::get_time_spent_on_the_course($user_id, $courseId)),
'student_progress' => round(Tracking::get_avg_student_progress($user_id, $courseCode)),
'student_score' => $avg_score,
'student_message' => Tracking::count_student_messages($user_id, $courseCode),
'student_assignments' => Tracking::count_student_assignments($user_id, $courseCode),
'student_exercises' => $resultToString,
'questions_answered' => $exercisesResults['questions_answered'],
'last_connection' => Tracking::get_last_connection_date_on_the_course($user_id, $courseInfo),
];
$list[] = $item;
}
return $list;
}
/**
* Display a sortable table that contains an overview off all the
* reporting progress of all users and all courses the user is subscribed to.
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* Alex Aragon <alex.aragon@beeznest.com>, BeezNest, Perú
*
* @version Chamilo 1.11.8
*
* @since April 2019
*/
public static function returnTrackingUserOverviewFilter($user_id)
{
$tpl = new Template('', false, false, false, false, false, false);
$userInfo = api_get_user_info($user_id);
$avatar = UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_SMALL);
$user = [
'id' => $user_id,
'code_user' => $userInfo['official_code'],
'complete_name' => $userInfo['complete_name'],
'username' => $userInfo['username'],
'course' => self::returnCourseTracking($user_id),
'avatar' => $avatar,
];
$tpl->assign('item', $user);
$templateName = $tpl->get_template('my_space/partials/tracking_user_overview.tpl');
$content = $tpl->fetch($templateName);
return $content;
}
/**
* Display a sortable table that contains an overview off all the
* reporting progress of all users and all courses the user is subscribed to.
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* Alex Aragon <alex.aragon@beeznest.com>, BeezNest, Perú
*
* @version Chamilo 1.11.8
*
* @since October 2008, Update April 2019
*/
public static function display_tracking_user_overview()
{
self::display_user_overview_export_options();
$params = ['view' => 'admin', 'display' => 'user'];
$table = new SortableTable(
'tracking_user_overview',
['MySpace', 'get_number_of_users_tracking_overview'],
['MySpace', 'get_user_data_tracking_overview'],
0,
20,
'ASC',
null, [
'class' => 'table table-transparent',
]
);
$table->additional_parameters = $params;
$table->set_column_filter(0, ['MySpace', 'returnTrackingUserOverviewFilter']);
$tableContent = $table->return_table();
$tpl = new Template('', false, false, false, false, false, false);
$tpl->assign('table', $tableContent);
$templateName = $tpl->get_template('my_space/user_summary.tpl');
$tpl->display($templateName);
}
/**
* @param $export_csv
*/
public static function display_tracking_coach_overview($export_csv)
{
if ($export_csv) {
$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
} else {
$is_western_name_order = api_is_western_name_order();
}
$sort_by_first_name = api_sort_by_first_name();
if (isset($_GET['tracking_list_coaches_column'])) {
$tracking_column = (int) $_GET['tracking_list_coaches_column'];
} else {
$tracking_column = ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
}
$tracking_direction = (isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']), ['ASC', 'DESC', 'ASCENDING', 'DESCENDING', '0', '1'])) ? $_GET['tracking_list_coaches_direction'] : 'DESC';
// Prepare array for column order - when impossible, use some of user names.
if ($is_western_name_order) {
$order = [
0 => 'firstname',
1 => 'lastname',
2 => $sort_by_first_name ? 'firstname' : 'lastname',
3 => 'login_date',
4 => $sort_by_first_name ? 'firstname' : 'lastname',
5 => $sort_by_first_name ? 'firstname' : 'lastname',
];
} else {
$order = [
0 => 'lastname',
1 => 'firstname',
2 => $sort_by_first_name ? 'firstname' : 'lastname',
3 => 'login_date',
4 => $sort_by_first_name ? 'firstname' : 'lastname',
5 => $sort_by_first_name ? 'firstname' : 'lastname',
];
}
$table = new SortableTable(
'tracking_list_coaches_myspace',
['MySpace', 'count_coaches'],
null,
($is_western_name_order xor $sort_by_first_name) ? 1 : 0
);
$parameters['view'] = 'admin';
$table->set_additional_parameters($parameters);
if ($is_western_name_order) {
$table->set_header(0, get_lang('FirstName'), true);
$table->set_header(1, get_lang('LastName'), true);
} else {
$table->set_header(0, get_lang('LastName'), true);
$table->set_header(1, get_lang('FirstName'), true);
}
$table->set_header(2, get_lang('TimeSpentOnThePlatform'), false);
$table->set_header(3, get_lang('LastConnexion'), false);
$table->set_header(4, get_lang('NbStudents'), false);
$table->set_header(5, get_lang('CountCours'), false);
$table->set_header(6, get_lang('NumberOfSessions'), false);
$table->set_header(7, get_lang('Sessions'), false);
if ($is_western_name_order) {
$csv_header[] = [
get_lang('FirstName'),
get_lang('LastName'),
get_lang('TimeSpentOnThePlatform'),
get_lang('LastConnexion'),
get_lang('NbStudents'),
get_lang('CountCours'),
get_lang('NumberOfSessions'),
];
} else {
$csv_header[] = [
get_lang('LastName'),
get_lang('FirstName'),
get_lang('TimeSpentOnThePlatform'),
get_lang('LastConnexion'),
get_lang('NbStudents'),
get_lang('CountCours'),
get_lang('NumberOfSessions'),
];
}
$tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
$sqlCoachs = "SELECT DISTINCT
scu.user_id as id_coach,
u.id as user_id,
lastname,
firstname,
MAX(login_date) as login_date
FROM $tbl_user u, $tbl_session_course_user scu, $tbl_track_login
WHERE
scu.user_id = u.id AND scu.status=2 AND login_user_id=u.id
GROUP BY user_id ";
if (api_is_multiple_url_enabled()) {
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if (-1 != $access_url_id) {
$sqlCoachs = "SELECT DISTINCT
scu.user_id as id_coach,
u.id as user_id,
lastname,
firstname,
MAX(login_date) as login_date
FROM $tbl_user u,
$tbl_session_course_user scu,
$tbl_track_login ,
$tbl_session_rel_access_url session_rel_url
WHERE
scu.user_id = u.id AND
scu.status = 2 AND
login_user_id = u.id AND
access_url_id = $access_url_id AND
session_rel_url.session_id = scu.session_id
GROUP BY u.id";
}
}
if (!empty($order[$tracking_column])) {
$sqlCoachs .= ' ORDER BY '.$order[$tracking_column].' '.$tracking_direction;
}
$result_coaches = Database::query($sqlCoachs);
$global_coaches = [];
while ($coach = Database::fetch_array($result_coaches)) {
$global_coaches[$coach['user_id']] = $coach;
}
$sql_session_coach = "SELECT session.id_coach, u.id as user_id, lastname, firstname, MAX(login_date) as login_date
FROM $tbl_user u , $tbl_sessions as session, $tbl_track_login
WHERE id_coach = u.id AND login_user_id = u.id
GROUP BY u.id
ORDER BY login_date $tracking_direction";
if (api_is_multiple_url_enabled()) {
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql_session_coach = "SELECT session.id_coach, u.id as user_id, lastname, firstname, MAX(login_date) as login_date
FROM $tbl_user u , $tbl_sessions as session, $tbl_track_login , $tbl_session_rel_access_url as session_rel_url
WHERE
id_coach = u.id AND
login_user_id = u.id AND
access_url_id = $access_url_id AND
session_rel_url.session_id = session.id
GROUP BY u.id
ORDER BY login_date $tracking_direction";
}
}
$result_sessions_coach = Database::query($sql_session_coach);
//$total_no_coaches += Database::num_rows($result_sessions_coach);
while ($coach = Database::fetch_array($result_sessions_coach)) {
$global_coaches[$coach['user_id']] = $coach;
}
$all_datas = [];
foreach ($global_coaches as $id_coach => $coaches) {
$time_on_platform = api_time_to_hms(
Tracking::get_time_spent_on_the_platform($coaches['user_id'])
);
$last_connection = Tracking::get_last_connection_date(
$coaches['user_id']
);
$nb_students = count(
Tracking::get_student_followed_by_coach($coaches['user_id'])
);
$nb_courses = count(
Tracking::get_courses_followed_by_coach($coaches['user_id'])
);
$nb_sessions = count(
Tracking::get_sessions_coached_by_user($coaches['user_id'])
);
$table_row = [];
if ($is_western_name_order) {
$table_row[] = $coaches['firstname'];
$table_row[] = $coaches['lastname'];
} else {
$table_row[] = $coaches['lastname'];
$table_row[] = $coaches['firstname'];
}
$table_row[] = $time_on_platform;
$table_row[] = $last_connection;
$table_row[] = $nb_students;
$table_row[] = $nb_courses;
$table_row[] = $nb_sessions;
$table_row[] = '<a href="session.php?id_coach='.$coaches['user_id'].'">
'.Display::return_icon('2rightarrow.png', get_lang('Details')).'
</a>';
$all_datas[] = $table_row;
if ($is_western_name_order) {
$csv_content[] = [
api_html_entity_decode($coaches['firstname'], ENT_QUOTES),
api_html_entity_decode($coaches['lastname'], ENT_QUOTES),
$time_on_platform,
$last_connection,
$nb_students,
$nb_courses,
$nb_sessions,
];
} else {
$csv_content[] = [
api_html_entity_decode($coaches['lastname'], ENT_QUOTES),
api_html_entity_decode($coaches['firstname'], ENT_QUOTES),
$time_on_platform,
$last_connection,
$nb_students,
$nb_courses,
$nb_sessions,
];
}
}
if ($tracking_column != 3) {
if ($tracking_direction == 'DESC') {
usort($all_datas, ['MySpace', 'rsort_users']);
} else {
usort($all_datas, ['MySpace', 'sort_users']);
}
}
if ($export_csv && $tracking_column != 3) {
usort($csv_content, 'sort_users');
}
if ($export_csv) {
$csv_content = array_merge($csv_header, $csv_content);
}
foreach ($all_datas as $row) {
$table->addRow($row, 'align="right"');
}
$table->display();
}
/**
* @return mixed
*/
public static function count_coaches()
{
global $total_no_coaches;
return $total_no_coaches;
}
public static function sort_users($a, $b)
{
$tracking = Session::read('tracking_column');
return api_strcmp(
trim(api_strtolower($a[$tracking])),
trim(api_strtolower($b[$tracking]))
);
}
public static function rsort_users($a, $b)
{
$tracking = Session::read('tracking_column');
return api_strcmp(
trim(api_strtolower($b[$tracking])),
trim(api_strtolower($a[$tracking]))
);
}
/**
* Display a sortable table that contains an overview off all the progress of the user in a session.
*
* @deprecated ?
*
* @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
*/
public static function display_tracking_lp_progress_overview(
$sessionId = '',
$courseId = '',
$date_from,
$date_to
) {
$course = api_get_course_info_by_id($courseId);
/**
* Column name
* The order is important you need to check the $column variable in the model.ajax.php file.
*/
$columns = [
get_lang('Username'),
get_lang('FirstName'),
get_lang('LastName'),
];
//add lessons of course
$lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
//create columns array
foreach ($lessons as $lesson_id => $lesson) {
$columns[] = $lesson['name'];
}
$columns[] = get_lang('Total');
/**
* Column config.
*/
$column_model = [
[
'name' => 'username',
'index' => 'username',
'align' => 'left',
'search' => 'true',
'wrap_cell' => "true",
],
[
'name' => 'firstname',
'index' => 'firstname',
'align' => 'left',
'search' => 'true',
],
[
'name' => 'lastname',
'index' => 'lastname',
'align' => 'left',
'search' => 'true',
],
];
// Get dinamic column names
foreach ($lessons as $lesson_id => $lesson) {
$column_model[] = [
'name' => $lesson['id'],
'index' => $lesson['id'],
'align' => 'left',
'search' => 'true',
];
}
$column_model[] = [
'name' => 'total',
'index' => 'total',
'align' => 'left',
'search' => 'true',
];
$action_links = '';
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_session_lp_progress&session_id='.$sessionId.'&course_id='.$courseId.'&date_to='.$date_to.'&date_from='.$date_from;
// Table Id
$tableId = 'lpProgress';
// Autowidth
$extra_params['autowidth'] = 'true';
// height auto
$extra_params['height'] = 'auto';
$table = Display::grid_js(
$tableId,
$url,
$columns,
$column_model,
$extra_params,
[],
$action_links,
true
);
$return = '<script>$(function() {'.$table.
'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
caption:"",
title:"'.get_lang('ExportExcel').'",
onClickButton : function () {
jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
}
});
});</script>';
$return .= Display::grid_html($tableId);
return $return;
}
/**
* Display a sortable table that contains an overview off all the progress of the user in a session.
*
* @param int $sessionId The session ID
* @param int $courseId The course ID
* @param int $exerciseId The quiz ID
* @param $date_from
* @param $date_to
*
* @return string HTML array of results formatted for gridJS
*
* @deprecated ?
*
* @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
*/
public static function display_tracking_exercise_progress_overview(
$sessionId = 0,
$courseId = 0,
$exerciseId = 0,
$date_from = null,
$date_to = null
) {
$date_from = Security::remove_XSS($date_from);
$date_to = Security::remove_XSS($date_to);
/**
* Column names
* The column order is important. Check $column variable in the main/inc/ajax/model.ajax.php file.
*/
$columns = [
get_lang('Session'),
get_lang('ExerciseId'),
get_lang('ExerciseName'),
get_lang('Username'),
get_lang('LastName'),
get_lang('FirstName'),
get_lang('Time'),
get_lang('QuestionId'),
get_lang('QuestionTitle'),
get_lang('WorkDescription'),
get_lang('Answer'),
get_lang('Correct'),
];
/**
* Column config.
*/
$column_model = [
['name' => 'session', 'index' => 'session', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"],
['name' => 'exercise_id', 'index' => 'exercise_id', 'align' => 'left', 'search' => 'true'],
['name' => 'quiz_title', 'index' => 'quiz_title', 'align' => 'left', 'search' => 'true'],
['name' => 'username', 'index' => 'username', 'align' => 'left', 'search' => 'true'],
['name' => 'lastname', 'index' => 'lastname', 'align' => 'left', 'search' => 'true'],
['name' => 'firstname', 'index' => 'firstname', 'align' => 'left', 'search' => 'true'],
['name' => 'time', 'index' => 'time', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"],
['name' => 'question_id', 'index' => 'question_id', 'align' => 'left', 'search' => 'true'],
['name' => 'question', 'index' => 'question', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"],
['name' => 'description', 'index' => 'description', 'align' => 'left', 'width' => '550', 'search' => 'true', 'wrap_cell' => "true"],
['name' => 'answer', 'index' => 'answer', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"],
['name' => 'correct', 'index' => 'correct', 'align' => 'left', 'search' => 'true', 'wrap_cell' => "true"],
];
//get dynamic column names
// jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_progress&session_id='.$sessionId.'&course_id='.$courseId.'&exercise_id='.$exerciseId.'&date_to='.$date_to.'&date_from='.$date_from;
// Autowidth
$extra_params['autowidth'] = 'true';
// height auto
$extra_params['height'] = 'auto';
$tableId = 'exerciseProgressOverview';
$table = Display::grid_js(
$tableId,
$url,
$columns,
$column_model,
$extra_params,
[],
'',
true
);
$return = '<script>$(function() {'.$table.
'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
caption:"",
title:"'.get_lang('ExportExcel').'",
onClickButton : function () {
jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
}
});
});</script>';
$return .= Display::grid_html($tableId);
return $return;
}
/**
* Displays a form with all the additionally defined user fields of the profile
* and give you the opportunity to include these in the CSV export.
*
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
*
* @version 1.8.6
*
* @since November 2008
*/
public static function display_user_overview_export_options()
{
$message = '';
$defaults = [];
// include the user manager and formvalidator library
if (isset($_GET['export']) && 'options' == $_GET['export']) {
// get all the defined extra fields
$extrafields = UserManager::get_extra_fields(
0,
50,
5,
'ASC',
false,
1
);
// creating the form with all the defined extra fields
$form = new FormValidator(
'exportextrafields',
'post',
api_get_self()."?view=".Security::remove_XSS($_GET['view']).'&display='.Security::remove_XSS($_GET['display']).'&export='.Security::remove_XSS($_GET['export'])
);
if (is_array($extrafields) && count($extrafields) > 0) {
foreach ($extrafields as $key => $extra) {
$form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]);
}
$form->addButtonSave(get_lang('Ok'), 'submit');
// setting the default values for the form that contains all the extra fields
$exportFields = Session::read('additional_export_fields');
if (is_array($exportFields)) {
foreach ($exportFields as $key => $value) {
$defaults['extra_export_field'.$value] = 1;
}
}
$form->setDefaults($defaults);
} else {
$form->addElement('html', Display::return_message(get_lang('ThereAreNotExtrafieldsAvailable'), 'warning'));
}
if ($form->validate()) {
// exporting the form values
$values = $form->exportValues();
// re-initialising the session that contains the additional fields that need to be exported
Session::write('additional_export_fields', []);
// adding the fields that are checked to the session
$message = '';
$additionalExportFields = [];
foreach ($values as $field_ids => $value) {
if ($value == 1 && strstr($field_ids, 'extra_export_field')) {
$additionalExportFields[] = str_replace('extra_export_field', '', $field_ids);
}
}
Session::write('additional_export_fields', $additionalExportFields);
// adding the fields that will be also exported to a message string
$additionalExportFields = Session::read('additional_export_fields');
if (is_array($additionalExportFields)) {
foreach ($additionalExportFields as $key => $extra_field_export) {
$message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
}
}
// Displaying a feedback message
if (!empty($additionalExportFields)) {
echo Display::return_message(
get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>',
'confirm',
false
);
} else {
echo Display::return_message(
get_lang('NoAdditionalFieldsWillBeExported'),
'confirm',
false
);
}
} else {
$form->display();
}
} else {
$additionalExportFields = Session::read('additional_export_fields');
if (!empty($additionalExportFields)) {
// get all the defined extra fields
$extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
foreach ($additionalExportFields as $key => $extra_field_export) {
$message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
}
echo Display::return_message(
get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>',
'normal',
false
);
}
}
}
/**
* Display a sortable table that contains an overview of all the reporting progress of all courses.
*/
public static function display_tracking_course_overview()
{
$params = ['view' => 'admin', 'display' => 'courseoverview'];
$table = new SortableTable(
'tracking_session_overview',
['MySpace', 'get_total_number_courses'],
['MySpace', 'get_course_data_tracking_overview'],
1,
20,
'ASC',
null, [
'class' => 'table table-transparent',
]