From 8e1ab75530b2085ed5ae67e714c624b06cae3695 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 14 Oct 2009 21:07:19 -0700 Subject: Recreate group::lookup that somehow got removed. --- modules/gallery/helpers/group.php | 31 ++++++++++++++++++++++++++++--- modules/gallery/helpers/user.php | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/group.php b/modules/gallery/helpers/group.php index fbc5157d..dbfa03fe 100644 --- a/modules/gallery/helpers/group.php +++ b/modules/gallery/helpers/group.php @@ -60,15 +60,40 @@ class group_Core { return model_cache::get("group", 2); } + /** + * Look up a user by id. + * @param integer $id the user id + * @return User_Model the user object, or null if the id was invalid. + */ + static function lookup($id) { + return self::_lookup_group_by_field("id", $id); + } + /** * Look up a group by name. * @param integer $id the group name * @return Group_Model the group object, or null if the name was invalid. */ static function lookup_by_name($name) { - $group = model_cache::get("group", $name, "name"); - if ($group->loaded) { - return $group; + return self::_lookup_group_by_field("name", $name); + } + + /** + * Look up a user by field value. + * @param string search field + * @param string search value + * @return Group_Model the user object, or null if the name was invalid. + */ + private static function _lookup_group_by_field($field_name, $value) { + try { + $user = model_cache::get("group", $value, $field_name); + if ($user->loaded) { + return $user; + } + } catch (Exception $e) { + if (strpos($e->getMessage(), "MISSING_MODEL") === false) { + throw $e; + } } return null; } diff --git a/modules/gallery/helpers/user.php b/modules/gallery/helpers/user.php index 7aa990e1..cb205170 100644 --- a/modules/gallery/helpers/user.php +++ b/modules/gallery/helpers/user.php @@ -351,7 +351,7 @@ class user_Core { * @param string search value * @return User_Core the user object, or null if the name was invalid. */ - private static function _lookup_user_by_field($field_name, $value) { + private static function _lookup_user_by_field($field_name, $value) { try { $user = model_cache::get("user", $value, $field_name); if ($user->loaded) { -- cgit v1.2.3