Get following status

This commit is contained in:
Pierre 2017-12-21 18:49:50 +01:00
parent 583ef8fc2d
commit 35d4ab94ac
2 changed files with 34 additions and 1 deletions

View File

@ -102,6 +102,7 @@ class friendsController{
"are_friend" => false, "are_friend" => false,
"sent_request" => false, "sent_request" => false,
"received_request" => false, "received_request" => false,
"following" => false,
); );
//Check if the two personns are friend //Check if the two personns are friend
@ -119,6 +120,13 @@ class friendsController{
if(CS::get()->components->friends->sent_request($friendID, userID)) if(CS::get()->components->friends->sent_request($friendID, userID))
$response["received_request"] = true; $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 the response
return $response; return $response;

View File

@ -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 * request to another friend
* *
* @param $user The ID of the user supposed to have sent a request * @param $user The ID of the user supposed to have sent a request
@ -207,6 +207,31 @@ class friends {
//Return result //Return result
return count($response) > 0; 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 //Register component