ComunicAPI/RestControllers/searchController.php

38 lines
943 B
PHP
Raw Normal View History

2017-05-27 07:30:54 +00:00
<?php
/**
* Search controller
*
* @author Pierre HUBERT
*/
2017-05-27 07:41:52 +00:00
class searchController
2017-05-27 07:30:54 +00:00
{
/**
* Peform a research on the database
*
* @url POST /search/request
2017-06-05 12:22:54 +00:00
* @url POST /user/search
2017-05-27 07:30:54 +00:00
*/
public function searchDatabase(){
2017-06-10 07:42:53 +00:00
user_login_required();
2017-05-27 07:30:54 +00:00
//Check if the query was specified with the request
if(!isset($_POST['query']))
Rest_fatal_error(400, "Please specify search terms");
//Check for search limit
$searchLimit = (isset($_POST['searchLimit']) ? toInt($_POST['searchLimit']) : 5);
2017-05-27 07:30:54 +00:00
//Check the limit
2017-05-27 07:41:52 +00:00
if($searchLimit < 1 || $searchLimit > 25)
2017-05-27 07:30:54 +00:00
Rest_fatal_error(401, "Invalid search limit !");
//Perform research on the database and return results
2017-05-27 09:22:55 +00:00
$results = CS::get()->components->searchUser->search($_POST['query'], $searchLimit);
if($results === false)
2017-05-27 07:41:52 +00:00
Rest_fatal_error(500, "An error occured while trying to perform a research in user list !");
2017-05-27 07:30:54 +00:00
2017-05-27 07:41:52 +00:00
//Return results
return $results;
2017-05-27 07:30:54 +00:00
}
}