aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/ORM/Repositories/Post.php
blob: d6328e63351ddfcc66f4b9e8b4c9284259bf3062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
namespace ORM\Repositories;
use ORM\Repository;
use ORM\Entities\User;
use ORM\Entities\Category;

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();
	}

	# TODO: This only gets the count of the direct category, not its children
	public function getCountByCategory(Category $Category): int {
		$query = 'SELECT COUNT(id) FROM %s WHERE category = ?';
		$query = sprintf($query, static::getTableName());

		$Statement = $this->Database->prepare($query);
		$Statement->execute([$Category->getID()]);

		return $Statement->fetchColumn();
	}
}