mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Created getList friend method
This commit is contained in:
parent
3ad05483f5
commit
b0177e9c6f
@ -16,7 +16,7 @@ class friendsController{
|
|||||||
user_login_required(); //Login required
|
user_login_required(); //Login required
|
||||||
|
|
||||||
//Try to get friends list
|
//Try to get friends list
|
||||||
$friendsList = false;
|
$friendsList = CS::get()->components->friends->getList(userID);
|
||||||
|
|
||||||
//Check for errors
|
//Check for errors
|
||||||
if($friendsList === false)
|
if($friendsList === false)
|
||||||
|
@ -7,6 +7,11 @@
|
|||||||
|
|
||||||
class friends {
|
class friends {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var String $friendsTable The name of the table for friends
|
||||||
|
*/
|
||||||
|
private $friendsTable = "amis";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Public construcor
|
* Public construcor
|
||||||
*/
|
*/
|
||||||
@ -14,6 +19,45 @@ class friends {
|
|||||||
//Nothing now
|
//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
|
//Register component
|
||||||
|
Loading…
Reference in New Issue
Block a user