From 5d5f165e26a3ac87ff69e268ac20164191eec102 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Tue, 22 Jun 2021 22:59:05 +1000 Subject: [PATCH] MDL-69498 admin: Group site admins by email domain --- admin/roles/classes/admins_existing_selector.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/admin/roles/classes/admins_existing_selector.php b/admin/roles/classes/admins_existing_selector.php index 93899198ee0a7..bae7b82cac66f 100644 --- a/admin/roles/classes/admins_existing_selector.php +++ b/admin/roles/classes/admins_existing_selector.php @@ -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); @@ -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;