1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Bundle\DefaultBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Application\Bundle\UserBundle\Entity\User; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
9
|
|
|
use Stfalcon\Bundle\EventBundle\Entity\EventPage; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
12
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Application event controller. |
19
|
|
|
*/ |
20
|
|
|
class EventController extends Controller |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Show all events. |
24
|
|
|
* |
25
|
|
|
* @Route("/events", name="events") |
26
|
|
|
* |
27
|
|
|
* @Template("@ApplicationDefault/Redesign/Event/events.html.twig") |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
public function eventsAction() |
32
|
|
|
{ |
33
|
|
|
$activeEvents = $this->getDoctrine()->getManager() |
34
|
|
|
->getRepository('StfalconEventBundle:Event') |
35
|
|
|
->findBy(['active' => true], ['date' => 'ASC']); |
36
|
|
|
|
37
|
|
|
$pastEvents = $this->getDoctrine()->getManager() |
38
|
|
|
->getRepository('StfalconEventBundle:Event') |
39
|
|
|
->findBy(['active' => false], ['date' => 'DESC']); |
40
|
|
|
|
41
|
|
|
return [ |
42
|
|
|
'activeEvents' => $activeEvents, |
43
|
|
|
'pastEvents' => $pastEvents, |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Show event. |
49
|
|
|
* |
50
|
|
|
* @Route("/event/{eventSlug}", name="event_show_redesign") |
51
|
|
|
* @Route("/event/{eventSlug}", name="event_show") |
52
|
|
|
* |
53
|
|
|
* @param string $eventSlug |
54
|
|
|
* |
55
|
|
|
* @Template("@ApplicationDefault/Redesign/Event/event.html.twig") |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function showAction($eventSlug) |
60
|
|
|
{ |
61
|
|
|
$referralService = $this->get('stfalcon_event.referral.service'); |
62
|
|
|
$referralService->handleRequest($this->container->get('request_stack')->getCurrentRequest()); |
63
|
|
|
|
64
|
|
|
return $this->get('app.event.service')->getEventPagesArr($eventSlug); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Finds and displays a event review. |
69
|
|
|
* |
70
|
|
|
* @Route("/event/{eventSlug}/review/{reviewSlug}", name="event_review_show_redesign") |
71
|
|
|
* |
72
|
|
|
* @param string $eventSlug |
73
|
|
|
* @param string $reviewSlug |
74
|
|
|
* |
75
|
|
|
* @Template("ApplicationDefaultBundle:Redesign/Speaker:report_review.html.twig") |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function showEventReviewAction($eventSlug, $reviewSlug) |
80
|
|
|
{ |
81
|
|
|
return $this->get('app.event.service')->getEventPagesArr($eventSlug, $reviewSlug); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get event header. |
86
|
|
|
* |
87
|
|
|
* @Route(path="/get_modal_header/{slug}/{headerType}", name="get_modal_header", |
88
|
|
|
* options = {"expose"=true}, |
89
|
|
|
* condition="request.isXmlHttpRequest()") |
90
|
|
|
* |
91
|
|
|
* @param string $slug |
92
|
|
|
* @param string $headerType |
93
|
|
|
* |
94
|
|
|
* @return JsonResponse |
95
|
|
|
*/ |
96
|
|
|
public function getModalHeaderAction($slug, $headerType) |
97
|
|
|
{ |
98
|
|
|
$event = $this->getDoctrine() |
99
|
|
|
->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); |
100
|
|
|
if (!$event) { |
|
|
|
|
101
|
|
|
return new JsonResponse(['result' => false, 'error' => 'Unable to find Event by slug: '.$slug]); |
102
|
|
|
} |
103
|
|
|
$html = ''; |
104
|
|
|
if ('buy' === $headerType) { |
105
|
|
|
$html = $this->get('translator')->trans('popup.header.title', ['%event_name%' => $event->getName()]); |
106
|
|
|
} elseif ('reg' === $headerType) { |
107
|
|
|
$html = $this->get('translator')->trans('popup.header_reg.title', ['%event_name%' => $event->getName()]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return new JsonResponse(['result' => true, 'error' => '', 'html' => $html]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get event map position. |
115
|
|
|
* |
116
|
|
|
* @Route(path="/get_map_pos/{slug}", name="get_event_map_position", |
117
|
|
|
* options = {"expose"=true}, |
118
|
|
|
* condition="request.isXmlHttpRequest()") |
119
|
|
|
* |
120
|
|
|
* @param string $slug |
121
|
|
|
* |
122
|
|
|
* @return JsonResponse |
123
|
|
|
*/ |
124
|
|
|
public function getEventMapPosition($slug) |
125
|
|
|
{ |
126
|
|
|
$event = $this->getDoctrine() |
127
|
|
|
->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); |
128
|
|
|
if (!$event) { |
|
|
|
|
129
|
|
|
return new JsonResponse(['result' => false, 'error' => 'Unable to find Event by slug: '.$slug]); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if ($this->get('app.service.google_map_service')->setEventMapPosition($event)) { |
133
|
|
|
$this->getDoctrine()->getManager()->flush($event); |
134
|
|
|
|
135
|
|
|
return new JsonResponse(['result' => true, 'lat' => $event->getLat(), 'lng' => $event->getLng()]); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
return new JsonResponse(['result' => false]); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* User wanna visit an event. |
143
|
|
|
* |
144
|
|
|
* @Route(path="/addwantstovisitevent/{slug}", name="add_wants_to_visit_event", |
145
|
|
|
* options = {"expose"=true}) |
146
|
|
|
* @Security("has_role('ROLE_USER')") |
147
|
|
|
* |
148
|
|
|
* @param string $slug |
149
|
|
|
* @param Request $request |
150
|
|
|
* |
151
|
|
|
* @throws NotFoundHttpException |
152
|
|
|
* |
153
|
|
|
* @return JsonResponse|Response|NotFoundHttpException |
154
|
|
|
*/ |
155
|
|
|
public function userAddWantsToVisitEventAction($slug, Request $request) |
156
|
|
|
{ |
157
|
|
|
/** @var User $user */ |
158
|
|
|
$user = $this->getUser(); |
159
|
|
|
$result = false; |
160
|
|
|
$html = ''; |
161
|
|
|
$flashContent = ''; |
162
|
|
|
$em = $this->getDoctrine()->getManager(); |
163
|
|
|
$event = $this->getDoctrine() |
164
|
|
|
->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); |
165
|
|
|
|
166
|
|
|
if (!$event) { |
|
|
|
|
167
|
|
|
if ($request->isXmlHttpRequest()) { |
168
|
|
|
return new JsonResponse(['result' => $result, 'error' => 'Unable to find Event by slug: '.$slug]); |
169
|
|
|
} |
170
|
|
|
throw $this->createNotFoundException(sprintf('Unable to find Event by slug: %s', $slug)); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if ($event->isActiveAndFuture()) { |
174
|
|
|
$result = $user->addWantsToVisitEvents($event); |
175
|
|
|
$error = $result ? '' : 'cant remove event '.$slug; |
176
|
|
|
} else { |
177
|
|
|
$error = 'Event not active!'; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
if ($result) { |
181
|
|
|
$flashContent = $this->get('translator')->trans('flash_you_registrated.title'); |
182
|
|
|
$html = $this->get('translator')->trans('ticket.status.not_take_apart'); |
183
|
|
|
$em->persist($user); |
184
|
|
|
$em->flush(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
if ($request->isXmlHttpRequest()) { |
188
|
|
|
return new JsonResponse(['result' => $result, 'error' => $error, 'html' => $html, 'flash' => $flashContent]); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return $this->redirect($this->get('app.url_for_redirect')->getRedirectUrl($request->headers->get('referer'))); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* User dont want to visit an event. |
196
|
|
|
* |
197
|
|
|
* @Route("/subwantstovisitevent/{slug}", name="sub_wants_to_visit_event", |
198
|
|
|
* methods={"POST"}, |
199
|
|
|
* options = {"expose"=true}, |
200
|
|
|
* condition="request.isXmlHttpRequest()") |
201
|
|
|
* @Security("has_role('ROLE_USER')") |
202
|
|
|
* |
203
|
|
|
* @param string $slug |
204
|
|
|
* |
205
|
|
|
* @return JsonResponse |
206
|
|
|
*/ |
207
|
|
|
public function userSubWantsToVisitEventAction($slug) |
208
|
|
|
{ |
209
|
|
|
/** @var User $user */ |
210
|
|
|
$user = $this->getUser(); |
211
|
|
|
$result = false; |
212
|
|
|
$html = ''; |
213
|
|
|
$flashContent = ''; |
214
|
|
|
$em = $this->getDoctrine()->getManager(); |
215
|
|
|
$event = $this->getDoctrine() |
216
|
|
|
->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $slug]); |
217
|
|
|
|
218
|
|
|
if (!$event) { |
|
|
|
|
219
|
|
|
return new JsonResponse(['result' => $result, 'error' => 'Unable to find Event by slug: '.$slug]); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if ($event->isActiveAndFuture()) { |
223
|
|
|
$result = $user->subtractWantsToVisitEvents($event); |
224
|
|
|
$error = $result ? '' : 'cant remove event '.$slug; |
225
|
|
|
} else { |
226
|
|
|
$error = 'Event not active!'; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
if ($result) { |
230
|
|
|
$flashContent = $this->get('translator')->trans('flash_you_unsubscribe.title'); |
231
|
|
|
$html = $this->get('translator')->trans('ticket.status.take_apart'); |
232
|
|
|
$em->flush(); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
return new JsonResponse(['result' => $result, 'error' => $error, 'html' => $html, 'flash' => $flashContent]); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @Route(path="/event/{eventSlug}/page/venue", name="show_event_venue_page") |
240
|
|
|
* |
241
|
|
|
* @param string $eventSlug |
242
|
|
|
* |
243
|
|
|
* @Template("ApplicationDefaultBundle:Redesign:venue_review.html.twig") |
244
|
|
|
* |
245
|
|
|
* @return array |
246
|
|
|
*/ |
247
|
|
|
public function showEventVenuePageAction($eventSlug) |
248
|
|
|
{ |
249
|
|
|
$resultArray = $this->get('app.event.service')->getEventPagesArr($eventSlug); |
250
|
|
|
if (null === $resultArray['venuePage']) { |
251
|
|
|
throw $this->createNotFoundException(sprintf('Unable to find page by slug: venue')); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
$newText = $resultArray['venuePage']->getTextNew(); |
255
|
|
|
$text = isset($newText) && !empty($newText) ? $newText : $resultArray['venuePage']->getText(); |
256
|
|
|
|
257
|
|
|
return array_merge($resultArray, ['text' => $text]); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @Route(path="/event/{eventSlug}/page/{pageSlug}", name="show_event_page") |
262
|
|
|
* |
263
|
|
|
* @param string $eventSlug |
264
|
|
|
* @param string $pageSlug |
265
|
|
|
* |
266
|
|
|
* @Template("ApplicationDefaultBundle:Redesign:static.page.html.twig") |
267
|
|
|
* |
268
|
|
|
* @return array |
269
|
|
|
*/ |
270
|
|
|
public function showEventPageInStaticAction($eventSlug, $pageSlug) |
271
|
|
|
{ |
272
|
|
|
$event = $this->getDoctrine() |
273
|
|
|
->getRepository('StfalconEventBundle:Event')->findOneBy(['slug' => $eventSlug]); |
274
|
|
|
if (!$event) { |
|
|
|
|
275
|
|
|
throw $this->createNotFoundException(sprintf('Unable to find event by slug: %s', $eventSlug)); |
276
|
|
|
} |
277
|
|
|
/** @var ArrayCollection $pages */ |
278
|
|
|
$pages = $this->get('app.event.service')->getEventMenuPages($event); |
279
|
|
|
$myPage = null; |
280
|
|
|
/** @var EventPage $page */ |
281
|
|
|
foreach ($pages as $page) { |
282
|
|
|
if ($pageSlug === $page->getSlug()) { |
283
|
|
|
$myPage = $page; |
284
|
|
|
break; |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
if (!$myPage) { |
|
|
|
|
289
|
|
|
throw $this->createNotFoundException(sprintf('Unable to find event page by slug: %s', $pageSlug)); |
290
|
|
|
} |
291
|
|
|
$newText = $myPage->getTextNew(); |
292
|
|
|
$text = isset($newText) && !empty($newText) ? $newText : $myPage->getText(); |
293
|
|
|
|
294
|
|
|
return ['text' => $text]; |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|