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\Common\Collections\ArrayCollection; |
11
|
|
|
use Doctrine\ORM\EntityRepository; |
12
|
|
|
use Doctrine\ORM\Query\ResultSetMappingBuilder; |
13
|
|
|
use PhpOption\None; |
14
|
|
|
use PhpOption\Option; |
15
|
|
|
use PhpOption\Some; |
16
|
|
|
use Doctrine\ORM\Query\Expr; |
17
|
|
|
|
18
|
|
|
class DoctrineRegistrationRepository extends EntityRepository implements RegistrationRepository |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @return Registration[] |
22
|
|
|
*/ |
23
|
|
|
public function getToPay() |
24
|
|
|
{ |
25
|
|
|
$qb = $this->createQueryBuilder('r'); |
26
|
|
|
$qb->andWhere('r.payment IS NULL'); |
27
|
|
|
$qb->andWhere('r.paymentNotified IS NULL'); |
28
|
|
|
return $qb->getQuery()->getResult(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $uuid |
33
|
|
|
* |
34
|
|
|
* @return \PhpOption\Option |
35
|
|
|
*/ |
36
|
|
|
public function getRegistrationByUuid($uuid) |
37
|
|
|
{ |
38
|
|
|
$qb = $this->createQueryBuilder('r'); |
39
|
|
|
$qb->andWhere('r.uuid = :uuid')->setParameter('uuid', $uuid); |
40
|
|
|
$registration = $qb->getQuery()->getOneOrNullResult(); |
41
|
|
|
return $registration === null ? None::create() : new Some($registration); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDocs} |
46
|
|
|
*/ |
47
|
|
|
public function getNextRegistrations(Event $event, $day, $capacity) |
48
|
|
|
{ |
49
|
|
|
$rsm = new ResultSetMappingBuilder($this->_em); |
50
|
|
|
$rsm->addRootEntityFromClassMetadata('BCRM\BackendBundle\Entity\Event\Registration', 'r'); |
51
|
|
|
|
52
|
|
|
$type = Registration::TYPE_NORMAL; |
53
|
|
|
$eventId = $event->getId(); |
54
|
|
|
$dayName = $day == Ticket::DAY_SATURDAY ? 'saturday' : 'sunday'; |
55
|
|
|
$registrations = "SELECT MAX(id) FROM registration WHERE type = $type AND event_id = $eventId GROUP BY event_id, email ORDER BY created ASC, id ASC"; |
56
|
|
|
$sql = "SELECT * FROM registration WHERE id IN ($registrations) AND email NOT IN (SELECT email FROM ticket WHERE day = $day AND event_id = $eventId) AND $dayName = 1 LIMIT $capacity"; |
57
|
|
|
$query = $this->_em->createNativeQuery( |
58
|
|
|
$sql, |
59
|
|
|
$rsm |
60
|
|
|
); |
61
|
|
|
return $query->getResult(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDocs} |
66
|
|
|
*/ |
67
|
|
|
public function getNextVipRegistrations(Event $event, $day) |
68
|
|
|
{ |
69
|
|
|
$rsm = new ResultSetMappingBuilder($this->_em); |
70
|
|
|
$rsm->addRootEntityFromClassMetadata('BCRM\BackendBundle\Entity\Event\Registration', 'r'); |
71
|
|
|
$types = join(',', array(Registration::TYPE_SPONSOR, Registration::TYPE_VIP)); |
72
|
|
|
$eventId = $event->getId(); |
73
|
|
|
$dayName = $day == Ticket::DAY_SATURDAY ? 'saturday' : 'sunday'; |
74
|
|
|
$registrations = "SELECT MAX(id) FROM registration WHERE type IN ($types) AND event_id = $eventId GROUP BY event_id, email ORDER BY created ASC, id ASC"; |
75
|
|
|
$sql = "SELECT * FROM registration WHERE id IN ($registrations) AND email NOT IN (SELECT email FROM ticket WHERE day = $day AND event_id = $eventId) AND $dayName = 1"; |
76
|
|
|
$query = $this->_em->createNativeQuery( |
77
|
|
|
$sql, |
78
|
|
|
$rsm |
79
|
|
|
); |
80
|
|
|
return $query->getResult(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param Event $event |
86
|
|
|
* @param string $email |
87
|
|
|
* |
88
|
|
|
* @return Option |
89
|
|
|
*/ |
90
|
|
|
public function getRegistrationForEmail(Event $event, $email) |
91
|
|
|
{ |
92
|
|
|
return Option::fromValue($this->createQueryBuilder('r') |
93
|
|
|
->andWhere('r.event = :event')->setParameter('event', $event) |
94
|
|
|
->andWhere('r.email = :email')->setParameter('email', $email) |
95
|
|
|
->andWhere('r.payment IS NOT NULL') |
96
|
|
|
->orderBy('r.created', 'DESC') |
97
|
|
|
->setMaxResults(1) |
98
|
|
|
->getQuery() |
99
|
|
|
->getOneOrNullResult()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function getParticipantList(Event $event) |
106
|
|
|
{ |
107
|
|
|
$qb = $this->createQueryBuilder('r'); |
108
|
|
|
return new ArrayCollection($qb |
109
|
|
|
->where('r.event = :event')->setParameter('event', $event) |
110
|
|
|
->andWhere($qb->expr()->in('r.email', |
111
|
|
|
$this->getEntityManager()->createQueryBuilder() |
112
|
|
|
->select('t.email') |
113
|
|
|
->from('BCRMBackendBundle:Event\Ticket', 't') |
114
|
|
|
->where('t.event = :event')->setParameter('event', $event) |
115
|
|
|
->getDQL() |
116
|
|
|
)) |
117
|
|
|
->andWhere($qb->expr()->in('r.id', |
118
|
|
|
$this->createQueryBuilder('r2') |
119
|
|
|
->select('MAX(r2.id)') |
120
|
|
|
->where('r2.event = :event')->setParameter('event', $event) |
121
|
|
|
->andWhere('r2.participantList = 1') |
122
|
|
|
->andWhere('r2.payment IS NOT NULL') |
123
|
|
|
->groupBy('r2.email') |
124
|
|
|
->getDQL() |
125
|
|
|
)) |
126
|
|
|
->orderBy('r.name') |
127
|
|
|
->getQuery() |
128
|
|
|
->getResult()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Find a registration by uuid |
133
|
|
|
* |
134
|
|
|
* @param string $uuid |
135
|
|
|
* |
136
|
|
|
* @return Option of Registration |
137
|
|
|
*/ |
138
|
|
|
public function findByUuid($uuid) |
139
|
|
|
{ |
140
|
|
|
return Option::fromValue($this->createQueryBuilder('r') |
141
|
|
|
->andWhere('r.uuid = :uuid')->setParameter('uuid', $uuid) |
142
|
|
|
->orderBy('r.id', 'DESC') |
143
|
|
|
->setMaxResults(1) |
144
|
|
|
->getQuery() |
145
|
|
|
->getOneOrNullResult()); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|