- Added JSON post parameter check in controllers/components/SearchBar->search

- Expanded search capabilities for organization units and employees
This commit is contained in:
Paolo
2022-06-27 16:22:40 +02:00
parent 47f7c03075
commit 2a298dc6d1
2 changed files with 103 additions and 72 deletions
@@ -11,37 +11,41 @@ class SearchBar extends FHC_Controller
const TYPES_PARAM = 'types';
/**
*
* Object initialization
*/
public function __construct()
{
parent::__construct();
//
// Load the library SearchBarLib
$this->load->library('SearchBarLib');
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
public function index()
{
$this->load->view('test');
}
/**
*
* Gets a JSON body via HTTP POST and provides the parameters
*/
public function search()
{
//$searchstr = $this->input->post(self::SEARCHSTR_PARAM);
//$types = $this->input->post(self::TYPES_PARAM);
$json = json_decode($this->input->raw_input_stream, true);
$searchstr = $json[self::SEARCHSTR_PARAM];
$types = $json[self::TYPES_PARAM];
$json = json_decode($this->input->raw_input_stream);
$this->outputJson($this->searchbarlib->search($searchstr, $types));
// Checks if the searchstr and the types parameters are in the POSTed JSON
if (isset($json->{self::SEARCHSTR_PARAM}) && isset($json->{self::TYPES_PARAM}))
{
// Convert to json the result from searchbarlib->search
$this->outputJson(
$this->searchbarlib->search(
$json->{self::SEARCHSTR_PARAM},
$json->{self::TYPES_PARAM}
)
);
}
else // otherwise return an error in JSON format
{
$this->outputJsonError(SearchBarLib::ERROR_WRONG_JSON);
}
}
}