diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-01-17 12:19:24 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-01-17 12:19:24 -0800 |
commit | 3789b85b7d960a046e4b6de2bbbf82b3e59d2eab (patch) | |
tree | 7d2c70d484640b8ab61b41becf0775b5f332b80b /modules | |
parent | 4f8c98a7bc89911427a6fd97b8ed6ef6f41a2835 (diff) |
Move rules down into validate() and improve valid_author().
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/models/comment.php | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 7ad47c6d..891ffbce 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -18,11 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Comment_Model extends ORM { - var $rules = array( - "text" => array("rules" => array("required")), - "state" => array("rules" => array("Comment_Model::valid_state")) - ); - function item() { return ORM::factory("item", $this->item_id); } @@ -64,8 +59,12 @@ class Comment_Model extends ORM { public function validate($array=null) { // validate() is recursive, only modify the rules on the outermost call. if (!$array) { - $this->rules["item_id"]["callbacks"] = array(array($this, "valid_item")); - $this->rules["guest_name"]["callbacks"] = array(array($this, "valid_author")); + $this->rules = array( + "guest_name" => array("callbacks" => array(array($this, "valid_author"))), + "item_id" => array("callbacks" => array(array($this, "valid_item"))), + "state" => array("rules" => array("Comment_Model::valid_state")), + "text" => array("rules" => array("required")), + ); } parent::validate($array); @@ -134,7 +133,9 @@ class Comment_Model extends ORM { * Make sure we have an appropriate author id set, or a guest name. */ public function valid_author(Validation $v, $field) { - if ($this->author_id == identity::guest()->id && empty($this->guest_name)) { + if (empty($this->author_id)) { + $v->add_error("author_id", "required"); + } else if ($this->author_id == identity::guest()->id && empty($this->guest_name)) { $v->add_error("guest_name", "required"); } } |