From 640dd416d3de28ad39b05747ad4b7c81d5203776 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 19 Jan 2025 19:25:03 +0200 Subject: feat(models/webpage): Add functions for getting all archives and updating the visits count --- models/webpage.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/models/webpage.php b/models/webpage.php index 35bb3ce..9dcc5ae 100644 --- a/models/webpage.php +++ b/models/webpage.php @@ -20,7 +20,7 @@ class Webpage extends Table { static function fromDB(string $URL) : Webpage { return Table::_fromDB( - "SELECT * FROM Webpages WHERE URL = \"$URL\"", + "SELECT * FROM Webpages WHERE URL = \"$URL\" ORDER BY Date DESC LIMIT 1", "Database\Webpage" ); } @@ -32,4 +32,20 @@ class Webpage extends Table { "GROUP BY URL ORDER BY Visits DESC, Date DESC LIMIT $count" ); } + + static function allArchives(string $URL) : array { + return Table::_get_all( + 'Webpages', + 'Database\Webpage', + "WHERE URL = \"$URL\" ORDER BY Date DESC" + ); + } + + function incrementVisits() { + Table::_update( + 'Webpages', + "Visits = \"" . ($this->Visits + 1) . "\"", + "WID = \"{$this->WID}\"" + ); + } } -- cgit v1.2.3