summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-26 20:50:50 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-26 20:50:50 -0400
commitd9101da79e839984e0e782b48113dc61157d6688 (patch)
tree81913fd719cfa6c0034c8008f2cb1f7b95a30e85 /app/Model
parent0596a4abb9ade1a6cd77516dc6893098eab2a323 (diff)
Mark notification as read when clicking on it
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/UserUnreadNotification.php26
1 files changed, 24 insertions, 2 deletions
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
@@ -36,6 +36,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
*
* @access public
@@ -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']);
+ }
}