ComunicAPI/RestControllers/searchController.php

35 lines
885 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
*/
public function searchDatabase(){
//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
2017-05-27 07:41:52 +00:00
$searchLimit = (isset($_POST['searchLimit']) ? $_POST['searchLimit']*1 : 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
}
}