fixup! RVRNEXT-11 add model and repository for events
This commit is contained in:
parent
669a012db4
commit
3ff3a49d12
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user