Commit 588126aa authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review

Merge "Add a function to turn a list of usernames into ids"

parents d62429dc ad2e892a
......@@ -2197,3 +2197,22 @@ function get_onlineusers($limit=10, $offset=0, $orderby='firstname,lastname') {
return $result;
}
/**
* Get a list of userids from a list of usernames
*
* @param $usernames array list of usernames
*
* @returns array list of userids
*/
function username_to_id($usernames) {
if (!empty($usernames)) {
$ids = get_records_sql_menu('
SELECT username, id FROM {usr}
WHERE deleted = 0
AND LOWER(username) IN (' . join(',', array_fill(0, count($usernames), '?')) . ')',
array_map('strtolower', $usernames)
);
}
return empty($ids) ? array() : $ids;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment