| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\GameCore\Persistence\Repository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\GameCore\Persistence\Entity\Game; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Bridge\Doctrine\RegistryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @method Game|null find($id, $lockMode = null, $lockVersion = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @method Game|null findOneBy(array $criteria, array $orderBy = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @method Game[]    findAll() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @method Game[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class GameRepository extends ServiceEntityRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     const GAME_TIME_RANGE = 'PT115M'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @param RegistryInterface $registry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct(RegistryInterface $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         parent::__construct($registry, Game::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return Game[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function findFutureGames() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $qb = $this->createQueryBuilder('game'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $qb->where('game.date > :date') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ->setParameter('date', new \DateTime()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ->orderBy('game.date', 'ASC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         return $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @return Game[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function findPastGames() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $qb = $this->createQueryBuilder('game'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $qb->where('game.date <= :date') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->setParameter('date', new \DateTime()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             ->orderBy('game.date', 'ASC'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return Game[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @throws \Exception | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     public function findActiveGames() | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         $dateGameStartRange = new \DateTime(); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $dateGameStartRange->sub(new \DateInterval(self::GAME_TIME_RANGE)); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $qb = $this->createQueryBuilder('game'); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $qb->where('game.date <= :dateNow'); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $qb->andWhere('game.date >= :dateGameStartRange'); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         $qb->setParameter('dateNow', new \DateTime()); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $qb->setParameter('dateGameStartRange', $dateGameStartRange); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $qb->orderBy('game.date', 'ASC'); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |          | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         return $qb->getQuery()->getResult(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |  |