summaryrefslogtreecommitdiff
path: root/modules/user/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user/helpers')
-rw-r--r--modules/user/helpers/group.php35
-rw-r--r--modules/user/helpers/user.php17
2 files changed, 48 insertions, 4 deletions
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index 98947794..f32e37dc 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -31,7 +31,7 @@ class group_Core {
* @return Group_Model
*/
static function create($name) {
- $group = ORM::factory("group")->where("name", $name);
+ $group = ORM::factory("group")->where("name", $name)->find();
if ($group->loaded) {
throw new Exception("@todo GROUP_ALREADY_EXISTS $name");
}
@@ -64,4 +64,37 @@ class group_Core {
static function registered_users() {
return ORM::factory("group", 2);
}
+
+ /**
+ * This is the API for handling groups.
+ * @TODO incorporate rules!
+ */
+ public static function get_edit_form($group, $action = NULL) {
+ $form = new Forge($action);
+ $form_group = $form->group("edit_group")->label(_("Edit Group"));
+ $form_group->input("gname")->label(_("Name"))->id("gName")->value($group->name);
+ $form_group->submit(_("Modify"));
+ $form->add_rules_from($group);
+ $form->edit_group->gname->rules($group->rules["name"]);
+ return $form;
+ }
+
+ public static function get_add_form($action = NULL) {
+ $form = new Forge($action);
+ $form_group = $form->group("add_group")->label(_("Add Group"));
+ $form_group->input("gname")->label(_("Name"))->id("gName");
+ $form_group->submit(_("Create"));
+ $group = ORM::factory("group");
+ $form->add_rules_from($group);
+ $form->add_group->gname->rules($group->rules["name"]);
+ return $form;
+ }
+
+ public static function get_delete_form($group, $action = NULL) {
+ $form = new Forge($action);
+ $form_group = $form->group("delete_group")->label(_("Delete Group"));
+ $form_group->label(_("Are you sure you want to delete " . $group->name . "?"));
+ $form_group->submit(_("Delete"));
+ return $form;
+ }
} \ No newline at end of file
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 0f5520e7..9ffcebfc 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -24,7 +24,7 @@
* Note: by design, this class does not do any permission checking.
*/
class user_Core {
- public static function get_edit_form($user, $action) {
+ public static function get_edit_form($user, $action = NULL) {
$form = new Forge($action, "", "post", array("id" => "gUserForm"));
$group = $form->group("edit_user")->label(_("Edit User"));
$group->input("uname")->label(_("Name"))->id("gName")->value($user->name);
@@ -33,18 +33,29 @@ class user_Core {
$group->input("email")->label(_("Email"))->id("gEmail")->value($user->email);
$group->submit(_("Modify"));
$form->add_rules_from($user);
+ $form->edit_user->uname->rules($user->rules["name"]);
return $form;
}
- public static function get_add_form($user, $action) {
- $form = new Forge($action, "", "post", array("id" => "gUserAddForm"));
+ public static function get_add_form($action = NULL) {
+ $form = new Forge($action);
$group = $form->group("add_user")->label(_("Add User"));
$group->input("uname")->label(_("Name"))->id("gName");
$group->input("full_name")->label(_("Full Name"))->id("gFullName");
$group->password("password")->label(_("Password"))->id("gPassword");
$group->input("email")->label(_("Email"))->id("gEmail");
$group->submit(_("Add"));
+ $user = ORM::factory("user");
$form->add_rules_from($user);
+ $form->add_user->uname->rules($user->rules["name"]);
+ return $form;
+ }
+
+ public static function get_delete_form($user, $action = NULL) {
+ $form = new Forge($action);
+ $group = $form->group("delete_user")->label(_("Delete User"));
+ $group->label(_("Are you sure you want to delete " . $user->name . "?"));
+ $group->submit(_("Delete"));
return $form;
}
/**