From d9101da79e839984e0e782b48113dc61157d6688 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 26 May 2016 20:50:50 -0400 Subject: Mark notification as read when clicking on it --- app/Model/UserUnreadNotification.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'app/Model/UserUnreadNotification.php') diff --git a/app/Model/UserUnreadNotification.php b/app/Model/UserUnreadNotification.php index cc0f326a..42893666 100644 --- a/app/Model/UserUnreadNotification.php +++ b/app/Model/UserUnreadNotification.php @@ -35,6 +35,23 @@ class UserUnreadNotification extends Base )); } + /** + * Get one notification + * + * @param integer $notification_id + * @return array|null + */ + public function getById($notification_id) + { + $notification = $this->db->table(self::TABLE)->eq('id', $notification_id)->findOne(); + + if (! empty($notification)) { + $this->unserialize($notification); + } + + return $notification; + } + /** * Get all notifications for a user * @@ -47,8 +64,7 @@ class UserUnreadNotification extends Base $events = $this->db->table(self::TABLE)->eq('user_id', $user_id)->asc('date_creation')->findAll(); foreach ($events as &$event) { - $event['event_data'] = json_decode($event['event_data'], true); - $event['title'] = $this->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']); + $this->unserialize($event); } return $events; @@ -90,4 +106,10 @@ class UserUnreadNotification extends Base { return $this->db->table(self::TABLE)->eq('user_id', $user_id)->exists(); } + + private function unserialize(&$event) + { + $event['event_data'] = json_decode($event['event_data'], true); + $event['title'] = $this->notification->getTitleWithoutAuthor($event['event_name'], $event['event_data']); + } } -- cgit v1.2.3