Created getList friend method

This commit is contained in:
Pierre 2017-05-31 16:49:25 +02:00
parent 3ad05483f5
commit b0177e9c6f
2 changed files with 45 additions and 1 deletions

View File

@ -16,7 +16,7 @@ class friendsController{
user_login_required(); //Login required
//Try to get friends list
$friendsList = false;
$friendsList = CS::get()->components->friends->getList(userID);
//Check for errors
if($friendsList === false)

View File

@ -7,6 +7,11 @@
class friends {
/**
* @var String $friendsTable The name of the table for friends
*/
private $friendsTable = "amis";
/**
* Public construcor
*/
@ -14,6 +19,45 @@ class friends {
//Nothing now
}
/**
* Get and returns the list of the friends of a user
*
* @param Integer $userID The ID of the user
* @return Array The list of the friends of the user
*/
public function getList($userID) : array {
//Prepare the request on the database
$tableName = $this->friendsTable.", utilisateurs";
$condition = "WHERE ID_personne = ? AND amis.ID_amis = utilisateurs.ID ORDER BY utilisateurs.last_activity";
$condValues = array($userID);
//Specify which fields to get
$fieldsList = array(
"utilisateurs.last_activity",
$this->friendsTable.".ID_amis",
$this->friendsTable.".actif",
$this->friendsTable.".abonnement",
);
//Perform the request on the database
$results = CS::get()->db->select($tableName, $condition, $condValues, $fieldsList);
//Process results
$friendsList = array();
foreach($results as $process){
$friendsList[] = array(
"ID_friend" => $process["ID_amis"],
"active" => $process["actif"],
"following" => $process["abonnement"],
"time_last_activity" => $process["last_activity"]
);
}
//Return result
return $friendsList;
}
}
//Register component