From 5d47e64f923cada68a665fdba2eeb28c94f9f5b8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 11 Mar 2018 16:40:41 +0100 Subject: [PATCH] Update friends post texts authorization status. --- RestControllers/friendsController.php | 30 +++++++++++++++++++++++++++ classes/components/friends.php | 23 ++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/RestControllers/friendsController.php b/RestControllers/friendsController.php index 1039218..6b62c33 100644 --- a/RestControllers/friendsController.php +++ b/RestControllers/friendsController.php @@ -302,6 +302,36 @@ class friendsController{ return array("success" => "Friendship status has been updated!"); } + /** + * Update the post text authorization status + * + * @url POST /friends/set_can_post_texts + */ + public function update_can_post_texts(){ + + user_login_required(); //Login required + + //Check if the a friendID has been specified + $friendID = getPostUserID('friendID'); + + //Check if a follow status has been specified + if(!isset($_POST['allow'])) + Rest_fatal_error(400, "Please specify an authorization status!"); + + $can_post_texts = $_POST['allow'] === "true"; + + //Check if the two personns are friend + if(!CS::get()->components->friends->are_friend(userID, $friendID)) + Rest_fatal_error(401, "You are not friend with this personn!"); + + //Update status + if(!components()->friends->set_can_post_texts(userID, $friendID, $can_post_texts)) + Rest_fatal_error(500, "Coudl not update friendship status !"); + + //Success + return array("success" => "Updated authorization status !"); + } + /** * Convert a friend object into an object readable by the api * diff --git a/classes/components/friends.php b/classes/components/friends.php index 8999823..4fa0f7a 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -343,6 +343,29 @@ class friends { return CS::get()->db->updateDB($tableName, $conditions, $newValues, $conditionsValues); } + /** + * Update the posts authorization status for a friendship + * + * @param int $userID The ID of the user updating the authorization status + * @param int $friendID The ID of the target friend + * @param boolean $allow The new authorization status + * @return bool TRUE in case of success / FALSE else + */ + public function set_can_post_texts(int $userID, int $friendID, bool $allow) : bool { + + //Update the table + $tableName = $this->friendsTable; + $conditions = "ID_personne = ? AND ID_amis = ?"; + $conditionsValues = array($userID, $friendID); + $newValues = array( + "autoriser_post_page" => $allow ? 1 : 0 + ); + + //Perform the request + return CS::get()->db->updateDB($tableName, $conditions, $newValues, $conditionsValues); + + } + /** * Count the number of friends of a user *