diff --git a/RestControllers/friendsController.php b/RestControllers/friendsController.php index 1fae9c0..2664a3f 100644 --- a/RestControllers/friendsController.php +++ b/RestControllers/friendsController.php @@ -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; } } \ No newline at end of file diff --git a/classes/components/friends.php b/classes/components/friends.php index da3f55c..dc288e6 100644 --- a/classes/components/friends.php +++ b/classes/components/friends.php @@ -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; } diff --git a/classes/models/Friend.php b/classes/models/Friend.php index 5bc4b72..875fdd0 100644 --- a/classes/models/Friend.php +++ b/classes/models/Friend.php @@ -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; + } } \ No newline at end of file