From faabc462d3080cac67687f450135a078731fb3d1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 1 Feb 2025 10:02:14 +0200 Subject: feat: Rework models methods to be more object-oriented where applicable --- models/webpage.php | 71 ++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 37 deletions(-) (limited to 'models/webpage.php') diff --git a/models/webpage.php b/models/webpage.php index ceb9cea..6347397 100644 --- a/models/webpage.php +++ b/models/webpage.php @@ -34,37 +34,12 @@ class Webpage extends Table { ); } - static function getPreviousPageId(string $url, string $date) : int { - $foundId = Table::_get_all( - "Webpages", - "Database\Webpage", - "WHERE URL = \"$url\" && Date < \"$date\" ORDER BY Date DESC LIMIT 1", - "WID" - ); - if (count($foundId) > 0) { - return $foundId[0]->WID; - } - return 0; - } - - static function getNextPageId(string $url, string $date) : int { - $foundId = Table::_get_all( - "Webpages", - "Database\Webpage", - "WHERE URL = \"$url\" && Date > \"$date\" ORDER BY Date ASC LIMIT 1", - "WID" - ); - if (count($foundId) > 0) { - return $foundId[0]->WID; - } - return 0; - } - + // TODO: remove this, refer to archive.php static function getPagesCount() : int { return Table::_get_entries_count("Webpages"); } - static function mostVisited(int $count) : array { + static function fromDBmostVisited(int $count) : array { return Table::_get_all( 'Webpages', 'Database\Webpage', @@ -73,29 +48,51 @@ class Webpage extends Table { ); } - static function allArchives(string $URL) : array { + static function getArchivePathsByPattern(string $URLPattern) : array { return Table::_get_all( 'Webpages', 'Database\Webpage', - "WHERE URL = \"$URL\" ORDER BY Date DESC" + "WHERE URL LIKE \"$URLPattern\" ORDER BY Date DESC", + "Path, WID" ); } - static function allArchivesByUser(int $UID) : array { + function allArchives() : array { return Table::_get_all( 'Webpages', 'Database\Webpage', - "WHERE RequesterUID = \"$UID\" ORDER BY Date DESC" + "WHERE URL = \"$this->URL\" ORDER BY Date DESC" ); } - static function getArchivePathsByPattern(string $URLPattern) : array { - return Table::_get_all( - 'Webpages', - 'Database\Webpage', - "WHERE URL LIKE \"$URLPattern\" ORDER BY Date DESC", - "Path, WID" + function previousPageId() : int { + $foundId = Table::_get_all( + "Webpages", + "Database\Webpage", + "WHERE URL = \"$this->URL\" AND Date < \"$this->Date\" + ORDER BY Date DESC + LIMIT 1", + "WID" ); + if (count($foundId) > 0) { + return $foundId[0]->WID; + } + return 0; + } + + function nextPageId() : int { + $foundId = Table::_get_all( + "Webpages", + "Database\Webpage", + "WHERE URL = \"$this->URL\" AND Date > \"$this->Date\" + ORDER BY Date ASC + LIMIT 1", + "WID" + ); + if (count($foundId) > 0) { + return $foundId[0]->WID; + } + return 0; } function incrementVisits() { -- cgit v1.2.3