aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/ORM/Repositories/UserRepository.php
blob: a0e58c676ab8edfb3596079ae1b42a8dcceddc6d (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
32
33
34
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();
	}
}