From 9eeded33f68872515954a2fc177fcb47a9273ae9 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 15 Aug 2014 17:23:41 -0700 Subject: Add email notifications --- app/Model/Comment.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'app/Model/Comment.php') diff --git a/app/Model/Comment.php b/app/Model/Comment.php index b5102070..b849fc23 100644 --- a/app/Model/Comment.php +++ b/app/Model/Comment.php @@ -20,6 +20,14 @@ class Comment extends Base */ const TABLE = 'comments'; + /** + * Events + * + * @var string + */ + const EVENT_UPDATE = 'comment.update'; + const EVENT_CREATE = 'comment.create'; + /** * Get all comments for a given task * @@ -95,7 +103,14 @@ class Comment extends Base { $values['date'] = time(); - return $this->db->table(self::TABLE)->save($values); + if ($this->db->table(self::TABLE)->save($values)) { + + $values['id'] = $this->db->getConnection()->getLastId(); + $this->event->trigger(self::EVENT_CREATE, $values); + return true; + } + + return false; } /** @@ -107,10 +122,14 @@ class Comment extends Base */ public function update(array $values) { - return $this->db + $result = $this->db ->table(self::TABLE) ->eq('id', $values['id']) ->update(array('comment' => $values['comment'])); + + $this->event->trigger(self::EVENT_UPDATE, $values); + + return $result; } /** -- cgit v1.2.3