Skip to content

Commit

Permalink
Merge branch 'MDL-69498-group-admin-by-domain' of https://github.com/…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jun 24, 2021
2 parents fa0ce04 + 5d5f165 commit b10ac1a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions admin/roles/classes/admins_existing_selector.php
Expand Up @@ -57,7 +57,10 @@ public function find_users($search) {

list($sort, $sortparams) = users_order_by_sql('', $search, $this->accesscontext);
$params = array_merge($params, $sortparams);
$order = ' ORDER BY ' . $sort;

// Sort first by email domain and then by normal name order.
$order = " ORDER BY " . $DB->sql_substr('email', $DB->sql_position("'@'", 'email'),
$DB->sql_length('email') ) . ", $sort";

$availableusers = $DB->get_records_sql($fields . $sql . $order, $params);

Expand All @@ -80,10 +83,15 @@ public function find_users($search) {
if ($availableusers) {
if ($search) {
$groupname = get_string('extusersmatching', 'core_role', $search);
$result[$groupname] = $availableusers;
} else {
$groupname = get_string('extusers', 'core_role');
$groupnameprefix = get_string('extusers', 'core_role');
foreach ($availableusers as $user) {
$domain = substr($user->email, strpos($user->email, '@'));
$groupname = "$groupnameprefix $domain";
$result[$groupname][] = $user;
}
}
$result[$groupname] = $availableusers;
}

return $result;
Expand Down

0 comments on commit b10ac1a

Please sign in to comment.