|
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\Command; |
|
9
|
|
|
|
|
10
|
|
|
use BCRM\BackendBundle\Entity\Event\Event; |
|
11
|
|
|
use BCRM\BackendBundle\Entity\Event\Registration; |
|
12
|
|
|
use BCRM\BackendBundle\Entity\Event\Ticket; |
|
13
|
|
|
use BCRM\BackendBundle\Exception\CommandException; |
|
14
|
|
|
use BCRM\BackendBundle\Service\Event\CreateTicketCommand; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
class CreateTicketsCommand extends ContainerAwareCommand |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var OutputInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $output; |
|
25
|
|
|
|
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
$this |
|
29
|
|
|
->setName('bcrm:tickets:create') |
|
30
|
|
|
->setDescription('Create tickets for the newly registered'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->output = $output; |
|
36
|
|
|
/* @var \BCRM\BackendBundle\Entity\Event\EventRepository $eventRepo */ |
|
37
|
|
|
/* @var \BCRM\BackendBundle\Entity\Event\RegistrationRepository $registrationRepo */ |
|
38
|
|
|
$eventRepo = $this->getContainer()->get('bcrm.backend.repo.event'); |
|
39
|
|
|
$registrationRepo = $this->getContainer()->get('bcrm.backend.repo.registration'); |
|
40
|
|
|
$event = $eventRepo->getNextEvent()->getOrThrow(new CommandException('No event.')); |
|
41
|
|
|
foreach (array(Ticket::DAY_SATURDAY, Ticket::DAY_SUNDAY) as $day) { |
|
42
|
|
|
// Regular tickets |
|
43
|
|
|
$capacity = $eventRepo->getCapacity($event, $day); |
|
44
|
|
|
$this->logVerbose(sprintf('Capacity on day %d: %d', $day, $capacity)); |
|
45
|
|
|
if ($capacity > 0) { |
|
46
|
|
|
foreach ($registrationRepo->getNextRegistrations($event, $day, $capacity) as $registration) { |
|
47
|
|
|
$this->createTicketForRegistration($event, $registration, $day); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
// VIP-Tickets |
|
51
|
|
|
foreach ($registrationRepo->getNextVipRegistrations($event, $day) as $registration) { |
|
52
|
|
|
$this->createTicketForRegistration($event, $registration, $day); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
protected function createTicketForRegistration(Event $event, Registration $registration, $day) |
|
58
|
|
|
{ |
|
59
|
|
|
$commandBus = $this->getContainer()->get('command_bus'); |
|
60
|
|
|
$this->logVerbose(sprintf('Creating day %d ticket for registration %s', $day, $registration)); |
|
61
|
|
|
$command = new CreateTicketCommand(); |
|
62
|
|
|
$command->registration = $registration; |
|
63
|
|
|
$command->day = $day; |
|
64
|
|
|
$command->event = $event; |
|
|
|
|
|
|
65
|
|
|
$commandBus->handle($command); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function logVerbose($msg) |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) return; |
|
71
|
|
|
$this->output->writeln($msg); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..