mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Optimized get friends list function
This commit is contained in:
parent
7df905a988
commit
4bf4218b1d
@ -13,8 +13,14 @@ class friendsController{
|
||||
* @url POST /friends/getList
|
||||
*/
|
||||
public function getFriendsList(){
|
||||
|
||||
user_login_required(); //Login required
|
||||
|
||||
//Check if the user want all the informations about its friends or not
|
||||
$all_infos = false;
|
||||
if(isset($_POST['complete']))
|
||||
$all_infos = $_POST['complete'] === "true";
|
||||
|
||||
//Try to get friends list
|
||||
$friendsList = CS::get()->components->friends->getList(userID);
|
||||
|
||||
@ -27,7 +33,7 @@ class friendsController{
|
||||
foreach($friendsList as $friend){
|
||||
|
||||
//Parse friend informations
|
||||
$api_list[] = $this->parseFriendAPI($friend);
|
||||
$api_list[] = $this->parseFriendAPI($friend, $all_infos);
|
||||
|
||||
}
|
||||
|
||||
@ -38,6 +44,15 @@ class friendsController{
|
||||
return $api_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of friends of a specific user
|
||||
*
|
||||
* @url POST /friends/get_user_list
|
||||
*/
|
||||
public function get_user_list(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a friendship request
|
||||
*
|
||||
@ -242,18 +257,29 @@ class friendsController{
|
||||
* Convert a friend object into an object readable by the api
|
||||
*
|
||||
* @param Friend $friend The input friend
|
||||
* @param bool $all_infos Specify if whether all the informations about the
|
||||
* friendship should be returned or not
|
||||
* @return array Informations about the friend readable by the api
|
||||
*/
|
||||
private function parseFriendAPI(Friend $friend) : array {
|
||||
private function parseFriendAPI(Friend $friend, bool $all_infos = FALSE) : array {
|
||||
|
||||
//Parse informations about the friend
|
||||
$data = array(
|
||||
"ID_friend" => $friend->getFriendID(),
|
||||
"accepted" => $friend->isAccepted() ? 1 : 0,
|
||||
"following" => $friend->isFollowing() ? 1 : 0,
|
||||
"time_last_activity" => $friend->getLastActivityTime()
|
||||
);
|
||||
|
||||
//Check if all the informations about the friendship should be returned or not
|
||||
if($all_infos){
|
||||
|
||||
//Following status
|
||||
$data["following"] = $friend->isFollowing() ? 1 : 0;
|
||||
|
||||
//Can posts text on page
|
||||
$data["canPostTexts"] = $friend->canPostTexts();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@ class friends {
|
||||
$this->friendsTable.".ID_amis",
|
||||
$this->friendsTable.".actif",
|
||||
$this->friendsTable.".abonnement",
|
||||
$this->friendsTable.".autoriser_post_page"
|
||||
);
|
||||
|
||||
//Perform the request on the database
|
||||
@ -364,6 +365,7 @@ class friends {
|
||||
$friend->setAccepted($data["actif"] == 1);
|
||||
$friend->setFollowing($data["abonnement"] == 1);
|
||||
$friend->setLastActivityTime($data["last_activity"]);
|
||||
$friend->setCanPostTexts($data["autoriser_post_page"] == 1);
|
||||
|
||||
return $friend;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class Friend {
|
||||
private $accepted;
|
||||
private $following;
|
||||
private $last_activity_time;
|
||||
private $can_post_texts;
|
||||
|
||||
//Set and get friend ID
|
||||
public function setFriendID(int $id){
|
||||
@ -44,4 +45,12 @@ class Friend {
|
||||
public function getLastActivityTime() : int {
|
||||
return $this->last_activity_time;
|
||||
}
|
||||
|
||||
//Set and get the post creation authorization status
|
||||
public function setCanPostTexts(bool $can_post_texts){
|
||||
$this->can_post_texts = $can_post_texts;
|
||||
}
|
||||
public function canPostTexts() : bool {
|
||||
return $this->can_post_texts;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user