|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Markus Tacker <[email protected]> |
|
5
|
|
|
* @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace BCRM\BackendBundle\Entity\Event; |
|
9
|
|
|
|
|
10
|
|
|
use Doctrine\ORM\EntityRepository; |
|
11
|
|
|
use PhpOption\None; |
|
12
|
|
|
use PhpOption\Option; |
|
13
|
|
|
use PhpOption\Some; |
|
14
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception; |
|
15
|
|
|
|
|
16
|
|
|
class DoctrineTicketRepository extends EntityRepository implements TicketRepository |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param Event $event |
|
20
|
|
|
* |
|
21
|
|
|
* @return Ticket[] |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
public function getToNotify(Event $event) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
return $this->createQueryBuilder('t') |
|
26
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
27
|
|
|
->andWhere('t.notified = 0') |
|
28
|
|
|
->andWhere('t.payment IS NOT NULL') |
|
29
|
|
|
->getQuery() |
|
30
|
|
|
->getResult(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param Event $event |
|
35
|
|
|
* @param string $email |
|
36
|
|
|
* |
|
37
|
|
|
* @return Ticket[] |
|
38
|
|
|
*/ |
|
39
|
|
View Code Duplication |
public function getTicketsForEmail(Event $event, $email) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
return $this->createQueryBuilder('t') |
|
42
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
43
|
|
|
->andWhere('t.email = :email')->setParameter('email', $email) |
|
44
|
|
|
->getQuery() |
|
45
|
|
|
->getResult(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param integer $id |
|
50
|
|
|
* @param string $code |
|
51
|
|
|
* |
|
52
|
|
|
* @return Option |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getTicketByIdAndCode($id, $code) |
|
55
|
|
|
{ |
|
56
|
|
|
return Option::fromValue($this->createQueryBuilder('t') |
|
57
|
|
|
->andWhere('t.id = :id')->setParameter('id', $id) |
|
58
|
|
|
->andWhere('t.code = :code')->setParameter('code', $code) |
|
59
|
|
|
->getQuery() |
|
60
|
|
|
->getOneOrNullResult()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Event $event |
|
65
|
|
|
* |
|
66
|
|
|
* @return Ticket[] |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getTicketsForEvent(Event $event) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->createQueryBuilder('t') |
|
71
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
72
|
|
|
->getQuery() |
|
73
|
|
|
->getResult(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns the number of tickets for the given day. |
|
78
|
|
|
* |
|
79
|
|
|
* @param Event $event |
|
80
|
|
|
* @param $day |
|
81
|
|
|
* |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
View Code Duplication |
public function getTicketCountForEvent(Event $event, $day) |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
return $this->createQueryBuilder('t') |
|
87
|
|
|
->select('COUNT(t.id)') |
|
88
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
89
|
|
|
->andWhere('t.day = :day')->setParameter('day', $day) |
|
90
|
|
|
->getQuery() |
|
91
|
|
|
->getSingleScalarResult(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Returns the number of checkins for the given day. |
|
96
|
|
|
* |
|
97
|
|
|
* @param Event $event |
|
98
|
|
|
* @param $day |
|
99
|
|
|
* |
|
100
|
|
|
* @return mixed |
|
101
|
|
|
*/ |
|
102
|
|
View Code Duplication |
public function getCheckinCountForEvent(Event $event, $day) |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
return $this->createQueryBuilder('t') |
|
105
|
|
|
->select('COUNT(t.id)') |
|
106
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
107
|
|
|
->andWhere('t.day = :day')->setParameter('day', $day) |
|
108
|
|
|
->andWhere('t.checkedIn IS NOT NULL') |
|
109
|
|
|
->getQuery() |
|
110
|
|
|
->getSingleScalarResult(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Returns the list of unprinted tickets for the given day. |
|
115
|
|
|
* |
|
116
|
|
|
* @param Event $event |
|
117
|
|
|
* @param $day |
|
118
|
|
|
* |
|
119
|
|
|
* @return Ticket[] |
|
120
|
|
|
*/ |
|
121
|
|
View Code Duplication |
public function getUnprintedTickets(Event $event, $day) |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
return $this->createQueryBuilder('t') |
|
124
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
125
|
|
|
->andWhere('t.day = :day')->setParameter('day', $day) |
|
126
|
|
|
->andWhere('t.checkedIn IS NOT NULL') |
|
127
|
|
|
->andWhere('t.printed = 0') |
|
128
|
|
|
->getQuery() |
|
129
|
|
|
->getResult(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Search tickets matching the given term |
|
134
|
|
|
* |
|
135
|
|
|
* @param Event $event |
|
136
|
|
|
* @param $day |
|
137
|
|
|
* @param $term |
|
138
|
|
|
* |
|
139
|
|
|
* @return mixed |
|
140
|
|
|
*/ |
|
141
|
|
|
public function searchTickets(Event $event, $day, $term) |
|
142
|
|
|
{ |
|
143
|
|
|
$qb = $this->createQueryBuilder('t'); |
|
144
|
|
|
return $qb |
|
145
|
|
|
->andWhere('t.event = :event')->setParameter('event', $event) |
|
146
|
|
|
->andWhere('t.day = :day')->setParameter('day', $day) |
|
147
|
|
|
->andWhere($qb->expr()->orX( |
|
148
|
|
|
$qb->expr()->like('t.name', ':term'), |
|
149
|
|
|
$qb->expr()->like('t.code', ':term'), |
|
150
|
|
|
$qb->expr()->like('t.email', ':term') |
|
151
|
|
|
))->setParameter('term', '%' . $term . '%') |
|
152
|
|
|
->getQuery() |
|
153
|
|
|
->getResult(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
} |
|
158
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.