1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Bundle\DefaultBundle\Service\EventBlock; |
4
|
|
|
|
5
|
|
|
use Application\Bundle\DefaultBundle\Service\TicketService; |
6
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
7
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractBlockService; |
8
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Event; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
12
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class TicketStatusEventBlockService. |
16
|
|
|
*/ |
17
|
|
|
class TicketStatusEventBlockService extends AbstractBlockService |
18
|
|
|
{ |
19
|
|
|
/** @var TicketService */ |
20
|
|
|
private $ticketService; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* TicketStatusEventBlockService constructor. |
24
|
|
|
* |
25
|
|
|
* @param string $name |
26
|
|
|
* @param EngineInterface $templating |
27
|
|
|
* @param TicketService $ticketService |
28
|
|
|
*/ |
29
|
|
|
public function __construct($name, EngineInterface $templating, TicketService $ticketService) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($name, $templating); |
32
|
|
|
|
33
|
|
|
$this->ticketService = $ticketService; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
40
|
|
|
{ |
41
|
|
|
$event = $blockContext->getSetting('event'); |
42
|
|
|
|
43
|
|
|
if (!$event instanceof Event) { |
44
|
|
|
return new NotFoundHttpException(); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$position = $blockContext->getSetting('position'); |
48
|
|
|
$ticketCost = $blockContext->getSetting('ticket_cost'); |
49
|
|
|
|
50
|
|
|
$result = $this->ticketService->getTicketHtmlData( |
51
|
|
|
$event, |
52
|
|
|
$position, |
53
|
|
|
$ticketCost |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
return $this->renderResponse($blockContext->getTemplate(), [ |
57
|
|
|
'block' => $blockContext->getBlock(), |
58
|
|
|
'event' => $event, |
59
|
|
|
'result' => $result, |
60
|
|
|
], $response); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function configureSettings(OptionsResolver $resolver) |
67
|
|
|
{ |
68
|
|
|
$resolver->setDefaults([ |
69
|
|
|
'template' => 'ApplicationDefaultBundle:Redesign/Event:event.ticket.status.html.twig', |
70
|
|
|
'event' => null, |
71
|
|
|
'position' => 'price_block', |
72
|
|
|
'ticket_cost' => null, |
73
|
|
|
'event_block' => null, |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: