Mark notification as read when clicking on it

This commit is contained in:
Frederic Guillot
2016-05-26 20:50:50 -04:00
parent 0596a4abb9
commit d9101da79e
6 changed files with 129 additions and 61 deletions

View File

@@ -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']);
}
}