fixup! RVRNEXT-11 add model and repository for events

This commit is contained in:
Bence Pőcze 2023-05-28 04:04:59 +02:00
parent 669a012db4
commit 3ff3a49d12
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -5,6 +5,7 @@ use DateTime;
use Generator; use Generator;
use RVR\PersistentData\Model\Community; use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\Event; use RVR\PersistentData\Model\Event;
use RVR\PersistentData\Model\User;
use SokoWeb\Database\Query\Select; use SokoWeb\Database\Query\Select;
class EventRepository class EventRepository
@ -41,6 +42,16 @@ class EventRepository
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); 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 public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
{ {
$select = $this->selectAllByCommunity($community); $select = $this->selectAllByCommunity($community);
@ -54,6 +65,7 @@ class EventRepository
{ {
$select = $this->selectAllByCommunity($community); $select = $this->selectAllByCommunity($community);
$select->where('title', 'LIKE', '%' . $title . '%'); $select->where('title', 'LIKE', '%' . $title . '%');
$select->orderBy('start', 'DESC');
$select->limit(10); $select->limit(10);
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class); yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class);
@ -63,7 +75,15 @@ class EventRepository
{ {
$select = new Select(Container::$dbConnection, Event::getTable()); $select = new Select(Container::$dbConnection, Event::getTable());
$select->where('community_id', '=', $community->getId()); $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; return $select;
} }
} }