From 53af7e3173bd8af841a3d77f3ec348cd474299c2 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 30 Apr 2021 07:57:27 +0200 Subject: [PATCH] add methods cmp_user_login() and cmp_user_fullname() --- inc/inc.Utils.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 82bee8308..9492e45d4 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -778,6 +778,44 @@ function createNonce() { /* {{{ */ return base64_encode($bytes); } /* }}} */ +/** + * Compare function for sorting users by login + * + * Use this for usort() + * + * + * $users = $dms->getAllUsers(); + * usort($users, 'cmp_user_login'); + * + */ +function cmp_user_login($a, $b) { /* {{{ */ + $as = strtolower($a->getLogin()); + $bs = strtolower($b->getLogin()); + if ($as == $bs) { + return 0; + } + return ($as < $bs) ? -1 : 1; +} /* }}} */ + +/** + * Compare function for sorting users by name + * + * Use this for usort() + * + * + * $users = $dms->getAllUsers(); + * usort($users, 'cmp_user_fullname'); + * + */ +function cmp_user_fullname($a, $b) { /* {{{ */ + $as = strtolower($a->getFullName()); + $bs = strtolower($b->getFullName()); + if ($as == $bs) { + return 0; + } + return ($as < $bs) ? -1 : 1; +} /* }}} */ + /** * Returns the mandatory reviewers *