diff --git a/RestControllers/friendsController.php b/RestControllers/friendsController.php index 9a32622..e7bec61 100644 --- a/RestControllers/friendsController.php +++ b/RestControllers/friendsController.php @@ -102,6 +102,7 @@ class friendsController{ "are_friend" => false, "sent_request" => false, "received_request" => false, + "following" => false, ); //Check if the two personns are friend @@ -119,6 +120,13 @@ class friendsController{ if(CS::get()->components->friends->sent_request($friendID, userID)) $response["received_request"] = true; } + else { + + //Perform the check specific to the real friend + if(CS::get()->components->friends->is_following(userID, $friendID)) + $response['following'] = true; + + } //Return the response return $response; diff --git a/classes/components/friends.php b/classes/components/friends.php index aa2e39d..2a9ab98 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -187,7 +187,7 @@ class friends { } /** - * Check whether a user has sent a friendship + * Check wether a user has sent a friendship * request to another friend * * @param $user The ID of the user supposed to have sent a request @@ -207,6 +207,31 @@ class friends { //Return result return count($response) > 0; } + + /** + * Check wether a user is following or not another user + * + * @param $userID The ID of the user supposed to follow another friend + * @param $friendID The ID of the friend + * @return TRUE if the user is following the other user / FALSE else + */ + public function is_following(int $userID, int $friendID) : bool { + + //Query the friend table + $tableName = $this->friendsTable; + $conditions = "WHERE ID_personne = ? AND ID_amis = ? AND actif = 1"; + $condValues = array($userID, $friendID); + $requiredFields = array("abonnement"); + + //Try to perform the request + $response = CS::get()->db->select($tableName, $conditions, $condValues, $requiredFields); + + //Check for result + if(count($response) < 1) + return FALSE; //No entry found + + return $response[0]['abonnement'] == 1; + } } //Register component