Compare commits
No commits in common. "6146641eedba2ef2b4db553a8c9f44534330d369" and "2d2cf9c6f0d1841b00e6357e00aaff657d8639ab" have entirely different histories.
6146641eed
...
2d2cf9c6f0
@ -23,24 +23,19 @@ class EventRepository
|
|||||||
|
|
||||||
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
|
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
$select = $this->selectAllByCommunity($community);
|
||||||
$this->selectAllByCommunity($select, $community);
|
|
||||||
|
|
||||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function countAllByCommunity(Community $community): int
|
public function countAllByCommunity(Community $community): int
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
return $this->selectAllByCommunity($community)->count();
|
||||||
$this->selectAllByCommunity($select, $community);
|
|
||||||
|
|
||||||
return $select->count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUpcomingAndRecentByCommunity(Community $community, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
public function getUpcomingAndRecentByCommunity(Community $community, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
$select = $this->selectAllByCommunity($community);
|
||||||
$this->selectAllByCommunity($select, $community);
|
|
||||||
$this->selectUpcomingAndRecent($select, $from, $days);
|
$this->selectUpcomingAndRecent($select, $from, $days);
|
||||||
$select->orderBy('start', 'DESC');
|
$select->orderBy('start', 'DESC');
|
||||||
$select->limit($limit, 0);
|
$select->limit($limit, 0);
|
||||||
@ -50,8 +45,7 @@ class EventRepository
|
|||||||
|
|
||||||
public function getUpcomingAndRecentByUser(User $user, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
public function getUpcomingAndRecentByUser(User $user, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
$select = $this->selectAllByUser($user);
|
||||||
$this->selectAllByUser($select, $user);
|
|
||||||
$this->selectUpcomingAndRecent($select, $from, $days);
|
$this->selectUpcomingAndRecent($select, $from, $days);
|
||||||
$select->orderBy('start', 'DESC');
|
$select->orderBy('start', 'DESC');
|
||||||
$select->limit($limit, 0);
|
$select->limit($limit, 0);
|
||||||
@ -61,8 +55,7 @@ class EventRepository
|
|||||||
|
|
||||||
public function getCurrentByUser(User $user, DateTime $from, int $days, bool $useRelations = false, array $withRelations = []): ?Event
|
public function getCurrentByUser(User $user, DateTime $from, int $days, bool $useRelations = false, array $withRelations = []): ?Event
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
$select = $this->selectAllByUser($user);
|
||||||
$this->selectAllByUser($select, $user);
|
|
||||||
$this->selectUpcomingAndRecent($select, $from, $days);
|
$this->selectUpcomingAndRecent($select, $from, $days);
|
||||||
$select->orderBy('start', 'DESC');
|
$select->orderBy('start', 'DESC');
|
||||||
$select->limit(1, 0);
|
$select->limit(1, 0);
|
||||||
@ -72,8 +65,7 @@ class EventRepository
|
|||||||
|
|
||||||
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
$select = $this->selectAllByCommunity($community);
|
||||||
$this->selectAllByCommunity($select, $community);
|
|
||||||
$select->orderBy('start', 'DESC');
|
$select->orderBy('start', 'DESC');
|
||||||
$select->paginate($page, $itemsPerPage);
|
$select->paginate($page, $itemsPerPage);
|
||||||
|
|
||||||
@ -82,8 +74,7 @@ class EventRepository
|
|||||||
|
|
||||||
public function searchByTitle(Community $community, string $title): Generator
|
public function searchByTitle(Community $community, string $title): Generator
|
||||||
{
|
{
|
||||||
$select = new Select(Container::$dbConnection, Event::getTable());
|
$select = $this->selectAllByCommunity($community);
|
||||||
$this->selectAllByCommunity($select, $community);
|
|
||||||
$select->where('title', 'LIKE', '%' . $title . '%');
|
$select->where('title', 'LIKE', '%' . $title . '%');
|
||||||
$select->orderBy('start', 'DESC');
|
$select->orderBy('start', 'DESC');
|
||||||
$select->limit(10);
|
$select->limit(10);
|
||||||
@ -91,21 +82,24 @@ class EventRepository
|
|||||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class);
|
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectAllByCommunity(Select $select, Community $community): void
|
private function selectAllByCommunity(Community $community)
|
||||||
{
|
{
|
||||||
|
$select = new Select(Container::$dbConnection, Event::getTable());
|
||||||
$select->where('community_id', '=', $community->getId());
|
$select->where('community_id', '=', $community->getId());
|
||||||
|
return $select;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectAllByUser(Select $select, User $user): void
|
private function selectAllByUser(User $user)
|
||||||
{
|
{
|
||||||
|
$select = new Select(Container::$dbConnection, Event::getTable());
|
||||||
$select->innerJoin('communities', ['communities', 'id'], '=', ['events', 'community_id']);
|
$select->innerJoin('communities', ['communities', 'id'], '=', ['events', 'community_id']);
|
||||||
$select->innerJoin('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']);
|
$select->innerJoin('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']);
|
||||||
$select->where(['community_members', 'user_id'], '=', $user->getId());
|
$select->where(['community_members', 'user_id'], '=', $user->getId());
|
||||||
|
return $select;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectUpcomingAndRecent(Select $select, DateTime $from, int $days): void
|
private function selectUpcomingAndRecent(Select $select, DateTime $from, int $days)
|
||||||
{
|
{
|
||||||
$select->where(function (Select $select) use ($from, $days) {
|
|
||||||
$select->where(function (Select $select) use ($from, $days) {
|
$select->where(function (Select $select) use ($from, $days) {
|
||||||
$select->where('start', '<', (clone $from)->add(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s'));
|
$select->where('start', '<', (clone $from)->add(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s'));
|
||||||
$select->where('end', '>', $from->format('Y-m-d H:i:s'));
|
$select->where('end', '>', $from->format('Y-m-d H:i:s'));
|
||||||
@ -114,6 +108,5 @@ class EventRepository
|
|||||||
$select->where('end', '>', (clone $from)->sub(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s'));
|
$select->where('end', '>', (clone $from)->sub(DateInterval::createFromDateString("$days days"))->format('Y-m-d H:i:s'));
|
||||||
$select->where('start', '<', $from->format('Y-m-d H:i:s'));
|
$select->where('start', '<', $from->format('Y-m-d H:i:s'));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user