diff options
| author | Syndamia <kamen@syndamia.com> | 2025-01-19 18:24:53 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-01-19 18:24:53 +0200 |
| commit | ba71a5ed4750c660ba5c0aa4743b8e7fd44e1ec9 (patch) | |
| tree | 752a78b922a1a1d02dbaee29a8dedff74ab79da5 | |
| parent | 97ce22e66707e82fbd160edeb97de0432e2be767 (diff) | |
| download | nowayforward_human-ba71a5ed4750c660ba5c0aa4743b8e7fd44e1ec9.tar nowayforward_human-ba71a5ed4750c660ba5c0aa4743b8e7fd44e1ec9.tar.gz nowayforward_human-ba71a5ed4750c660ba5c0aa4743b8e7fd44e1ec9.zip | |
feat(database): Update _get_all to include an additional query and add mostVisited function to Webpage
| -rw-r--r-- | models/database.php | 14 |
1 files changed, 11 insertions, 3 deletions
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); |
