mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Check wether user can post text on his friend page
This commit is contained in:
		@@ -103,6 +103,7 @@ class friendsController{
 | 
			
		||||
			"sent_request" => false,
 | 
			
		||||
			"received_request" => false,
 | 
			
		||||
			"following" => false,
 | 
			
		||||
			"can_post_texts" => false,
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		//Check if the two personns are friend
 | 
			
		||||
@@ -123,9 +124,14 @@ class friendsController{
 | 
			
		||||
		else {
 | 
			
		||||
 | 
			
		||||
			//Perform the check specific to the real friend
 | 
			
		||||
			//Check if the user is following his friend or not
 | 
			
		||||
			if(CS::get()->components->friends->is_following(userID, $friendID))
 | 
			
		||||
				$response['following'] = true;
 | 
			
		||||
 | 
			
		||||
			//Check if the user can post text on his friend page
 | 
			
		||||
			if(CS::get()->components->friends->can_post_text(userID, $friendID))
 | 
			
		||||
				$response['can_post_texts'] = true;
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Return the response
 | 
			
		||||
 
 | 
			
		||||
@@ -209,7 +209,7 @@ class friends {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check wether a user is following or not another user
 | 
			
		||||
	 * Check wether a user is following or not another friend
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param $userID The ID of the user supposed to follow another friend
 | 
			
		||||
	 * @param $friendID The ID of the friend
 | 
			
		||||
@@ -232,6 +232,34 @@ class friends {
 | 
			
		||||
		
 | 
			
		||||
		return $response[0]['abonnement'] == 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check wether a friend allows a friend to post text on his page or not
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param $userID The ID of the user performing the request
 | 
			
		||||
	 * @param $friendID The ID of the friend allowing or denying the user
 | 
			
		||||
	 * to post texts on his page
 | 
			
		||||
	 * @return TRUE if the user is allowed to post texts on the page / FALSE else
 | 
			
		||||
	 */
 | 
			
		||||
	public function can_post_text(int $userID, int $friendID) : bool {
 | 
			
		||||
 | 
			
		||||
		//Query the friend table
 | 
			
		||||
		$tableName = $this->friendsTable;
 | 
			
		||||
		$conditions = "WHERE ID_personne = ? AND ID_amis = ? AND actif = 1";
 | 
			
		||||
		$condValues = array($friendID, $userID);
 | 
			
		||||
		$requiredFields = array("autoriser_post_page");
 | 
			
		||||
 | 
			
		||||
		//Try to perform the request
 | 
			
		||||
		$response = CS::get()->db->select($tableName, $conditions, $condValues, $requiredFields);
 | 
			
		||||
 | 
			
		||||
		//Check for result
 | 
			
		||||
		if(count($response) < 1)
 | 
			
		||||
			return FALSE; //No entry found
 | 
			
		||||
		
 | 
			
		||||
		return $response[0]['autoriser_post_page'] == 1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Register component
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user