1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Bundle\DefaultBundle\Repository; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityRepository; |
6
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Event; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class TicketCostRepository. |
10
|
|
|
*/ |
11
|
|
|
class TicketCostRepository extends EntityRepository |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Get event current cost. |
15
|
|
|
* |
16
|
|
|
* @param Event $event |
17
|
|
|
* |
18
|
|
|
* @return float |
19
|
|
|
*/ |
20
|
|
|
public function getEventCurrentCost(Event $event) |
21
|
|
|
{ |
22
|
|
|
$qb = $this->getEventTicketsCostQB($event); |
23
|
|
|
$qb->select('tc.amount'); |
24
|
|
|
$qb->andWhere($qb->expr()->eq('tc.enabled', 1)); |
25
|
|
|
|
26
|
|
|
$result = $qb->getQuery()->getResult(); |
27
|
|
|
$result = is_array($result) ? array_shift($result) : null; |
|
|
|
|
28
|
|
|
|
29
|
|
|
$currentCost = $result ? $result['amount'] : null; |
30
|
|
|
|
31
|
|
|
return $currentCost; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get Event tickets cost. |
36
|
|
|
* |
37
|
|
|
* @param Event $event |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function getEventTicketsCost(Event $event) |
42
|
|
|
{ |
43
|
|
|
$qb = $this->getEventTicketsCostQB($event); |
44
|
|
|
|
45
|
|
|
return $qb->getQuery()->getResult(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get Event enabled tickets cost. |
50
|
|
|
* |
51
|
|
|
* @param Event $event |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function getEventEnabledTicketsCost(Event $event) |
56
|
|
|
{ |
57
|
|
|
$qb = $this->getEventTicketsCostQB($event); |
58
|
|
|
$qb->andWhere($qb->expr()->eq('tc.enabled', 1)); |
59
|
|
|
|
60
|
|
|
return $qb->getQuery()->getResult(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Event $event |
65
|
|
|
* |
66
|
|
|
* @return \Doctrine\ORM\QueryBuilder |
67
|
|
|
*/ |
68
|
|
|
private function getEventTicketsCostQB(Event $event) |
69
|
|
|
{ |
70
|
|
|
$qb = $this->createQueryBuilder('tc'); |
71
|
|
|
$qb->where($qb->expr()->eq('tc.event', ':event')) |
72
|
|
|
->setParameter(':event', $event) |
73
|
|
|
->orderBy('tc.amount'); |
74
|
|
|
|
75
|
|
|
return $qb; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|