aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/ORM/Repositories/UserRepository.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/namespace/ORM/Repositories/UserRepository.php')
-rw-r--r--core/namespace/ORM/Repositories/UserRepository.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/namespace/ORM/Repositories/UserRepository.php b/core/namespace/ORM/Repositories/UserRepository.php
new file mode 100644
index 0000000..a0e58c6
--- /dev/null
+++ b/core/namespace/ORM/Repositories/UserRepository.php
@@ -0,0 +1,35 @@
+<?php
+namespace ORM\Repositories;
+use ORM\Repository;
+use ORM\Entities\User;
+
+class UserRepository extends Repository {
+ public static function getTableName(): string { return 'user'; }
+ public static function getClassName(): string { return 'ORM\Entities\User'; }
+
+ #===============================================================================
+ # Get number of *pages* assigned to $User
+ #===============================================================================
+ public function getNumberOfPages(User $User): int {
+ $query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
+ $query = sprintf($query, PageRepository::getTableName());
+
+ $Statement = $this->Database->prepare($query);
+ $Statement->execute([$User->getID()]);
+
+ return $Statement->fetchColumn();
+ }
+
+ #===============================================================================
+ # Get number of *posts* assigned to $User
+ #===============================================================================
+ public function getNumberOfPosts(User $User): int {
+ $query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
+ $query = sprintf($query, PostRepository::getTableName());
+
+ $Statement = $this->Database->prepare($query);
+ $Statement->execute([$User->getID()]);
+
+ return $Statement->fetchColumn();
+ }
+}