This commit is contained in:
21 files changed
+844
-15
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use Generator;
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use RVR\PersistentData\Model\CommunityMember;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
use SokoWeb\PersistentData\PersistentDataManager;
|
||||
|
||||
class CommunityMemberRepository
|
||||
{
|
||||
private PersistentDataManager $pdm;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getById(int $id): ?CommunityMember
|
||||
{
|
||||
return $this->pdm->selectFromDbById($id, CommunityMember::class);
|
||||
}
|
||||
|
||||
public function getAllByCommunity(Community $community, bool $useRelations = false): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('community_id', '=', $community->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, CommunityMember::class, $useRelations);
|
||||
}
|
||||
|
||||
public function getAllByUser(User $user, bool $useRelations = false): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('user_id', '=', $user->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, CommunityMember::class, $useRelations);
|
||||
}
|
||||
|
||||
public function getByCommunityAndUser(Community $community, User $user) : ?CommunityMember
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('community_id', '=', $community->getId());
|
||||
$select->where('user_id', '=', $user->getId());
|
||||
|
||||
return $this->pdm->selectFromDb($select, CommunityMember::class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user