diff options
Diffstat (limited to 'app/Model/Comment.php')
-rw-r--r-- | app/Model/Comment.php | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/app/Model/Comment.php b/app/Model/Comment.php index cd361b1d..3aa9c027 100644 --- a/app/Model/Comment.php +++ b/app/Model/Comment.php @@ -2,6 +2,7 @@ namespace Model; +use Event\CommentEvent; use SimpleValidator\Validator; use SimpleValidator\Validators; @@ -46,7 +47,8 @@ class Comment extends Base self::TABLE.'.user_id', self::TABLE.'.comment', User::TABLE.'.username', - User::TABLE.'.name' + User::TABLE.'.name', + User::TABLE.'.email' ) ->join(User::TABLE, 'id', 'user_id') ->orderBy(self::TABLE.'.date', 'ASC') @@ -95,24 +97,22 @@ class Comment extends Base } /** - * Save a comment in the database + * Create a new comment * * @access public * @param array $values Form values - * @return boolean + * @return boolean|integer */ public function create(array $values) { $values['date'] = time(); + $comment_id = $this->persist(self::TABLE, $values); - if ($this->db->table(self::TABLE)->save($values)) { - - $values['id'] = $this->db->getConnection()->getLastId(); - $this->event->trigger(self::EVENT_CREATE, $values); - return true; + if ($comment_id) { + $this->container['dispatcher']->dispatch(self::EVENT_CREATE, new CommentEvent(array('id' => $comment_id) + $values)); } - return false; + return $comment_id; } /** @@ -129,7 +129,9 @@ class Comment extends Base ->eq('id', $values['id']) ->update(array('comment' => $values['comment'])); - $this->event->trigger(self::EVENT_UPDATE, $values); + if ($result) { + $this->container['dispatcher']->dispatch(self::EVENT_UPDATE, new CommentEvent($values)); + } return $result; } |