mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-30 09:16:35 +00:00
Get following status
This commit is contained in:
parent
583ef8fc2d
commit
35d4ab94ac
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user