mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Can get friendship status
This commit is contained in:
		@@ -61,12 +61,12 @@ class friendsController{
 | 
				
			|||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @url POST /friends/remove
 | 
						 * @url POST /friends/remove
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	 public function delete(){
 | 
						public function delete(){
 | 
				
			||||||
		 user_login_required(); //Login required
 | 
							user_login_required(); //Login required
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		 //Check input parametres
 | 
							//Check input parametres
 | 
				
			||||||
		 if(!isset($_POST['friendID']))
 | 
							if(!isset($_POST['friendID']))
 | 
				
			||||||
		 	Rest_fatal_error(400, "Please specify the ID of the friend to delete !");
 | 
								Rest_fatal_error(400, "Please specify the ID of the friend to delete !");
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		//Delete the friend from the list
 | 
							//Delete the friend from the list
 | 
				
			||||||
		$friendID = toInt($_POST['friendID']);
 | 
							$friendID = toInt($_POST['friendID']);
 | 
				
			||||||
@@ -77,6 +77,50 @@ class friendsController{
 | 
				
			|||||||
			Rest_fatal_error(500, "Couldn't remove user from the friendlist for an unexcepted reason !");
 | 
								Rest_fatal_error(500, "Couldn't remove user from the friendlist for an unexcepted reason !");
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			return array("success" => "The friend was removed from the list !");
 | 
								return array("success" => "The friend was removed from the list !");
 | 
				
			||||||
	 }
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get the status of a friendship
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * Check if the users are friends, or this there is a pending request...
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @url POST /friends/getStatus
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function getStatus(){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							user_login_required(); //Login required
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if the a friendID has been specified
 | 
				
			||||||
 | 
							if(!isset($_POST['friendID']))
 | 
				
			||||||
 | 
								Rest_fatal_error(400, "Please specify a friend ID !");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Get it
 | 
				
			||||||
 | 
							$friendID = toInt($_POST['friendID']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Prepare the response
 | 
				
			||||||
 | 
							$response = array(
 | 
				
			||||||
 | 
								"are_friend" => false,
 | 
				
			||||||
 | 
								"sent_request" => false,
 | 
				
			||||||
 | 
								"received_request" => false,
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Check if the two personns are friend
 | 
				
			||||||
 | 
							$response['are_friend'] = 
 | 
				
			||||||
 | 
								CS::get()->components->friends->are_friend(userID, $friendID);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Perform next check only if the personns are not already friend
 | 
				
			||||||
 | 
							if(!$response['are_friend']){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//Check if the current user has sent a request to the other user
 | 
				
			||||||
 | 
								if(CS::get()->components->friends->sent_request(userID, $friendID))
 | 
				
			||||||
 | 
									$response["sent_request"] = true;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								//Check if the current user has received a friendship request
 | 
				
			||||||
 | 
								if(CS::get()->components->friends->sent_request($friendID, userID))
 | 
				
			||||||
 | 
									$response["received_request"] = true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Return the response
 | 
				
			||||||
 | 
							return $response;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -185,6 +185,28 @@ class friends {
 | 
				
			|||||||
		//Return the result
 | 
							//Return the result
 | 
				
			||||||
		return count($response) > 0;
 | 
							return count($response) > 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Check whether a user has sent a friendship 
 | 
				
			||||||
 | 
						 * request to another friend
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param $user The ID of the user supposed to have sent a request
 | 
				
			||||||
 | 
						 * @param $targetUser The ID of the target user
 | 
				
			||||||
 | 
						 * @return TRUE if a request has been sent / FALSE else
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function sent_request(int $user, int $targetUser) : bool {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Query the friend table
 | 
				
			||||||
 | 
							$tableName = $this->friendsTable;
 | 
				
			||||||
 | 
							$conditions = "WHERE ID_personne = ? AND ID_amis = ? AND actif = 0";
 | 
				
			||||||
 | 
							$condValues = array($targetUser, $user);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Try to perform the request
 | 
				
			||||||
 | 
							$response = CS::get()->db->select($tableName, $conditions, $condValues);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Return result
 | 
				
			||||||
 | 
							return count($response) > 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Register component
 | 
					//Register component
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user