made get_course_users and similar functions work also for the site course
This commit is contained in:
+20
-4
@@ -1106,7 +1106,8 @@ function get_recent_enrolments($courseid, $timestart) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of all students in this course
|
||||
* Returns array of userinfo of all students in this course
|
||||
* or on this site if courseid is id of site
|
||||
*
|
||||
* @param type description
|
||||
*/
|
||||
@@ -1115,6 +1116,16 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
|
||||
|
||||
global $CFG;
|
||||
|
||||
$site = get_site();
|
||||
if ($courseid == $site->id) {
|
||||
$sort = str_replace('s.timeaccess', '', $sort); // site users can't be sorted by timeaccess
|
||||
$sort = str_replace('u.', '', $sort); // the get_user function doesn't use the u. prefix to fields
|
||||
if ($sort) {
|
||||
$sort = "$sort $dir";
|
||||
}
|
||||
return get_users(true, $search, true, '', $sort, $firstinitial, $lastinitial, $page, $recordsperpage);
|
||||
}
|
||||
|
||||
switch ($CFG->dbtype) {
|
||||
case "mysql":
|
||||
$fullname = " CONCAT(firstname,\" \",lastname) ";
|
||||
@@ -1169,7 +1180,7 @@ function get_course_students($courseid, $sort="s.timeaccess", $dir="", $page=0,
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the students in a given course, or a subset of them
|
||||
* Counts the students in a given course (or site), or a subset of them
|
||||
*
|
||||
* @param type description
|
||||
*/
|
||||
@@ -1177,6 +1188,10 @@ function count_course_students($course, $search="", $firstinitial="", $lastiniti
|
||||
|
||||
global $CFG;
|
||||
|
||||
if (!$course->category) {
|
||||
return get_users(false, $search, true, '', '', $firstinitial, $lastinitial);
|
||||
}
|
||||
|
||||
switch ($CFG->dbtype) {
|
||||
case "mysql":
|
||||
$fullname = " CONCAT(firstname,\" \",lastname) ";
|
||||
@@ -1217,7 +1232,8 @@ function count_course_students($course, $search="", $firstinitial="", $lastiniti
|
||||
|
||||
|
||||
/**
|
||||
* Returns list of all teachers in this course
|
||||
* Returns list of all teachers in this course
|
||||
* (also works for site)
|
||||
*
|
||||
* @param type description
|
||||
*/
|
||||
@@ -1246,7 +1262,7 @@ function get_course_users($courseid, $sort="timeaccess DESC") {
|
||||
$site = get_site();
|
||||
|
||||
if ($courseid == $site->id) {
|
||||
return get_site_users();
|
||||
return get_users(true, '', true, '', $sort);
|
||||
}
|
||||
|
||||
/// Using this method because the single SQL just would not always work!
|
||||
|
||||
@@ -560,8 +560,20 @@ function iscreator ($userid=0) {
|
||||
|
||||
function isstudent($courseid, $userid=0) {
|
||||
/// Is the user a student in this course?
|
||||
/// If course is site, is the user a confirmed user on the site?
|
||||
global $USER;
|
||||
|
||||
$site = get_site();
|
||||
if ($courseid == $site->id) {
|
||||
if (!$userid) {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
if (isguest($userid)) {
|
||||
return false;
|
||||
}
|
||||
return record_exists('user', 'id', $userid, 'confirmed', 1, 'deleted', 0);
|
||||
}
|
||||
|
||||
if (!$userid) {
|
||||
return !empty($USER->student[$courseid]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user