From 4e9c7f8c3c470dcaff096ee9d523efa72a1db6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 17 Jun 2023 13:17:29 +0200 Subject: [PATCH] RVRNEXT-43 extend community member repository with count --- src/Repository/CommunityMemberRepository.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Repository/CommunityMemberRepository.php b/src/Repository/CommunityMemberRepository.php index d0a1e2f..9757955 100644 --- a/src/Repository/CommunityMemberRepository.php +++ b/src/Repository/CommunityMemberRepository.php @@ -15,12 +15,16 @@ class CommunityMemberRepository public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator { - $select = new Select(\Container::$dbConnection); - $select->where('community_id', '=', $community->getId()); + $select = $this->selectAllByCommunity($community); yield from \Container::$persistentDataManager->selectMultipleFromDb($select, CommunityMember::class, $useRelations, $withRelations); } + public function countAllByCommunity(Community $community): int + { + return $this->selectAllByCommunity($community)->count(); + } + public function getAllByUser(User $user, bool $useRelations = false, array $withRelations = []): Generator { $select = new Select(\Container::$dbConnection); @@ -37,4 +41,11 @@ class CommunityMemberRepository return \Container::$persistentDataManager->selectFromDb($select, CommunityMember::class); } + + private function selectAllByCommunity(Community $community): Select + { + $select = new Select(\Container::$dbConnection, CommunityMember::getTable()); + $select->where('community_id', '=', $community->getId()); + return $select; + } }