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
|
|
|
use Symfony\Component\Translation\IdentityTranslator; |
15
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class SpeakersEventBlockService. |
19
|
|
|
*/ |
20
|
|
|
class SpeakersEventBlockService extends AbstractBlockService |
21
|
|
|
{ |
22
|
|
|
/** @var IdentityTranslator */ |
23
|
|
|
private $translator; |
24
|
|
|
|
25
|
|
|
/** @var ReviewRepository */ |
26
|
|
|
private $reviewRepository; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* SpeakersEventBlockService constructor. |
30
|
|
|
* |
31
|
|
|
* @param string $name |
32
|
|
|
* @param EngineInterface $templating |
33
|
|
|
* @param TranslatorInterface $translator |
34
|
|
|
* @param ObjectRepository $reviewRepository |
35
|
|
|
*/ |
36
|
|
|
public function __construct($name, EngineInterface $templating, TranslatorInterface $translator, ObjectRepository $reviewRepository) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($name, $templating); |
39
|
|
|
|
40
|
|
|
$this->translator = $translator; |
|
|
|
|
41
|
|
|
$this->reviewRepository = $reviewRepository; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
48
|
|
|
{ |
49
|
|
|
$event = $blockContext->getSetting('event'); |
50
|
|
|
|
51
|
|
|
if (!$event instanceof Event) { |
52
|
|
|
return new NotFoundHttpException(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$speakers = $event->getSpeakers(); |
56
|
|
|
|
57
|
|
|
/** @var $speaker \Stfalcon\Bundle\EventBundle\Entity\Speaker */ |
58
|
|
|
foreach ($speakers as &$speaker) { |
59
|
|
|
$speaker->setReviews( |
60
|
|
|
$this->reviewRepository->findReviewsOfSpeakerForEvent($speaker, $event) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this->renderResponse($blockContext->getTemplate(), [ |
65
|
|
|
'block' => $blockContext->getBlock(), |
66
|
|
|
'templateTitle' => $this->translator->trans('speaker.title'), |
67
|
|
|
'speakers' => $speakers, |
68
|
|
|
'section_id' => 'speakers-event', |
69
|
|
|
'with_review' => true, |
70
|
|
|
'event' => $event, |
71
|
|
|
], $response); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function configureSettings(OptionsResolver $resolver) |
78
|
|
|
{ |
79
|
|
|
$resolver->setDefaults([ |
80
|
|
|
'template' => 'ApplicationDefaultBundle:Redesign/Event:event.speakers.html.twig', |
81
|
|
|
'event' => null, |
82
|
|
|
'event_block' => null, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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.