From 658fd289774d658347ccc5eafa5c140b8ff48d39 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 19 Jan 2025 18:40:48 +0200 Subject: feat(models): Separate user and webpage out of database --- models/database.php | 58 ----------------------------------------------------- models/user.php | 29 +++++++++++++++++++++++++++ models/webpage.php | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 58 deletions(-) create mode 100644 models/user.php create mode 100644 models/webpage.php (limited to 'models') diff --git a/models/database.php b/models/database.php index c59dec6..1fe05e0 100644 --- a/models/database.php +++ b/models/database.php @@ -2,64 +2,6 @@ namespace Database; use PDO; -class User extends Table { - public $UID; - public $Username; - public $Password; - public $Role; - - static function create(string $Username, string $Password, string $Role) : int { - return Table::_create( - "Users", - "(Username, Password, Role)", - "(\"$Username\", \"$Password\", \"$Role\")", - ); - } - - function fromDB(string $username) : User { - return Table::_fromDB( - "SELECT * FROM Users WHERE Username = \"$username\"", - "Database\User" - ); - } - - static function get_all() : array { - return Table::_get_all("Users", "Database\User"); - } -} - -class Webpage extends Table { - public $WID; - public $Path; - public $URL; - public $Date; - public $Visits; - public $RequesterUID; - - static function create(string $Path, string $URL, int $RequesterUID) : int { - return Table::_create( - 'Webpages', - '(Path, URL, Date, Visits, RequesterUID)', - "(\"$Path\", \"$URL\", NOW(), 0, \"$RequesterUID\")" - ); - } - - static function fromDB(string $URL) : Webpage { - return Table::_fromDB( - "SELECT * FROM Webpages WHERE URL = \"$URL\"", - "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 { // Cannot be created, because FETCH_CLASS will assign to all attributes // and then call the constructor diff --git a/models/user.php b/models/user.php new file mode 100644 index 0000000..72933f9 --- /dev/null +++ b/models/user.php @@ -0,0 +1,29 @@ +