🎨 Improving filters

This commit is contained in:
Florian SYLVAIN
2022-01-06 14:31:11 +01:00
parent 183d53b8df
commit a89a4f2315
4 changed files with 41 additions and 20 deletions
+12 -2
View File
@@ -55,7 +55,7 @@ class dump {
return $theses_array;
}
public static function getSuggestions(string $search, string $option) : array {
public static function getSuggestions(string $search, string $option) : ?array {
$array = [];
$search = '%' . $search . '%';
@@ -63,7 +63,17 @@ class dump {
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt = $pdo->prepare("SELECT DISTINCT author FROM theses WHERE author LIKE :search LIMIT 10;");
if ($option == 'auto') {
return null;
}
$stmt = match ($option) {
'author' => $pdo->prepare("SELECT DISTINCT author FROM theses WHERE author LIKE :search LIMIT 10;"),
'title' => $pdo->prepare("SELECT DISTINCT title FROM theses WHERE title LIKE :search LIMIT 5;"),
'director' => $pdo->prepare("SELECT DISTINCT these_director FROM theses WHERE these_director LIKE :search LIMIT 10;"),
'establishment' => $pdo->prepare("SELECT DISTINCT soutenance_establishment FROM theses WHERE soutenance_establishment LIKE :search LIMIT 10;"),
default => "",
};
$stmt->bindParam(':search', $search, PDO::PARAM_STR, 100);
$stmt->execute();