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\SponsorBundle\Repository\CategoryRepository; |
10
|
|
|
use Stfalcon\Bundle\SponsorBundle\Repository\SponsorRepository; |
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
14
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class PartnersEventBlockService. |
18
|
|
|
*/ |
19
|
|
|
class PartnersEventBlockService extends AbstractBlockService |
20
|
|
|
{ |
21
|
|
|
/** @var SponsorRepository */ |
22
|
|
|
private $partnerRepository; |
23
|
|
|
|
24
|
|
|
/** @var CategoryRepository */ |
25
|
|
|
private $partnerCategoryRepository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* PartnersEventBlockService constructor. |
29
|
|
|
* |
30
|
|
|
* @param string $name |
31
|
|
|
* @param EngineInterface $templating |
32
|
|
|
* @param ObjectRepository $partnerRepository |
33
|
|
|
* @param ObjectRepository $partnerCategoryRepository |
34
|
|
|
*/ |
35
|
|
|
public function __construct($name, EngineInterface $templating, ObjectRepository $partnerRepository, ObjectRepository $partnerCategoryRepository) |
36
|
|
|
{ |
37
|
|
|
parent::__construct($name, $templating); |
38
|
|
|
|
39
|
|
|
$this->partnerRepository = $partnerRepository; |
|
|
|
|
40
|
|
|
$this->partnerCategoryRepository = $partnerCategoryRepository; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
47
|
|
|
{ |
48
|
|
|
$event = $blockContext->getSetting('event'); |
49
|
|
|
|
50
|
|
|
if (!$event instanceof Event) { |
51
|
|
|
return new NotFoundHttpException(); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$partners = $this->partnerRepository->getSponsorsOfEventWithCategory($event); |
55
|
|
|
|
56
|
|
|
$sortedPartners = []; |
57
|
|
|
foreach ($partners as $key => $partner) { |
58
|
|
|
$partnerCategory = $this->partnerCategoryRepository->find($partner['id']); |
59
|
|
|
if ($partnerCategory) { |
60
|
|
|
$sortedPartners[$partnerCategory->isWideContainer()][$partnerCategory->getSortOrder()][$partnerCategory->getName()][] = $partner[0]; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (isset($sortedPartners[0])) { |
65
|
|
|
krsort($sortedPartners[0]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (isset($sortedPartners[1])) { |
69
|
|
|
krsort($sortedPartners[1]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->renderResponse($blockContext->getTemplate(), [ |
73
|
|
|
'block' => $blockContext->getBlock(), |
74
|
|
|
'settings' => $blockContext->getSettings(), |
75
|
|
|
'partners' => $sortedPartners, |
76
|
|
|
], $response); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function configureSettings(OptionsResolver $resolver) |
83
|
|
|
{ |
84
|
|
|
$resolver->setDefaults([ |
85
|
|
|
'template' => 'ApplicationDefaultBundle:Redesign/Partner:partners.html.twig', |
86
|
|
|
'event' => null, |
87
|
|
|
'event_block' => null, |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.