MDL-14978 removed obsoleted get_course_students()
This commit is contained in:
@@ -203,133 +203,6 @@ function get_recent_enrolments($courseid, $timestart) {
|
||||
ORDER BY l.time ASC");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of userinfo of all students in this course
|
||||
* or on this site if courseid is id of site
|
||||
*
|
||||
* @uses $CFG
|
||||
* @uses SITEID
|
||||
* @param int $courseid The course in question.
|
||||
* @param string $sort ?
|
||||
* @param string $dir ?
|
||||
* @param int $page ?
|
||||
* @param int $recordsperpage ?
|
||||
* @param string $firstinitial ?
|
||||
* @param string $lastinitial ?
|
||||
* @param ? $group ?
|
||||
* @param string $search ?
|
||||
* @param string $fields A comma separated list of fields to be returned from the chosen table.
|
||||
* @param string $exceptions ?
|
||||
* @return object
|
||||
* @todo Finish documenting this function
|
||||
*/
|
||||
function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='', $recordsperpage='',
|
||||
$firstinitial='', $lastinitial='', $group=NULL, $search='', $fields='', $exceptions='') {
|
||||
|
||||
global $CFG;
|
||||
|
||||
// make sure it works on the site course
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
|
||||
/// For the site course, old way was to check if $CFG->allusersaresitestudents was set to true.
|
||||
/// The closest comparible method using roles is if the $CFG->defaultuserroleid is set to the legacy
|
||||
/// student role. This function should be replaced where it is used with something more meaningful.
|
||||
if (($courseid == SITEID) && !empty($CFG->defaultuserroleid) && empty($CFG->nodefaultuserrolelists)) {
|
||||
if ($roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW, $context)) {
|
||||
$hascap = false;
|
||||
foreach ($roles as $role) {
|
||||
if ($role->id == $CFG->defaultuserroleid) {
|
||||
$hascap = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hascap) {
|
||||
// return users with confirmed, undeleted accounts who are not site teachers
|
||||
// the following is a mess because of different conventions in the different user functions
|
||||
$sort = str_replace('s.timeaccess', 'lastaccess', $sort); // site users can't be sorted by timeaccess
|
||||
$sort = str_replace('timeaccess', 'lastaccess', $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
|
||||
$fields = str_replace('u.', '', $fields);
|
||||
if ($sort) {
|
||||
$sort = $sort .' '. $dir;
|
||||
}
|
||||
// Now we have to make sure site teachers are excluded
|
||||
|
||||
$exceptions = array();
|
||||
if ($teachers = get_course_teachers(SITEID)) {
|
||||
foreach ($teachers as $teacher) {
|
||||
$exceptions[] = $teacher->userid;
|
||||
}
|
||||
}
|
||||
|
||||
return get_users(true, $search, true, $exceptions, $sort, $firstinitial, $lastinitial,
|
||||
$page, $recordsperpage, $fields ? $fields : '*');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$LIKE = sql_ilike();
|
||||
$fullname = sql_fullname('u.firstname','u.lastname');
|
||||
|
||||
$groupmembers = '';
|
||||
|
||||
$select = "c.contextlevel=".CONTEXT_COURSE." AND "; // Must be on a course
|
||||
if ($courseid != SITEID) {
|
||||
// If not site, require specific course
|
||||
$select.= "c.instanceid=$courseid AND ";
|
||||
}
|
||||
$select.="rc.capability='moodle/legacy:student' AND rc.permission=".CAP_ALLOW." AND ";
|
||||
|
||||
$select .= ' u.deleted = \'0\' ';
|
||||
|
||||
if (!$fields) {
|
||||
$fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, '.
|
||||
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.city, '.
|
||||
'u.country, u.picture, u.idnumber, u.department, u.institution, '.
|
||||
'u.emailstop, u.lang, u.timezone, ul.timeaccess as lastaccess';
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$search = ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\') ';
|
||||
}
|
||||
|
||||
if ($firstinitial) {
|
||||
$select .= ' AND u.firstname '. $LIKE .'\''. $firstinitial .'%\' ';
|
||||
}
|
||||
|
||||
if ($lastinitial) {
|
||||
$select .= ' AND u.lastname '. $LIKE .'\''. $lastinitial .'%\' ';
|
||||
}
|
||||
|
||||
if ($group === 0) { /// Need something here to get all students not in a group
|
||||
return array();
|
||||
|
||||
} else if ($group !== NULL) {
|
||||
$groupmembers = "INNER JOIN {$CFG->prefix}groups_members gm on u.id=gm.userid";
|
||||
$select .= ' AND gm.groupid = \''. $group .'\'';
|
||||
}
|
||||
|
||||
if (!empty($exceptions)) {
|
||||
$select .= ' AND u.id NOT IN ('. $exceptions .')';
|
||||
}
|
||||
|
||||
if ($sort) {
|
||||
$sort = ' ORDER BY '. $sort .' ';
|
||||
}
|
||||
|
||||
$students = get_records_sql("SELECT $fields
|
||||
FROM {$CFG->prefix}user u INNER JOIN
|
||||
{$CFG->prefix}role_assignments ra on u.id=ra.userid INNER JOIN
|
||||
{$CFG->prefix}role_capabilities rc ON ra.roleid=rc.roleid INNER JOIN
|
||||
{$CFG->prefix}context c ON c.id=ra.contextid LEFT OUTER JOIN
|
||||
{$CFG->prefix}user_lastaccess ul on ul.userid=ra.userid
|
||||
$groupmembers
|
||||
WHERE $select $search $sort $dir", $page, $recordsperpage);
|
||||
|
||||
return $students;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns list of all teachers in this course
|
||||
*
|
||||
|
||||
+1
-2
@@ -565,8 +565,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) {
|
||||
/// If the user is an editing teacher, or a non-editing teacher not assigned to a group, show all student
|
||||
/// wikis, regardless of creation.
|
||||
if ((SITEID != $course->id) and ($isteacheredit or ($groupmode == NOGROUPS))) {
|
||||
|
||||
if ($students = get_course_students($course->id)) {
|
||||
if ($students = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'moodle/course:view', '', '', '', '', '', '', false)) {
|
||||
/// Default pagename is dependent on the wiki settings.
|
||||
$defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user