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 | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByCommunity($select, $community); | ||||
|         $select = $this->selectAllByCommunity($community); | ||||
| 
 | ||||
|         yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations); | ||||
|     } | ||||
| 
 | ||||
|     public function countAllByCommunity(Community $community): int | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByCommunity($select, $community); | ||||
| 
 | ||||
|         return $select->count(); | ||||
|         return $this->selectAllByCommunity($community)->count(); | ||||
|     } | ||||
| 
 | ||||
|     public function getUpcomingAndRecentByCommunity(Community $community, DateTime $from, int $days, int $limit, bool $useRelations = false, array $withRelations = []): Generator | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByCommunity($select, $community); | ||||
|         $select = $this->selectAllByCommunity($community); | ||||
|         $this->selectUpcomingAndRecent($select, $from, $days); | ||||
|         $select->orderBy('start', 'DESC'); | ||||
|         $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 | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByUser($select, $user); | ||||
|         $select = $this->selectAllByUser($user); | ||||
|         $this->selectUpcomingAndRecent($select, $from, $days); | ||||
|         $select->orderBy('start', 'DESC'); | ||||
|         $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 | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByUser($select, $user); | ||||
|         $select = $this->selectAllByUser($user); | ||||
|         $this->selectUpcomingAndRecent($select, $from, $days); | ||||
|         $select->orderBy('start', 'DESC'); | ||||
|         $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 | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByCommunity($select, $community); | ||||
|         $select = $this->selectAllByCommunity($community); | ||||
|         $select->orderBy('start', 'DESC'); | ||||
|         $select->paginate($page, $itemsPerPage); | ||||
| 
 | ||||
| @ -82,8 +74,7 @@ class EventRepository | ||||
| 
 | ||||
|     public function searchByTitle(Community $community, string $title): Generator | ||||
|     { | ||||
|         $select = new Select(Container::$dbConnection, Event::getTable()); | ||||
|         $this->selectAllByCommunity($select, $community); | ||||
|         $select = $this->selectAllByCommunity($community); | ||||
|         $select->where('title', 'LIKE', '%' . $title . '%'); | ||||
|         $select->orderBy('start', 'DESC'); | ||||
|         $select->limit(10); | ||||
| @ -91,29 +82,31 @@ class EventRepository | ||||
|         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()); | ||||
|         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('community_members', ['communities', 'id'], '=', ['community_members', 'community_id']); | ||||
|         $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('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->orWhere(function (Select $select) use ($from, $days) { | ||||
|                 $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', '<', (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->orWhere(function (Select $select) use ($from, $days) { | ||||
|             $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')); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user