From e143770fc296e34862d95272fc79a56fa9d20a34 Mon Sep 17 00:00:00 2001 From: Georgi Nikolov Date: Sat, 25 Jan 2025 17:01:26 +0200 Subject: Added additional table column for the favicon in the database With that commit handled the saving of that favicon as well --- models/database.php | 7 +++++++ models/webpage.php | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'models') diff --git a/models/database.php b/models/database.php index 62f5b10..f472dbb 100644 --- a/models/database.php +++ b/models/database.php @@ -33,6 +33,13 @@ abstract class Table { return $id; } + static protected function _get_entries_count(string $table) : int { + $conn = Table::connect(); + $query = $conn->query("SELECT count(*) FROM $table"); + $conn = null; + return $query->fetchColumn(); + } + static protected function _update(string $table, string $sets, string $identify) { $conn = Table::connect(); $query = $conn->query("UPDATE $table SET $sets WHERE $identify"); diff --git a/models/webpage.php b/models/webpage.php index 1a2f4a6..5dd44e0 100644 --- a/models/webpage.php +++ b/models/webpage.php @@ -9,12 +9,13 @@ class Webpage extends Table { public $Date; public $Visits; public $RequesterUID; + public $FaviconPath; - static function create(string $Path, string $URL, int $RequesterUID) : int { + static function create(string $Path, string $URL, int $RequesterUID, string $FaviconPath) : int { return Table::_create( 'Webpages', - '(Path, URL, Date, Visits, RequesterUID)', - "(\"$Path\", \"$URL\", (NOW() + INTERVAL 2 HOUR), 0, \"$RequesterUID\")" + '(Path, URL, Date, Visits, RequesterUID, FaviconPath)', + "(\"$Path\", \"$URL\", (NOW() + INTERVAL 2 HOUR), 0, \"$RequesterUID\", \"$FaviconPath\")" ); } @@ -25,6 +26,10 @@ class Webpage extends Table { ); } + static function getPagesCount() : int { + return Table::_get_entries_count("Webpages"); + } + static function mostVisited(int $count) : array { return Table::_get_all( 'Webpages', -- cgit v1.2.3