Skip to content

Commit

Permalink
MDL-69498 admin: Group site admins by email domain
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood committed Jun 23, 2021
1 parent 338b60f commit 5d5f165
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions admin/roles/classes/admins_existing_selector.php
Original file line number Diff line number Diff line change
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 5d5f165

Please sign in to comment.