mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Update friends post texts authorization status.
This commit is contained in:
parent
6cc90d281f
commit
5d47e64f92
@ -302,6 +302,36 @@ class friendsController{
|
|||||||
return array("success" => "Friendship status has been updated!");
|
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
|
* Convert a friend object into an object readable by the api
|
||||||
*
|
*
|
||||||
|
@ -343,6 +343,29 @@ class friends {
|
|||||||
return CS::get()->db->updateDB($tableName, $conditions, $newValues, $conditionsValues);
|
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
|
* Count the number of friends of a user
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user