|
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\WebBundle\Controller; |
|
9
|
|
|
|
|
10
|
|
|
use BCRM\BackendBundle\Entity\Event\Event; |
|
11
|
|
|
use BCRM\BackendBundle\Entity\Event\EventRepository; |
|
12
|
|
|
use BCRM\BackendBundle\Entity\Event\RegistrationRepository; |
|
13
|
|
|
use BCRM\BackendBundle\Entity\Event\Ticket; |
|
14
|
|
|
use BCRM\BackendBundle\Entity\Event\TicketRepository; |
|
15
|
|
|
use BCRM\BackendBundle\Service\Concierge\CheckinCommand; |
|
16
|
|
|
use BCRM\WebBundle\Content\ContentReader; |
|
17
|
|
|
use BCRM\WebBundle\Exception\AccesDeniedHttpException; |
|
18
|
|
|
use BCRM\WebBundle\Exception\BadRequestException; |
|
19
|
|
|
use Carbon\Carbon; |
|
20
|
|
|
use LiteCQRS\Bus\CommandBus; |
|
21
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
22
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
23
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
24
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
25
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
26
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
27
|
|
|
use Symfony\Component\Validator\Constraints\DateTime; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Manages event checkins. |
|
31
|
|
|
*/ |
|
32
|
|
|
class CheckinController |
|
33
|
|
|
{ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
EventRepository $eventRepo, |
|
36
|
|
|
TicketRepository $ticketRepo, |
|
37
|
|
|
RegistrationRepository $registrationRepo, |
|
38
|
|
|
CommandBus $commandBus |
|
39
|
|
|
) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->ticketRepo = $ticketRepo; |
|
|
|
|
|
|
42
|
|
|
$this->eventRepo = $eventRepo; |
|
|
|
|
|
|
43
|
|
|
$this->registrationRepo = $registrationRepo; |
|
|
|
|
|
|
44
|
|
|
$this->commandBus = $commandBus; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param Request $request |
|
49
|
|
|
* @param $id |
|
50
|
|
|
* @param $code |
|
51
|
|
|
* |
|
52
|
|
|
* @return array|RedirectResponse |
|
53
|
|
|
* @Template() |
|
54
|
|
|
*/ |
|
55
|
|
|
public function checkinAction(Request $request, $id, $code) |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
/* @var $ticket Ticket */ |
|
58
|
|
|
$ticket = $this->ticketRepo->getTicketByIdAndCode($id, $code)->getOrThrow(new NotFoundHttpException('Unknown ticket.')); |
|
59
|
|
|
|
|
60
|
|
|
// Do not allow double checkins |
|
61
|
|
|
if ($ticket->isCheckedIn()) { |
|
62
|
|
|
throw new BadRequestException('Already checked in!'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Do not allow checkins on the wrong day |
|
66
|
|
|
/* @var $event Event */ |
|
67
|
|
|
$event = $this->eventRepo->getNextEvent()->getOrThrow(new AccesDeniedHttpException('No event.')); |
|
68
|
|
|
$now = new Carbon(); |
|
69
|
|
|
$start = Carbon::createFromTimestamp($event->getStart()->getTimestamp()); |
|
70
|
|
|
$start->setTime(0, 0, 0); |
|
71
|
|
|
if ($ticket->isSunday()) { |
|
72
|
|
|
$start->modify('+1day'); |
|
73
|
|
|
} |
|
74
|
|
|
$end = clone $start; |
|
75
|
|
|
$end->setTime(23, 59, 59); |
|
76
|
|
|
if (!$now->between($start, $end)) { |
|
77
|
|
|
throw new BadRequestException('Wrong day!'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$registrationOption = $this->registrationRepo->getRegistrationForEmail($ticket->getEvent(), $ticket->getEmail()); |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
// Record checkin |
|
84
|
|
|
$command = new CheckinCommand(); |
|
85
|
|
|
$command->ticket = $ticket; |
|
86
|
|
|
$this->commandBus->handle($command); |
|
87
|
|
|
|
|
88
|
|
|
return array( |
|
89
|
|
|
'ticket' => $ticket, |
|
90
|
|
|
'registration' => $registrationOption->getOrElse(null), |
|
91
|
|
|
); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: