|
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
|
|
|
*/ |
|
56
|
|
|
public function findPastGamesById(int $id) |
|
57
|
|
|
{ |
|
58
|
|
|
$qb = $this->createQueryBuilder('game'); |
|
59
|
|
|
$qb->where('game.date <= :date'); |
|
60
|
|
|
$qb->andWhere('game.id = :id'); |
|
61
|
|
|
$qb->setParameter('date', new \DateTime()); |
|
62
|
|
|
$qb->setParameter('id', $id); |
|
63
|
|
|
|
|
64
|
|
|
return $qb->getQuery()->getResult(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Game[] |
|
69
|
|
|
* @throws \Exception |
|
70
|
|
|
*/ |
|
71
|
|
|
public function findActiveGames() |
|
72
|
|
|
{ |
|
73
|
|
|
$dateGameStartRange = new \DateTime(); |
|
74
|
|
|
$dateGameStartRange->sub(new \DateInterval(self::GAME_TIME_RANGE)); |
|
75
|
|
|
|
|
76
|
|
|
$qb = $this->createQueryBuilder('game'); |
|
77
|
|
|
$qb->where('game.date <= :dateNow'); |
|
78
|
|
|
$qb->andWhere('game.date >= :dateGameStartRange'); |
|
79
|
|
|
$qb->setParameter('dateNow', new \DateTime()); |
|
80
|
|
|
$qb->setParameter('dateGameStartRange', $dateGameStartRange); |
|
81
|
|
|
$qb->orderBy('game.date', 'ASC'); |
|
82
|
|
|
|
|
83
|
|
|
return $qb->getQuery()->getResult(); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|