From 3ff3a49d12b25a98f1259d8efd28549cf84bbaf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 28 May 2023 04:04:59 +0200 Subject: [PATCH] fixup! RVRNEXT-11 add model and repository for events --- src/Repository/EventRepository.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Repository/EventRepository.php b/src/Repository/EventRepository.php index dbcf503..9e568e4 100644 --- a/src/Repository/EventRepository.php +++ b/src/Repository/EventRepository.php @@ -5,6 +5,7 @@ use DateTime; use Generator; use RVR\PersistentData\Model\Community; use RVR\PersistentData\Model\Event; +use RVR\PersistentData\Model\User; use SokoWeb\Database\Query\Select; class EventRepository @@ -41,6 +42,16 @@ class EventRepository yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); } + public function getUpcomingByUser(User $user, DateTime $from, int $limit, bool $useRelations = false, array $withRelations = []): Generator + { + $select = $this->selectAllByUser($user); + $select->where('end', '>', $from->format('Y-m-d H:i:s')); + $select->orderBy('start', 'ASC'); + $select->limit($limit, 0); + + yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); + } + public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator { $select = $this->selectAllByCommunity($community); @@ -54,6 +65,7 @@ class EventRepository { $select = $this->selectAllByCommunity($community); $select->where('title', 'LIKE', '%' . $title . '%'); + $select->orderBy('start', 'DESC'); $select->limit(10); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class); @@ -63,7 +75,15 @@ class EventRepository { $select = new Select(Container::$dbConnection, Event::getTable()); $select->where('community_id', '=', $community->getId()); - $select->orderBy('start', 'DESC'); + return $select; + } + + private function selectAllByUser(User $user) + { + $select = new Select(Container::$dbConnection, Event::getTable()); + $select->innerJoin('communities', ['communities', 'id'], '=', ['events', 'community_id']); + $select->innerJoin('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']); + $select->where(['community_members', 'user_id'], '=', $user->getId()); return $select; } }