|
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\PrintBundle\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\PrintBundle\Exception\AccesDeniedHttpException; |
|
16
|
|
|
use BCRM\PrintBundle\Exception\NotFoundHttpException; |
|
17
|
|
|
use Carbon\Carbon; |
|
18
|
|
|
use LiteCQRS\Bus\CommandBus; |
|
19
|
|
|
use LiteCQRS\Plugin\CRUD\Model\Commands\UpdateResourceCommand; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Dashboard for the event concierge. |
|
26
|
|
|
*/ |
|
27
|
|
|
class PrintingController |
|
28
|
|
|
{ |
|
29
|
|
View Code Duplication |
public function __construct(EventRepository $eventRepo, RegistrationRepository $registrationRepo, TicketRepository $ticketRepo, CommandBus $commandBus, RouterInterface $router, $schemeAndHost) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
$this->eventRepo = $eventRepo; |
|
|
|
|
|
|
32
|
|
|
$this->ticketRepo = $ticketRepo; |
|
|
|
|
|
|
33
|
|
|
$this->registrationRepo = $registrationRepo; |
|
|
|
|
|
|
34
|
|
|
$this->commandBus = $commandBus; |
|
|
|
|
|
|
35
|
|
|
$this->router = $router; |
|
|
|
|
|
|
36
|
|
|
$this->schemeAndHost = trim($schemeAndHost, '/ '); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* List unprinted tickets. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function queueAction() |
|
43
|
|
|
{ |
|
44
|
|
|
/* @var $event Event */ |
|
45
|
|
|
$event = $this->eventRepo->getNextEvent()->getOrThrow(new AccesDeniedHttpException('No event.')); |
|
46
|
|
|
|
|
47
|
|
|
// Do not allow checkins on the wrong day |
|
48
|
|
|
$now = new Carbon(); |
|
49
|
|
|
$start = Carbon::createFromTimestamp($event->getStart()->getTimestamp()); |
|
50
|
|
|
$day = |
|
|
|
|
|
|
51
|
|
|
$start->setTime(0, 0, 0); |
|
52
|
|
|
$end = clone $start; |
|
53
|
|
|
$end->setTime(23, 59, 59); |
|
54
|
|
|
$day = $now->between($start, $end) ? Ticket::DAY_SATURDAY : Ticket::DAY_SUNDAY; |
|
55
|
|
|
$items = array(); |
|
56
|
|
|
foreach ($this->ticketRepo->getUnprintedTickets($event, $day) as $ticket) { |
|
57
|
|
|
$registration = $this->registrationRepo->getRegistrationForEmail($event, $ticket->getEmail())->get(); |
|
58
|
|
|
$type = null; |
|
|
|
|
|
|
59
|
|
|
$items[] = array( |
|
60
|
|
|
'@context' => 'http://barcamp-rheinmain.de/jsonld/Ticket', |
|
61
|
|
|
'@subject' => $this->schemeAndHost . $this->router->generate('bcrmprint_ticket', array('id' => $ticket->getId(), 'code' => $ticket->getCode())), |
|
62
|
|
|
'name' => $ticket->getName(), |
|
63
|
|
|
'twitter' => $registration->getTwitter(), |
|
64
|
|
|
'code' => $ticket->getCode(), |
|
65
|
|
|
'day' => $ticket->getDay(), |
|
66
|
|
|
'tags' => $registration->getTags(), |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
$data = array('items' => $items); |
|
70
|
|
|
$response = new Response(json_encode($data)); |
|
71
|
|
|
$response->setCharset('utf-8'); |
|
72
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
|
73
|
|
|
return $response; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Mark the given ticket as printed. |
|
78
|
|
|
* |
|
79
|
|
|
* @param Request $request |
|
80
|
|
|
* @param int $id |
|
81
|
|
|
* @param string $code |
|
82
|
|
|
* |
|
83
|
|
|
* @return Response |
|
84
|
|
|
*/ |
|
85
|
|
|
public function printAction(Request $request, $id, $code) |
|
86
|
|
|
{ |
|
87
|
|
|
$ticket = $this->ticketRepo->getTicketByIdAndCode($id, $code)->getOrThrow(new NotFoundHttpException('Ticket not found.')); |
|
|
|
|
|
|
88
|
|
|
$updateCommand = new UpdateResourceCommand(); |
|
89
|
|
|
$updateCommand->class = '\BCRM\BackendBundle\Entity\Event\Ticket'; |
|
90
|
|
|
$updateCommand->id = $id; |
|
91
|
|
|
$updateCommand->data = array('printed' => $request->getMethod() === 'PATCH'); |
|
92
|
|
|
$this->commandBus->handle($updateCommand); |
|
93
|
|
|
$response = new Response(json_encode(array('status' => 'OK'))); |
|
94
|
|
|
$response->setCharset('utf-8'); |
|
95
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
|
96
|
|
|
return $response; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
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.