diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-16 07:41:33 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-16 08:55:26 -0700 |
commit | bc241e44c2e4d10ac19ccc32a40c90426672d963 (patch) | |
tree | aade0e13346a059c061e2f2f4a767e25a45fe17b /modules/user/helpers/group.php | |
parent | 00eacd659f27df9c13246c510057c4f42c8866a2 (diff) |
Cleanup merge of user/group helpers into Identity interface. Reduce redundant code in the user module and remove references to the Identity helper from the user module as the user module should be able to access things directly. Simplify the get_user_list api method to just accept an array of ids to return user objects for.
Diffstat (limited to 'modules/user/helpers/group.php')
-rw-r--r-- | modules/user/helpers/group.php | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 295e5f50..cf5c050f 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -28,7 +28,14 @@ class group_Core { * @see Identity_Driver::create. */ static function create($name) { - return Identity::instance()->create_group($name); + $group = ORM::factory("group")->where("name", $name)->find(); + if ($group->loaded) { + throw new Exception("@todo GROUP_ALREADY_EXISTS $name"); + } + + $group->name = $name; + $group->save(); + return $group; } /** @@ -51,7 +58,7 @@ class group_Core { * @return Group_Definition the group object, or null if the id was invalid. */ static function lookup($id) { - return Identity::instance()->lookup_group_by_field("id", $id); + return self::lookup_by_field("id", $id); } /** @@ -60,20 +67,23 @@ class group_Core { * @return Group_Definition the group object, or null if the name was invalid. */ static function lookup_by_name($name) { - return Identity::instance()->lookup_group_by_field("name", $name); + return self::lookup_by_field("name", $name); } /** * @see Identity_Driver::get_group_list. */ - static function get_group_list($filter=array()) { - return Identity::instance()->get_group_list($filter); - } - - /** - * @see Identity_Driver::get_edit_rules. - */ - static function get_edit_rules() { - return Identity::instance()->get_edit_rules("group"); + static function lookup_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; } } |