1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Bundle\DefaultBundle\Service\EventBlock; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
6
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractBlockService; |
7
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
8
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Event; |
9
|
|
|
use Stfalcon\Bundle\EventBundle\Repository\ReviewRepository; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
13
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ReviewsEventBlockService. |
17
|
|
|
*/ |
18
|
|
|
class ReviewsEventBlockService extends AbstractBlockService |
19
|
|
|
{ |
20
|
|
|
/** @var ReviewRepository */ |
21
|
|
|
private $reviewRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* SpeakersEventBlockService constructor. |
25
|
|
|
* |
26
|
|
|
* @param string $name |
27
|
|
|
* @param EngineInterface $templating |
28
|
|
|
* @param ObjectRepository $reviewRepository |
29
|
|
|
*/ |
30
|
|
|
public function __construct($name, EngineInterface $templating, ObjectRepository $reviewRepository) |
31
|
|
|
{ |
32
|
|
|
parent::__construct($name, $templating); |
33
|
|
|
|
34
|
|
|
$this->reviewRepository = $reviewRepository; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
41
|
|
|
{ |
42
|
|
|
$event = $blockContext->getSetting('event'); |
43
|
|
|
|
44
|
|
|
if (!$event instanceof Event) { |
45
|
|
|
return new NotFoundHttpException(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$reviews = $this->reviewRepository->findReviewsByEvent($event); |
49
|
|
|
|
50
|
|
|
return $this->renderResponse($blockContext->getTemplate(), [ |
51
|
|
|
'block' => $blockContext->getBlock(), |
52
|
|
|
'reviews' => $reviews, |
53
|
|
|
'event' => $event, |
54
|
|
|
], $response); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function configureSettings(OptionsResolver $resolver) |
61
|
|
|
{ |
62
|
|
|
$resolver->setDefaults([ |
63
|
|
|
'template' => 'ApplicationDefaultBundle:Redesign/Event:event.reviews.html.twig', |
64
|
|
|
'event' => null, |
65
|
|
|
'event_block' => null, |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.