aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/ORM/Repositories
diff options
context:
space:
mode:
Diffstat (limited to 'core/namespace/ORM/Repositories')
-rw-r--r--core/namespace/ORM/Repositories/Page.php19
-rw-r--r--core/namespace/ORM/Repositories/Post.php19
-rw-r--r--core/namespace/ORM/Repositories/User.php8
3 files changed, 46 insertions, 0 deletions
diff --git a/core/namespace/ORM/Repositories/Page.php b/core/namespace/ORM/Repositories/Page.php
new file mode 100644
index 0000000..595b420
--- /dev/null
+++ b/core/namespace/ORM/Repositories/Page.php
@@ -0,0 +1,19 @@
+<?php
+namespace ORM\Repositories;
+use ORM\Repository;
+use ORM\Entities\User;
+
+class Page extends Repository {
+ public static function getTableName(): string { return 'page'; }
+ public static function getClassName(): string { return 'ORM\Entities\Page'; }
+
+ public function getCountByUser(User $User): int {
+ $query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
+ $query = sprintf($query, static::getTableName());
+
+ $Statement = $this->Database->prepare($query);
+ $Statement->execute([$User->getID()]);
+
+ return $Statement->fetchColumn();
+ }
+}
diff --git a/core/namespace/ORM/Repositories/Post.php b/core/namespace/ORM/Repositories/Post.php
new file mode 100644
index 0000000..8eac12f
--- /dev/null
+++ b/core/namespace/ORM/Repositories/Post.php
@@ -0,0 +1,19 @@
+<?php
+namespace ORM\Repositories;
+use ORM\Repository;
+use ORM\Entities\User;
+
+class Post extends Repository {
+ public static function getTableName(): string { return 'post'; }
+ public static function getClassName(): string { return 'ORM\Entities\Post'; }
+
+ public function getCountByUser(User $User): int {
+ $query = 'SELECT COUNT(id) FROM %s WHERE user = ?';
+ $query = sprintf($query, static::getTableName());
+
+ $Statement = $this->Database->prepare($query);
+ $Statement->execute([$User->getID()]);
+
+ return $Statement->fetchColumn();
+ }
+}
diff --git a/core/namespace/ORM/Repositories/User.php b/core/namespace/ORM/Repositories/User.php
new file mode 100644
index 0000000..629d9c1
--- /dev/null
+++ b/core/namespace/ORM/Repositories/User.php
@@ -0,0 +1,8 @@
+<?php
+namespace ORM\Repositories;
+use ORM\Repository;
+
+class User extends Repository {
+ public static function getTableName(): string { return 'user'; }
+ public static function getClassName(): string { return 'ORM\Entities\User'; }
+}