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
-1
View File
@@ -1,6 +1,5 @@
<?php
// Since I don't know atm if I am allowed to use external libs like dotenv, I used this piece of code to load .env file.
// Link : https://dev.to/fadymr/php-create-your-own-php-dotenv-3k2i
// Author : F.R Michel
class dotEnv
+23 -25
View File
@@ -16,16 +16,31 @@ class dump {
return date("Y-m-d", strtotime($old_date));
}
public static function getTheseByAuthor($author) : array {
public static function getTheses(string $search, string $option) : array {
$theses_array = [];
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$author = '%' . $author . '%';
$search = '%' . $search . '%';
$stmt = $pdo->prepare("SELECT * FROM theses WHERE author LIKE :author ORDER BY author;");
$stmt->bindParam(':author', $author, PDO::PARAM_STR, 100);
$stmt = match ($option) {
'auto' => $pdo->prepare("
SELECT *
FROM theses
WHERE author LIKE :search
OR title LIKE :search
OR these_director LIKE :search
OR soutenance_establishment LIKE :search;
"),
'author' => $pdo->prepare("SELECT * FROM theses WHERE author LIKE :search ORDER BY author;"),
'title' => $pdo->prepare("SELECT * FROM theses WHERE title LIKE :search;"),
'director' => $pdo->prepare("SELECT * FROM theses WHERE these_director LIKE :search;"),
'establishment' => $pdo->prepare("SELECT * FROM theses WHERE soutenance_establishment LIKE :search;"),
default => "",
};
$stmt->bindParam(':search', $search, PDO::PARAM_STR, 100);
$stmt->execute();
$i = 0;
@@ -40,16 +55,16 @@ class dump {
return $theses_array;
}
public static function getAuthorsByAuthor(string $author_name) : array {
public static function getSuggestions(string $search, string $option) : array {
$array = [];
$author_name = '%' . $author_name . '%';
$search = '%' . $search . '%';
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt = $pdo->prepare("SELECT DISTINCT author FROM theses WHERE author LIKE :author_name LIMIT 10;");
$stmt->bindParam(':author_name', $author_name, PDO::PARAM_STR, 100);
$stmt = $pdo->prepare("SELECT DISTINCT author FROM theses WHERE author LIKE :search LIMIT 10;");
$stmt->bindParam(':search', $search, PDO::PARAM_STR, 100);
$stmt->execute();
while ($obj = $stmt->fetchObject()) {
@@ -61,23 +76,6 @@ class dump {
return $array;
}
public static function getAuthorsCountByAuthor(string $author_name) : int {
$author_name = '%' . $author_name . '%';
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
$stmt = $pdo->prepare("SELECT COUNT(author) FROM theses WHERE author LIKE :author_name;");
$stmt->bindParam(':author_name', $author_name, PDO::PARAM_STR, 100);
$stmt->execute();
while ($obj = $stmt->fetchObject()) {
foreach ($obj as $elem) {
return $elem;
}
} return 0;
}
public function sendThese($pdo) {
$data = [
'author' => $this->these->getAuthor(),