From ba71a5ed4750c660ba5c0aa4743b8e7fd44e1ec9 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 19 Jan 2025 18:24:53 +0200 Subject: feat(database): Update _get_all to include an additional query and add mostVisited function to Webpage --- models/database.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'models/database.php') diff --git a/models/database.php b/models/database.php index 5f94ec3..c59dec6 100644 --- a/models/database.php +++ b/models/database.php @@ -24,7 +24,7 @@ class User extends Table { } static function get_all() : array { - return Table::_get_all("Database\User"); + return Table::_get_all("Users", "Database\User"); } } @@ -50,6 +50,14 @@ class Webpage extends Table { "Database\Webpage" ); } + + static function mostVisited(int $count) : array { + return Table::_get_all( + 'Webpages', + 'Database\Webpage', + "GROUP BY URL ORDER BY Visits DESC, Date DESC LIMIT $count" + ); + } } abstract class Table { @@ -82,9 +90,9 @@ abstract class Table { return $id; } - static protected function _get_all(string $class) : array { + static protected function _get_all(string $table, string $class, string $additional = null) : array { $conn = Table::connect(); - $query = $conn->query("SELECT * FROM Users"); + $query = $conn->query("SELECT * FROM $table " . $additional); $conn = null; $query->setFetchMode(PDO::FETCH_CLASS, $class); -- cgit v1.2.3