diff options
| author | Andy Staudacher <andy.st@gmail.com> | 2009-11-15 19:44:47 -0800 |
|---|---|---|
| committer | Andy Staudacher <andy.st@gmail.com> | 2009-11-15 19:44:47 -0800 |
| commit | 0733dc37fda27a5ba35f9020edf3c66aa41a95a0 (patch) | |
| tree | 6877946232f1b01b1c8709054c689f6658cef34f /modules/user/helpers/group.php | |
| parent | 218493c50be9362d4abed6900a816308fee5d978 (diff) | |
| parent | 9379308f91a476f790fb8d444536719535c584e4 (diff) | |
Merge commit 'upstream/master'
Conflicts:
modules/gallery/tests/xss_data.txt
Diffstat (limited to 'modules/user/helpers/group.php')
| -rw-r--r-- | modules/user/helpers/group.php | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php index 04e6efd6..3aaf1b11 100644 --- a/modules/user/helpers/group.php +++ b/modules/user/helpers/group.php @@ -28,7 +28,7 @@ class group_Core { * Create a new group. * * @param string $name - * @return Group_Model + * @return Group_Definition the group object */ static function create($name) { $group = ORM::factory("group")->where("name", $name)->find(); @@ -38,14 +38,13 @@ class group_Core { $group->name = $name; $group->save(); - return $group; } /** * The group of all possible visitors. This includes the guest user. * - * @return Group_Model + * @return Group_Definition the group object */ static function everybody() { return model_cache::get("group", 1); @@ -54,54 +53,47 @@ class group_Core { /** * The group of all logged-in visitors. This does not include guest users. * - * @return Group_Model + * @return Group_Definition the group object */ static function registered_users() { return model_cache::get("group", 2); } /** + * Look up a group by id. + * @param integer $id the user id + * @return Group_Definition the group object, or null if the id was invalid. + */ + static function lookup($id) { + return self::_lookup_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. + * @return Group_Definition 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 null; + return self::_lookup_by_field("name", $name); } - static function get_edit_form_admin($group) { - $form = new Forge("admin/users/edit_group/$group->id", "", "post", array("id" => "gEditGroupForm")); - $form_group = $form->group("edit_group")->label(t("Edit Group")); - $form_group->input("name")->label(t("Name"))->id("gName")->value($group->name); - $form_group->inputs["name"]->error_messages( - "in_use", t("There is already a group with that name")); - $form_group->submit("")->value(t("Save")); - $form->add_rules_from($group); - return $form; - } - - static function get_add_form_admin() { - $form = new Forge("admin/users/add_group", "", "post", array("id" => "gAddGroupForm")); - $form_group = $form->group("add_group")->label(t("Add Group")); - $form_group->input("name")->label(t("Name"))->id("gName"); - $form_group->inputs["name"]->error_messages( - "in_use", t("There is already a group with that name")); - $form_group->submit("")->value(t("Add Group")); - $group = ORM::factory("group"); - $form->add_rules_from($group); - return $form; - } - - static function get_delete_form_admin($group) { - $form = new Forge("admin/users/delete_group/$group->id", "", "post", - array("id" => "gDeleteGroupForm")); - $form_group = $form->group("delete_group")->label( - t("Are you sure you want to delete group %group_name?", array("group_name" => $group->name))); - $form_group->submit("")->value(t("Delete")); - return $form; + /** + * Search the groups by the field and value. + * @param string $field_name column to look up the user by + * @param string $value value to match + * @return Group_Definition the group object, or null if the name was invalid. + */ + private 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; } } |
