From b9406731a42f04520bad2b452f2f633f342a70b6 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 18 Feb 2018 18:57:19 +0100 Subject: [PATCH] Can get the number of unread notifications --- RestControllers/notificationsController.php | 30 +++++++++++++++++++++ classes/components/notifications.php | 18 +++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 RestControllers/notificationsController.php diff --git a/RestControllers/notificationsController.php b/RestControllers/notificationsController.php new file mode 100644 index 0000000..f9a736a --- /dev/null +++ b/RestControllers/notificationsController.php @@ -0,0 +1,30 @@ +notifications->count_unread(userID); + + //Return it + return array( + "number" => $number + ); + + } + +} \ No newline at end of file diff --git a/classes/components/notifications.php b/classes/components/notifications.php index e77531c..9d660f6 100644 --- a/classes/components/notifications.php +++ b/classes/components/notifications.php @@ -13,6 +13,24 @@ class notificationComponent { */ const NOTIFICATIONS_TABLE = "comunic_notifications"; + /** + * Count the number of unread notifications of a user + * + * @param int $userID Target user ID + * @return int The number of unread notifications + */ + public function count_unread(int $userID) : int { + + //Set the conditions of the request + $conditions = "WHERE dest_user_id = ? AND seen = 0"; + $values = array($userID); + + //Compute and return result + return CS::get()->db->count(self::NOTIFICATIONS_TABLE, $conditions, $values); + + } + + /** * Push a new notification *