aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/ORM/Repositories/UserRepository.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-22 14:00:12 +0200
committerThomas Lange <code@nerdmind.de>2021-07-22 14:00:12 +0200
commit59392e460020447720089976b83139ad59d275fe (patch)
tree25cc766f352d9ae6319d22d43388db563d6ba404 /core/namespace/ORM/Repositories/UserRepository.php
parent912a19ef8c58b87ac075d21cee0425f7715b4f94 (diff)
downloadblog-59392e460020447720089976b83139ad59d275fe.tar.gz
blog-59392e460020447720089976b83139ad59d275fe.tar.xz
blog-59392e460020447720089976b83139ad59d275fe.zip
Rename: Append "Repository" to repository classes
Rename the repository classes and append the name with "Repository" to prevent naming confusions with the entity classes.
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();
+ }
+}