Check wether user can post text on his friend page

This commit is contained in:
Pierre 2017-12-21 18:55:20 +01:00
parent 35d4ab94ac
commit d5eda3c1d4
2 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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