From 3300404912867f551f84b2deea0f603e186ebc61 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Mon, 30 Aug 2010 16:59:08 +1200 Subject: [PATCH] Add a getUserByEMail() function. --- htdocs/always.php | 18 ++++++++++++++++++ inc/always.php.in | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/htdocs/always.php b/htdocs/always.php index 0882bdb3..c2b15245 100644 --- a/htdocs/always.php +++ b/htdocs/always.php @@ -245,6 +245,24 @@ function getUserByName( $username, $use_cache = true ) { } +/** +* Return a user record identified by e-mail address, caching it for any subsequent lookup +* @param string $email The email address of the user record to retrieve +* @param boolean $use_cache Whether or not to use the cache (default: yes) +*/ +function getUserByEMail( $email, $use_cache = true ) { + global $_known_users_name; + + if ( $use_cache ) { + /** We don't actually maintain a cache-access by e-mail, since it's rare */ + foreach( $_known_users_name AS $k => $v ) { + if ( strtolower($email) == strtolower($v->email) ) return $v; + } + } + return _davical_get_principal_query_cached( 'lower(email) = lower(:param)', $email ); +} + + /** * Return a user record identified by a user_no, caching it for any subsequent lookup * @param int $user_no The ID of the record to retrieve diff --git a/inc/always.php.in b/inc/always.php.in index 2585bae7..58b97f32 100644 --- a/inc/always.php.in +++ b/inc/always.php.in @@ -245,6 +245,24 @@ function getUserByName( $username, $use_cache = true ) { } +/** +* Return a user record identified by e-mail address, caching it for any subsequent lookup +* @param string $email The email address of the user record to retrieve +* @param boolean $use_cache Whether or not to use the cache (default: yes) +*/ +function getUserByEMail( $email, $use_cache = true ) { + global $_known_users_name; + + if ( $use_cache ) { + /** We don't actually maintain a cache-access by e-mail, since it's rare */ + foreach( $_known_users_name AS $k => $v ) { + if ( strtolower($email) == strtolower($v->email) ) return $v; + } + } + return _davical_get_principal_query_cached( 'lower(email) = lower(:param)', $email ); +} + + /** * Return a user record identified by a user_no, caching it for any subsequent lookup * @param int $user_no The ID of the record to retrieve