|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use AppBundle\Entity\PerformanceEvent; |
|
6
|
|
|
use AppBundle\Exception\NotFoundException; |
|
7
|
2 |
|
|
|
8
|
|
|
class PerformanceEventRepository extends AbstractRepository |
|
9
|
2 |
|
{ |
|
10
|
2 |
|
/** |
|
11
|
2 |
|
* @param \DateTime $fromDate |
|
12
|
2 |
|
* @param \DateTime $toDate |
|
13
|
2 |
|
* @param string $limit |
|
14
|
|
|
* @param null $performanceSlug |
|
15
|
|
|
* @return mixed |
|
16
|
2 |
|
*/ |
|
17
|
|
|
public function findByDateRangeAndSlug( |
|
18
|
|
|
\DateTime $fromDate, |
|
19
|
|
|
\DateTime $toDate, |
|
20
|
2 |
|
$limit = null, |
|
21
|
|
|
$performanceSlug = null |
|
22
|
2 |
|
) { |
|
23
|
|
|
$qb = $this->createQueryBuilder('u') |
|
24
|
|
|
->where('u.dateTime BETWEEN :from AND :to') |
|
25
|
|
|
->setParameter('from', $fromDate->format('Y-m-d H:i')) |
|
26
|
|
|
->setParameter('to', $toDate->format('Y-m-d H:i')) |
|
27
|
|
|
->orderBy('u.dateTime', 'ASC') |
|
28
|
|
|
; |
|
29
|
|
|
|
|
30
|
|
|
if ($limit) { |
|
|
|
|
|
|
31
|
|
|
$qb->setMaxResults($limit); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if ($performanceSlug) { |
|
35
|
|
|
$qb->join('u.performance', 'p')->andWhere('p.slug = :slug')->setParameter('slug', $performanceSlug); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$query = $qb->getQuery(); |
|
39
|
|
|
|
|
40
|
|
|
return $query->execute(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get PerformanceEvent by ID |
|
45
|
|
|
* |
|
46
|
|
|
* @param int $id |
|
47
|
|
|
* |
|
48
|
|
|
* @return PerformanceEvent |
|
49
|
|
|
* @throws NotFoundException |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getById(int $id): PerformanceEvent |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var PerformanceEvent $performanceEvent */ |
|
54
|
|
|
$performanceEvent = $this->find($id); |
|
55
|
|
|
if (!$performanceEvent) { |
|
56
|
|
|
throw new NotFoundException('Performance Event not found by ID: '.$id); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $performanceEvent; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: