mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Made search more clear
This commit is contained in:
		@@ -10,10 +10,10 @@ class searchController
 | 
			
		||||
	/**
 | 
			
		||||
	 * Peform a research on the database
 | 
			
		||||
	 *
 | 
			
		||||
	 * @url POST /search/request
 | 
			
		||||
	 * @url POST /search/user
 | 
			
		||||
	 * @url POST /user/search
 | 
			
		||||
	 */
 | 
			
		||||
	public function searchDatabase(){
 | 
			
		||||
	public function search_user(){
 | 
			
		||||
		user_login_required();
 | 
			
		||||
 | 
			
		||||
		//Check if the query was specified with the request
 | 
			
		||||
@@ -28,7 +28,7 @@ class searchController
 | 
			
		||||
			Rest_fatal_error(401, "Invalid search limit !");
 | 
			
		||||
		
 | 
			
		||||
		//Perform research on the database and return results
 | 
			
		||||
		$results = CS::get()->components->searchUser->search($_POST['query'], $searchLimit);
 | 
			
		||||
		$results = CS::get()->components->search->search_user($_POST['query'], $searchLimit);
 | 
			
		||||
		if($results === false)
 | 
			
		||||
			Rest_fatal_error(500, "An error occured while trying to perform a research in user list !");
 | 
			
		||||
		
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +1,20 @@
 | 
			
		||||
<?php
 | 
			
		||||
/**
 | 
			
		||||
 * Search user controller
 | 
			
		||||
 * Search controller
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class searchUser {
 | 
			
		||||
class search {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Search for user in the database
 | 
			
		||||
	 *
 | 
			
		||||
	 * @param Sting $query The query to research on the database
 | 
			
		||||
	 * @param Integer $limit The number of results to return on the screen
 | 
			
		||||
	 * @return Array the result of the result
 | 
			
		||||
	 * @param string $query The query to research on the database
 | 
			
		||||
	 * @param int $limit The number of results to return on the screen (default: 10)
 | 
			
		||||
	 * @return array the result of the result
 | 
			
		||||
	 */
 | 
			
		||||
	public function search($query, $limit) : array{
 | 
			
		||||
	public function search_user(string $query, int $limit = 10) : array{
 | 
			
		||||
 | 
			
		||||
		//Prepare query string
 | 
			
		||||
		$query = "%".str_replace(" ", "%", $query)."%";
 | 
			
		||||
@@ -40,4 +40,4 @@ class searchUser {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//Register class
 | 
			
		||||
Components::register("searchUser", new searchUser());
 | 
			
		||||
Components::register("search", new search());
 | 
			
		||||
		Reference in New Issue
	
	Block a user