-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_curse_users.php
134 lines (96 loc) · 4.27 KB
/
list_curse_users.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
<?php
require_once("config.php");
require_once($CFG->dirroot . '/course/lib.php');
//Teles
use core_table\local\filter\filter;
use core_table\local\filter\integer_filter;
use core_table\local\filter\string_filter;
use core_user\table\participants;
//Teles
function send_course_user_roles_to_file(){
global $DB,$PAGE;
$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
$context = context_course::instance($id);
$PAGE->set_context($context);
$userids = optional_param_array('userid', array(), PARAM_INT);
if (empty($userids)) {
// The first time list hack.
if (empty($userids) and $post = data_submitted()) {//ha ures az $userids akkor azt a postból fogja megkapni // user1,user2
foreach ($post as $k => $v) {
if (preg_match('/^user(\d+)$/', $k, $m)) {
$userids[] = $m[1];
}
}
}
}
$coursecontext = context_course::instance($id);
$users = get_enrolled_users($coursecontext,'',0,'u.id');
foreach($users as $key=>$value){
$userids[] = $key;
}
$columnnames = array(
'course_short_name'=>'course_short_name',
'course_id'=>'course_id',
'neptun_id' => "neptun_id",
);
$identityfields = get_extra_user_fields($context);
$identityfieldsselect = '';
foreach ($identityfields as $field) {
//$columnnames[$field] = get_string($field);
//$identityfieldsselect .= ', u.' . $field . ' ';
}
$columnnames['roles'] = "Roles";
if (!empty($userids)) {
list($insql, $inparams) = $DB->get_in_or_equal($userids);
}
$sql = "SELECT u.id,u.username,u.firstname, u.lastname" . $identityfieldsselect . "
FROM {user} u
WHERE u.id $insql";
//Teles
$records = $DB->get_records_sql($sql,$inparams);
$participanttable = new \core_user\table\participants("user-index-participants-{$course->id}");
$filterset = new \core_user\table\participants_filterset();
$filterset->add_filter(new integer_filter('courseid', filter::JOINTYPE_DEFAULT, [(int)$course->id]));
//$participanttable->out_without_html_table(20, true,true);
ob_start();
$participanttable->set_filterset($filterset);
//$participanttable->out_without_html_table(2000,true);
$participanttable->out(2000,true);
ob_end_clean();
print_object($participanttable);
foreach($records as $record){
unset($record->firstname);
unset($record->lastname);
$temp = $record->username;
unset($record->username);
$record->course_short_name = $course->shortname;
$record->username = $temp;
$record->fullname = fullname($DB->get_record('user',['id'=>$record->id]));
$record->roles = null;
$record->roles .= '[';
foreach($participanttable->public_allroleassignments[$record->id] as $allroleassignment){
/*if(!(end($allroleassignment))){
$r->roles .= $allroleassignment->shortname.',';
}else{
$r->roles .= $allroleassignment->shortname;
}*/
$record->roles .= $allroleassignment->shortname.' ';
}
unset($record->id);
$record->roles = trim($record->roles);
$record->roles = str_replace(" ",",",$record->roles);
$record->roles .= ']';
print_object($record);
}
$line = null;
foreach ($records as $record) {
foreach($record as $key=>$value){
$line.= $value.',';
}
$line = substr($line, 0, -1);
$line.="<br>";
}
print($line);
}
send_course_user_roles_to_file();