diff --git a/ProjetProgWeb/api.php b/ProjetProgWeb/api.php index cc8d522..2c091d3 100644 --- a/ProjetProgWeb/api.php +++ b/ProjetProgWeb/api.php @@ -17,13 +17,14 @@ if (strlen($author_name) < 3) { $json_object = match ($q) { "theses" => dump::getTheseByAuthor($author_name), - "authors" => dump::getAuthorsByAuthors($author_name), + "authors" => dump::getAuthorsByAuthor($author_name), + "authorsCount" => dump::getAuthorsCountByAuthor($author_name), default => NULL, }; $json = json_encode(array( "status" => 200, - "message" => "Results : " . count($json_object), "data" => $json_object + "message" => "Success", "data" => $json_object ),JSON_PRETTY_PRINT); print_r($json); diff --git a/ProjetProgWeb/class/dump.php b/ProjetProgWeb/class/dump.php index f7d791b..7d7d988 100644 --- a/ProjetProgWeb/class/dump.php +++ b/ProjetProgWeb/class/dump.php @@ -40,7 +40,7 @@ class dump { return $theses_array; } - public static function getAuthorsByAuthors(mixed $author_name) : array { + public static function getAuthorsByAuthor(string $author_name) : array { $array = []; $author_name = '%' . $author_name . '%'; @@ -61,6 +61,23 @@ 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(),