From d5eda3c1d432e1f20882a48d2837c5901b3f97a0 Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 21 Dec 2017 18:55:20 +0100 Subject: [PATCH] Check wether user can post text on his friend page --- RestControllers/friendsController.php | 6 ++++++ classes/components/friends.php | 30 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/RestControllers/friendsController.php b/RestControllers/friendsController.php index e7bec61..c8c101e 100644 --- a/RestControllers/friendsController.php +++ b/RestControllers/friendsController.php @@ -103,6 +103,7 @@ class friendsController{ "sent_request" => false, "received_request" => false, "following" => false, + "can_post_texts" => false, ); //Check if the two personns are friend @@ -123,9 +124,14 @@ class friendsController{ else { //Perform the check specific to the real friend + //Check if the user is following his friend or not if(CS::get()->components->friends->is_following(userID, $friendID)) $response['following'] = true; + //Check if the user can post text on his friend page + if(CS::get()->components->friends->can_post_text(userID, $friendID)) + $response['can_post_texts'] = true; + } //Return the response diff --git a/classes/components/friends.php b/classes/components/friends.php index 2a9ab98..102f0f2 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -209,7 +209,7 @@ class friends { } /** - * Check wether a user is following or not another user + * Check wether a user is following or not another friend * * @param $userID The ID of the user supposed to follow another friend * @param $friendID The ID of the friend @@ -232,6 +232,34 @@ class friends { return $response[0]['abonnement'] == 1; } + + /** + * Check wether a friend allows a friend to post text on his page or not + * + * @param $userID The ID of the user performing the request + * @param $friendID The ID of the friend allowing or denying the user + * to post texts on his page + * @return TRUE if the user is allowed to post texts on the page / FALSE else + */ + public function can_post_text(int $userID, int $friendID) : bool { + + //Query the friend table + $tableName = $this->friendsTable; + $conditions = "WHERE ID_personne = ? AND ID_amis = ? AND actif = 1"; + $condValues = array($friendID, $userID); + $requiredFields = array("autoriser_post_page"); + + //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]['autoriser_post_page'] == 1; + + + } } //Register component