summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/comment/helpers/comment.php6
-rw-r--r--modules/comment/models/comment.php2
-rw-r--r--modules/user/controllers/user.php52
-rw-r--r--modules/user/helpers/user.php19
-rw-r--r--modules/user/models/user.php2
5 files changed, 28 insertions, 53 deletions
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 1c876f10..8352fae4 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -61,8 +61,7 @@ class Comment_Core {
$group->input("email") ->label(_("Email")) ->id("gEmail");
$group->textarea("text")->label(_("Text")) ->id("gText");
$group->submit(_("Add"));
-
- comment::_add_validation_rules("comment", $form);
+ $form->add_rules_from(ORM::factory("comment"));
return $form;
}
@@ -73,8 +72,7 @@ class Comment_Core {
$group->input("email") ->label(_("Email")) ->id("gEmail") ->value($comment->email);
$group->textarea("text")->label(_("Text")) ->id("gText") ->value($comment->text);
$group->submit(_("Edit"));
-
- comment::_add_validation_rules("comment", $form);
+ $form->add_rules_from($comment);
return $form;
}
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 2ed2b83c..b1eb37b7 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Comment_Model extends ORM {
- var $validation_rules = array(
+ var $rules = array(
"author" => "required",
"email" => "required|valid_email",
"text" => "required");
diff --git a/modules/user/controllers/user.php b/modules/user/controllers/user.php
index d3370dbe..c1794af3 100644
--- a/modules/user/controllers/user.php
+++ b/modules/user/controllers/user.php
@@ -21,57 +21,19 @@ class User_Controller extends REST_Controller {
protected $resource_type = "user";
/**
- * Return the form for creating / modifying users.
+ * Present a form for editing a user
+ * @see Rest_Controller::form($resource)
*/
- private function _get_form($user) {
- $form = new Forge(url::current(true), "", "post", array("id" => "gUser"));
- $group = $form->group(_("User Info"));
- $group->input("name")
- ->label(_("Name"))
- ->id("gName")
- ->class(null)
- ->value($user->name);
- $group->input("display_name")
- ->label(_("Display Name"))
- ->id("gDisplayName")
- ->class(null)
- ->value($user->display_name);
- $group->password("password")
- ->label(_("Password"))
- ->id("gPassword")
- ->class(null);
- $group->input("email")
- ->label(_("Email"))
- ->id("gEmail")
- ->class(null)
- ->value($user->email);
- $group->submit(_("Modify"));
-
- $this->_add_validation_rules(ORM::factory("user")->validation_rules, $form);
-
- return $form;
- }
-
- /**
- * @todo Refactor this into a more generic location
- */
- private function _add_validation_rules($rules, $form) {
- foreach ($form->inputs as $name => $input) {
- if (isset($input->inputs)) {
- $this->_add_validation_rules($rules, $input);
- }
- if (isset($rules[$name])) {
- $input->rules($rules[$name]);
- }
- }
+ public function _form($user) {
+ $form = user::get_edit_form($user);
+ print $form->render();
}
/**
* @see Rest_Controller::_get($resource)
*/
public function _get($user) {
- $form = $this->_get_form($user);
- print $form->render("form.html");
+ throw new Exception("@todo User_Controller::_get NOT IMPLEMENTED");
}
/**
@@ -85,7 +47,7 @@ class User_Controller extends REST_Controller {
* @see Rest_Controller::_post($resource)
*/
public function _post($user) {
- $form = $this->_get_form($user);
+ $form = user::get_edit_form($user);
if ($form->validate()) {
foreach ($form->as_array() as $key => $value) {
$user->$key = $value;
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index aaf16299..8ad2709f 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -19,14 +19,29 @@
*/
/**
- * This helper provides a common around the user management functions.
- *
+ * This helper provides a common around the user management functions.
+ *
* @author Tim Almdal <public@timalmdal.com>
*
*/
class user {
/**
+ * Return the form for creating / modifying users.
+ */
+ public static function get_edit_form($user) {
+ $form = new Forge(url::site("user/{$user->id}"), "", "post", array("id" => "gUserForm"));
+ $group = $form->group(_("User Info"));
+ $group->input("name") ->label(_("Name")) ->id("gName") ->value($user->name);
+ $group->input("display_name") ->label(_("Display Name")) ->id("gDisplayName") ->value($user->display_name);
+ $group->password("password") ->label(_("Password")) ->id("gPassword");
+ $group->input("email") ->label(_("Email")) ->id("gEmail") ->value($user->email);
+ $group->submit(_("Modify"));
+ $form->add_rules_from($user);
+ return $form;
+ }
+
+ /**
* Is the password provided correct?
*
* @param user User Model
diff --git a/modules/user/models/user.php b/modules/user/models/user.php
index 1c56b34e..5c88d8dc 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -20,7 +20,7 @@
class User_Model extends ORM {
protected $has_and_belongs_to_many = array("groups");
- var $validation_rules = array(
+ var $rules = array(
"name" => "required|length[4,32]",
"email" => "valid_email",
"password" => "required|length[5,40]");