mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-12451, in get_users_by_capability(), defaultroleid bit fixes
This commit is contained in:
parent
cecac3b37c
commit
176058849a
@ -4212,14 +4212,26 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
|
||||
$view=false, $useviewallgroups=false) {
|
||||
global $CFG;
|
||||
|
||||
/// check for front page course, and see if default front page role has the required capability
|
||||
/// Sorting out exceptions
|
||||
$exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
|
||||
|
||||
/// check for front page course, and see if default front page role has the required capability
|
||||
/// if it does, we can just return all users, and we do not need to check further, just return all users
|
||||
|
||||
// TODO This bit will break if $fields, $sort or sort are not passed in, and also it ignores $exceptions. There may be other problems too.
|
||||
$frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
|
||||
if (!empty($CFG->defaultfrontpageroleid) && ($context->id == $frontpagectx->id || strstr($context->path, '/'.$frontpagectx->id.'/'))) {
|
||||
|
||||
$roles = get_roles_with_capability($capability, CAP_ALLOW, $context);
|
||||
// if this condition is satisfied, then everyone is selected, no need to check further
|
||||
if (in_array($CFG->defaultfrontpageroleid, array_keys($roles))) {
|
||||
return get_records_sql("SELECT $fields FROM {$CFG->prefix}user u ORDER BY $sort", $limitfrom, $limitnum);
|
||||
if (empty($fields)) {
|
||||
$fields = 'u.*';
|
||||
}
|
||||
|
||||
if (empty($sort)) {
|
||||
$sort = 'u.lastaccess';
|
||||
}
|
||||
return get_records_sql("SELECT $fields FROM {$CFG->prefix}user u $exceptionsql ORDER BY $sort", $limitfrom, $limitnum);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4245,9 +4257,6 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
|
||||
$groupsql = '';
|
||||
}
|
||||
|
||||
/// Sorting out exceptions
|
||||
$exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
|
||||
|
||||
/// Set up default fields
|
||||
if (empty($fields)) {
|
||||
$fields = 'u.*, ul.timeaccess as lastaccess, ra.hidden';
|
||||
|
Loading…
x
Reference in New Issue
Block a user