1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Command; |
4
|
|
|
|
5
|
|
|
use AppBundle\Domain\PerformanceEvent\PerformanceEventInterface; |
6
|
|
|
use AppBundle\Domain\Ticket\TicketInterface; |
7
|
|
|
use Doctrine\ORM\EntityManager; |
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class GenerateTicketsCommand extends ContainerAwareCommand |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** @var PerformanceEventInterface */ |
18
|
|
|
public $performanceEventService; |
19
|
|
|
|
20
|
|
|
/** @var TicketInterface */ |
21
|
|
|
public $ticketService; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
PerformanceEventInterface $performanceEventService, |
25
|
|
|
TicketInterface $ticketService |
26
|
|
|
) { |
27
|
|
|
$this->performanceEventService = $performanceEventService; |
28
|
|
|
$this->ticketService = $ticketService; |
29
|
|
|
parent::__construct(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function configure() |
33
|
|
|
{ |
34
|
|
|
$this |
35
|
|
|
->setName('app:generate-tickets') |
36
|
|
|
->setDescription('Generate new Set of Tickets for performanceEvent') |
37
|
|
|
->addArgument( |
38
|
|
|
'performanceEventId', |
39
|
|
|
InputArgument::REQUIRED, |
40
|
|
|
'The Performance Event ID.' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'force', |
44
|
|
|
'f', |
45
|
|
|
InputOption::VALUE_OPTIONAL, |
46
|
|
|
'Remove previously generated tickets set for PerformanceEvent and generates new one.', |
47
|
|
|
false |
48
|
|
|
) |
49
|
|
|
; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
|
|
$startTime = new \DateTime('now'); |
56
|
|
|
|
57
|
|
|
/** @var EntityManager $em */ |
58
|
|
|
$output->writeln('<comment>Running Tickets Generation</comment>'); |
59
|
|
|
|
60
|
|
|
$performanceEventId = (int) $input->getArgument('performanceEventId') ?: null; |
61
|
|
|
$force = (bool) $input->getOption('force') ? true : false; |
62
|
|
|
|
63
|
|
|
$this->ticketService->generateSet($this->performanceEventService->getById($performanceEventId), $force); |
64
|
|
|
|
65
|
|
|
$output->writeln(sprintf('<info>SUCCESS</info>')); |
66
|
|
|
} catch (\Exception $e) { |
67
|
|
|
$output->writeln('<error>ERROR Generating Tickets: '.$e->getMessage().'</error>'); |
68
|
|
|
} finally { |
69
|
|
|
$finishTime = new \DateTime('now'); |
70
|
|
|
$interval = $startTime->diff($finishTime); |
71
|
|
|
$output->writeln(sprintf('<comment>DONE in %s seconds<comment>', $interval->s)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|