Can get the number of friends of a user

This commit is contained in:
Pierre 2017-12-23 18:03:05 +01:00
parent ffff5e6c85
commit a2b92b4e6c
3 changed files with 28 additions and 3 deletions

View File

@ -138,6 +138,17 @@ class userController
if(count($userInfos) == 0)
Rest_fatal_error(500, "Couldn't get informations about the user !");
//Add account image url
$userInfos['accountImage'] = CS::get()->components->accountImage->getPath($userID);
//Get the number of friends (if allowed)
if($userInfos['friend_list_public'] === true){
$userInfos['number_friends'] = CS::get()->components->friends->count_all($userID);
}
else
//User friends won't be displayed
$userInfos["number_friends"] = 0;
//Return user informations
return $userInfos;

View File

@ -322,6 +322,23 @@ class friends {
//Perform the request
return CS::get()->db->updateDB($tableName, $conditions, $newValues, $conditionsValues);
}
/**
* Count the number of friends of a user
*
* @param int $userID The target user ID
* @return int The number of friends of the user
*/
public function count_all(int $userID) : int {
//Perform a request on the datbase
$tableName = $this->friendsTable;
$conditions = "WHERE ID_amis = ? AND actif = 1";
$condValues = array($userID);
return CS::get()->db->count($tableName, $conditions, $condValues);
}
}
//Register component

View File

@ -236,9 +236,6 @@ class User{
$return['openPage'] = $userInfos['pageouverte'] == 1;
$return['virtualDirectory'] = $userInfos['sous_repertoire'];
//Add account image url
$return['accountImage'] = CS::get()->components->accountImage->getPath($return['userID']);
//Check if we have to fetch advanced informations
if($advanced){