ComunicAPI/classes/components/friends.php

64 lines
1.4 KiB
PHP
Raw Normal View History

2017-05-28 12:09:20 +00:00
<?php
/**
* Friends component
*
* @author Pierre HUBERT
*/
class friends {
2017-05-31 14:49:25 +00:00
/**
* @var String $friendsTable The name of the table for friends
*/
private $friendsTable = "amis";
2017-05-28 12:09:20 +00:00
/**
* Public construcor
*/
public function __construct(){
//Nothing now
}
2017-05-31 14:49:25 +00:00
/**
* 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";
2017-06-03 11:42:45 +00:00
$condition = "WHERE ID_personne = ? AND amis.ID_amis = utilisateurs.ID ORDER BY utilisateurs.last_activity DESC";
2017-05-31 14:49:25 +00:00
$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;
}
2017-05-28 12:09:20 +00:00
}
//Register component
Components::register("friends", new friends());