|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Application\Bundle\DefaultBundle\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Application\Bundle\DefaultBundle\Repository\TicketCostRepository; |
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
7
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
|
8
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\Event; |
|
9
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\EventGroup; |
|
10
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\EventPage; |
|
11
|
|
|
use Stfalcon\Bundle\EventBundle\Repository\EventRepository; |
|
12
|
|
|
use Stfalcon\Bundle\EventBundle\Repository\ReviewRepository; |
|
13
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
14
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker; |
|
15
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class EventService. |
|
19
|
|
|
*/ |
|
20
|
|
|
class EventService |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var EventRepository */ |
|
23
|
|
|
private $eventRepository; |
|
24
|
|
|
|
|
25
|
|
|
/** @var TicketCostRepository */ |
|
26
|
|
|
private $ticketCostRepository; |
|
27
|
|
|
|
|
28
|
|
|
/** @var ReviewRepository */ |
|
29
|
|
|
private $reviewRepository; |
|
30
|
|
|
|
|
31
|
|
|
/** @var AuthorizationChecker */ |
|
32
|
|
|
private $authorizationChecker; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* EventService constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param ObjectRepository $eventRepository |
|
38
|
|
|
* @param ObjectRepository $ticketCostRepository |
|
39
|
|
|
* @param ObjectRepository $reviewRepository |
|
40
|
|
|
* @param AuthorizationCheckerInterface $authorizationChecker |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(ObjectRepository $eventRepository, ObjectRepository $ticketCostRepository, ObjectRepository $reviewRepository, AuthorizationCheckerInterface $authorizationChecker) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->eventRepository = $eventRepository; |
|
|
|
|
|
|
45
|
|
|
$this->ticketCostRepository = $ticketCostRepository; |
|
|
|
|
|
|
46
|
|
|
$this->reviewRepository = $reviewRepository; |
|
|
|
|
|
|
47
|
|
|
$this->authorizationChecker = $authorizationChecker; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param Event $event |
|
52
|
|
|
* @param null $reviewSlug |
|
|
|
|
|
|
53
|
|
|
* |
|
54
|
|
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getEventPages(Event $event, $reviewSlug = null) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($event->isAdminOnly() && !$this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
|
59
|
|
|
throw new NotFoundHttpException(sprintf('Unable to find event by slug: %s', $event->getSlug())); |
|
60
|
|
|
} |
|
61
|
|
|
$review = null; |
|
62
|
|
|
if ($reviewSlug) { |
|
|
|
|
|
|
63
|
|
|
$review = $this->reviewRepository->findOneBy(['slug' => $reviewSlug]); |
|
64
|
|
|
|
|
65
|
|
|
if (!$review) { |
|
66
|
|
|
throw new NotFoundHttpException('Unable to find Review entity.'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** @var ArrayCollection $pages */ |
|
71
|
|
|
$pages = $this->getEventMenuPages($event); |
|
72
|
|
|
|
|
73
|
|
|
/** @var EventPage $page */ |
|
74
|
|
|
$programPage = null; |
|
75
|
|
|
$venuePage = null; |
|
76
|
|
|
foreach ($pages as $key => $page) { |
|
77
|
|
|
if ('program' === $page->getSlug()) { |
|
78
|
|
|
$programPage = $page; |
|
79
|
|
|
unset($pages[$key]); |
|
80
|
|
|
} elseif ('venue' === $page->getSlug()) { |
|
81
|
|
|
$venuePage = $page; |
|
82
|
|
|
unset($pages[$key]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$eventCurrentAmount = $this->ticketCostRepository->getEventCurrentCost($event); |
|
87
|
|
|
|
|
88
|
|
|
$futureEvent = !$event->isActiveAndFuture() && $event->getGroup() instanceof EventGroup ? $this->eventRepository->findFutureEventFromSameGroup($event->getGroup()) : null; |
|
89
|
|
|
|
|
90
|
|
|
return [ |
|
91
|
|
|
'event' => $event, |
|
92
|
|
|
'programPage' => $programPage, |
|
93
|
|
|
'venuePage' => $venuePage, |
|
94
|
|
|
'pages' => $pages, |
|
95
|
|
|
'review' => $review, |
|
96
|
|
|
'eventCurrentAmount' => $eventCurrentAmount, |
|
97
|
|
|
'futureEvent' => $futureEvent, |
|
98
|
|
|
]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Return array of event with pages. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $eventSlug |
|
105
|
|
|
* @param string|null $reviewSlug |
|
106
|
|
|
* |
|
107
|
|
|
* @return array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getEventPagesArr($eventSlug, $reviewSlug = null) |
|
110
|
|
|
{ |
|
111
|
|
|
/** @var Event $event */ |
|
112
|
|
|
$event = $this->eventRepository->findOneBy(['slug' => $eventSlug]); |
|
113
|
|
|
if (!$event instanceof Event) { |
|
|
|
|
|
|
114
|
|
|
throw new NotFoundHttpException(sprintf('Unable to find event by slug: %s', $eventSlug)); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $this->getEventPages($event, $reviewSlug); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Get event pages that may show. |
|
122
|
|
|
* |
|
123
|
|
|
* @param Event $event |
|
124
|
|
|
* |
|
125
|
|
|
* @return array |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getEventMenuPages(Event $event) |
|
128
|
|
|
{ |
|
129
|
|
|
/** TODO замінити на репозіторій */ |
|
130
|
|
|
$pages = []; |
|
131
|
|
|
/** @var EventPage $page */ |
|
132
|
|
|
foreach ($event->getPages() as $page) { |
|
133
|
|
|
if ($page->isShowInMenu()) { |
|
134
|
|
|
$pages[] = $page; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return $pages; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
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.