From 0d0878daa9acbb7cc9dbb3aef6e1d7a5aeca4dd6 Mon Sep 17 00:00:00 2001 From: Pierre Date: Fri, 11 May 2018 20:19:50 +0200 Subject: [PATCH] Fix issue : friends posts appeared in latest posts even if friendship was not accepted. --- classes/components/friends.php | 10 ++++++++-- classes/components/posts.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/classes/components/friends.php b/classes/components/friends.php index 77a49b8..952bdee 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -29,9 +29,10 @@ class friends { * * @param int $userID The ID of the user * @param int $friendID The ID of a specific friend (default -1) + * @param bool $only_accepted Specify if only the accepted friends must be selected (default: FALSE) * @return array The list of the friends of the user (Friend objects) */ - public function getList(int $userID, int $friendID = -1) : array { + public function getList(int $userID, int $friendID = -1, bool $only_accepted = FALSE) : array { //Prepare the request on the database $tableName = $this->friendsTable.", utilisateurs"; @@ -40,10 +41,15 @@ class friends { //Check if the request is targeting a specific friend if($friendID != -1){ - $condition .= " AND ID_amis = ?"; + $condition .= " AND ID_amis = ? "; $condValues[] = $friendID; } + //Check if only accepted friendship must be selected + if($only_accepted){ + $condition .= " AND actif = 1 "; + } + //Complete conditions $condition .= "ORDER BY utilisateurs.last_activity DESC"; diff --git a/classes/components/posts.php b/classes/components/posts.php index ec5343f..4104f00 100644 --- a/classes/components/posts.php +++ b/classes/components/posts.php @@ -177,7 +177,7 @@ class Posts { $visibilityLevel = self::VISIBILITY_FRIENDS; //Get the list of friends of the user - $friendsList = components()->friends->getList($userID); + $friendsList = components()->friends->getList($userID, -1, TRUE); //Prepare the request on the database