Implementing working filters (almost)

This commit is contained in:
Florian SYLVAIN
2022-01-05 12:02:20 +01:00
parent f55f866476
commit 183d53b8df
7 changed files with 86 additions and 56 deletions
+9 -8
View File
@@ -2,15 +2,16 @@
require_once("class/dump.php");
if (!isset($_GET['q']) || !isset($_GET['author'])) {
if (!isset($_GET['q']) || !isset($_GET['search']) || !isset($_GET['option'])) {
print_r(json_encode(array("status" => 400, "message" => "Missing query type or attributes.")));
exit();
}
$author_name = filter_var($_GET['author'], FILTER_SANITIZE_ADD_SLASHES);
$q = $_GET['q'];
$search = filter_var($_GET['search'], FILTER_SANITIZE_ADD_SLASHES);
$option = $_GET['option'];
if (strlen($author_name) < 3) {
if (strlen($search) < 3) {
print_r(json_encode(array(
"status" => 400,
"message" => "La recherche doit comporter un minimum de 3 caractères."
@@ -19,15 +20,15 @@ if (strlen($author_name) < 3) {
}
$json_object = match ($q) {
"theses" => dump::getTheseByAuthor($author_name),
"authors" => dump::getAuthorsByAuthor($author_name),
"authorsCount" => dump::getAuthorsCountByAuthor($author_name),
"theses" => dump::getTheses($search, $option),
"suggestion" => dump::getSuggestions($search, $option),
default => NULL,
};
$json = json_encode(array(
"status" => 200,
"message" => "Success", "data" => $json_object
));
"message" => "Success",
"data" => $json_object,
));
echo $json;