From e1760dd772d2355fbf392424ff4de525cb3a9e84 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 24 Aug 2018 08:25:38 +0200 Subject: [PATCH] Can get the number of friendship request with the notifications. --- RestControllers/notificationsController.php | 8 +++++++- classes/components/friends.php | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/RestControllers/notificationsController.php b/RestControllers/notificationsController.php index 423a203..d41c102 100644 --- a/RestControllers/notificationsController.php +++ b/RestControllers/notificationsController.php @@ -40,11 +40,17 @@ class notificationsController { user_login_required(); //Get and return the data - return array( + $data = array( "notifications" => components()->notifications->count_unread(userID), "conversations" => components()->conversations->number_user_unread(userID) ); + //Include friendship requests if required + if(isset($_POST["friends_request"])) + if(postBool("friends_request")) + $data["friends_request"] = components()->friends->count_requests(userID); + + return $data; } diff --git a/classes/components/friends.php b/classes/components/friends.php index 952bdee..15dc58b 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -409,6 +409,19 @@ class friends { } + /** + * Count the number of friendship requests a user has received + * + * @param int $userID Target user ID + * @return int The number of friendship request the user received + */ + public function count_requests(int $userID) : int { + return db()->count( + $this->friendsTable, + "WHERE ID_personne = ? AND actif = 0", + array($userID)); + } + /** * Parse friend informations from the database *