3 namespace Rapsys\AirBundle\Controller
;
5 use Symfony\Bridge\Twig\Mime\TemplatedEmail
;
6 use Symfony\Component\DependencyInjection\ContainerAwareTrait
;
7 use Symfony\Component\DependencyInjection\ContainerInterface
;
8 use Symfony\Component\Form\FormError
;
9 use Symfony\Component\HttpFoundation\Request
;
10 use Symfony\Component\HttpFoundation\RequestStack
;
11 use Symfony\Component\HttpFoundation\Response
;
12 use Symfony\Component\Mailer\Exception\TransportExceptionInterface
;
13 use Symfony\Component\Mailer\MailerInterface
;
14 use Symfony\Component\Mime\Address
;
15 use Symfony\Component\Routing\RouterInterface
;
16 use Symfony\Component\Translation\TranslatorInterface
;
18 use Rapsys\AirBundle\Entity\Location
;
19 use Rapsys\AirBundle\Entity\Session
;
20 use Rapsys\AirBundle\Pdf\DisputePdf
;
22 class DefaultController
extends AbstractController
{
26 ///ContainerInterface instance
35 ///Translator instance
36 protected $translator;
45 * Inject container, router and translator interface
47 * @param ContainerInterface $container The container instance
48 * @param RouterInterface $router The router instance
49 * @param TranslatorInterface $translator The translator instance
51 public function __construct(ContainerInterface
$container, RouterInterface
$router, TranslatorInterface
$translator) {
53 $this->config
= $container->getParameter(self
::getAlias());
56 $this->container
= $container;
59 $this->router
= $router;
62 $this->translator
= $translator;
67 'title' => $translator->trans($this->config
['contact']['title']),
68 'mail' => $this->config
['contact']['mail']
71 'by' => $translator->trans($this->config
['copy']['by']),
72 'link' => $this->config
['copy']['link'],
73 'long' => $translator->trans($this->config
['copy']['long']),
74 'short' => $translator->trans($this->config
['copy']['short']),
75 'title' => $this->config
['copy']['title']
78 'description' => null,
83 'donate' => $this->config
['site']['donate'],
84 'ico' => $this->config
['site']['ico'],
85 'logo' => $this->config
['site']['logo'],
86 'png' => $this->config
['site']['png'],
87 'svg' => $this->config
['site']['svg'],
88 'title' => $translator->trans($this->config
['site']['title']),
89 'url' => $router->generate($this->config
['site']['url'])
95 'og' => 'http://ogp.me/ns#',
96 'fb' => 'http://ogp.me/ns/fb#'
99 'og:type' => 'article',
100 'og:site_name' => $this->translator
->trans($this->config
['site']['title']),
101 #'fb:admins' => $this->config['facebook']['admins'],
102 'fb:app_id' => $this->config
['facebook']['apps']
113 * @desc Display the about informations
115 * @param Request $request The request instance
116 * @return Response The rendered view
118 public function about(Request
$request): Response
{
120 $this->context
['page']['title'] = $this->translator
->trans('About');
123 $this->context
['page']['description'] = $this->translator
->trans('Libre Air about');
126 $this->context
['keywords'] = [
127 $this->translator
->trans('about'),
128 $this->translator
->trans('Libre Air')
132 $response = $this->render('@RapsysAir/default/about.html.twig', $this->context
);
133 $response->setEtag(md5($response->getContent()));
134 $response->setPublic();
135 $response->isNotModified($request);
144 * @desc Send a contact mail to configured contact
146 * @param Request $request The request instance
147 * @param MailerInterface $mailer The mailer instance
149 * @return Response The rendered view or redirection
151 public function contact(Request
$request, MailerInterface
$mailer): Response
{
153 $this->context
['page']['title'] = $this->translator
->trans('Contact');
156 $this->context
['page']['description'] = $this->translator
->trans('Contact Libre Air');
159 $this->context
['keywords'] = [
160 $this->translator
->trans('contact'),
161 $this->translator
->trans('Libre Air'),
162 $this->translator
->trans('outdoor'),
163 $this->translator
->trans('Argentine Tango'),
164 $this->translator
->trans('calendar')
167 //Create the form according to the FormType created previously.
168 //And give the proper parameters
169 $form = $this->createForm('Rapsys\AirBundle\Form\ContactType', null, [
170 'action' => $this->generateUrl('rapsys_air_contact'),
174 if ($request->isMethod('POST')) {
175 // Refill the fields in case the form is not valid.
176 $form->handleRequest($request);
178 if ($form->isValid()) {
180 $data = $form->getData();
183 $message = (new TemplatedEmail())
185 ->from(new Address($data['mail'], $data['name']))
187 ->to(new Address($this->context
['contact']['mail'], $this->context
['contact']['title']))
189 ->subject($data['subject'])
191 //Set path to twig templates
192 ->htmlTemplate('@RapsysAir/mail/contact.html.twig')
193 ->textTemplate('@RapsysAir/mail/contact.text.twig')
198 'subject' => $data['subject'],
199 'message' => strip_tags($data['message']),
203 //Try sending message
204 //XXX: mail delivery may silently fail
207 $mailer->send($message);
209 //Redirect on the same route with sent=1 to cleanup form
210 return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+
$request->get('_route_params'));
211 //Catch obvious transport exception
212 } catch(TransportExceptionInterface
$e) {
213 if ($message = $e->getMessage()) {
214 //Add error message mail unreachable
215 $form->get('mail')->addError(new FormError($this->translator
->trans('Unable to contact: %mail%: %message%', ['%mail%' => $this->context
['contact']['mail'], '%message%' => $this->translator
->trans($message)])));
217 //Add error message mail unreachable
218 $form->get('mail')->addError(new FormError($this->translator
->trans('Unable to contact: %mail%', ['%mail%' => $this->context
['contact']['mail']])));
225 return $this->render('@RapsysAir/form/contact.html.twig', ['form' => $form->createView(), 'sent' => $request->query
->get('sent', 0)]+
$this->context
);
231 * @desc Generate a dispute document
233 * @param Request $request The request instance
234 * @param MailerInterface $mailer The mailer instance
236 * @return Response The rendered view or redirection
238 public function dispute(Request
$request, MailerInterface
$mailer): Response
{
239 //Prevent non-guest to access here
240 $this->denyAccessUnlessGranted('ROLE_USER', null, $this->translator
->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator
->trans('User')]));
243 $this->context
['page']['title'] = $this->translator
->trans('Dispute');
246 $this->context
['page']['description'] = $this->translator
->trans('Libre Air dispute');
249 $this->context
['keywords'] = [
250 $this->translator
->trans('dispute'),
251 $this->translator
->trans('Libre Air'),
252 $this->translator
->trans('outdoor'),
253 $this->translator
->trans('Argentine Tango'),
254 $this->translator
->trans('calendar')
257 //Create the form according to the FormType created previously.
258 //And give the proper parameters
259 $form = $this->createForm('Rapsys\AirBundle\Form\DisputeType', ['court' => 'Paris', 'abstract' => 'Pour constater cette prĆ©tendue infraction, les agents verbalisateurs ont pĆ©nĆ©trĆ© dans un jardin privatif, sans visibilitĆ© depuis la voie publique, situĆ© derriĆØre un batiment privĆ©, pour ce faire ils ont franchi au moins un grillage de chantier ou des potteaux mĆ©talliques sĆ©parant le terrain privĆ© de la voie publique de l\'autre cĆ“tĆ© du batiment.'], [
260 'action' => $this->generateUrl('rapsys_air_dispute'),
264 if ($request->isMethod('POST')) {
265 // Refill the fields in case the form is not valid.
266 $form->handleRequest($request);
268 if ($form->isValid()) {
270 $data = $form->getData();
273 if (!empty($data['offense']) && $data['offense'] == 'gathering') {
275 $output = DisputePdf
::genGathering($data['court'], $data['notice'], $data['agent'], $data['service'], $data['abstract'], $this->translator
->trans($this->getUser()->getCivility()->getTitle()), $this->getUser()->getForename(), $this->getUser()->getSurname());
277 } elseif (!empty($data['offense'] && $data['offense'] == 'traffic')) {
279 $output = DisputePdf
::genTraffic($data['court'], $data['notice'], $data['agent'], $data['service'], $data['abstract'], $this->translator
->trans($this->getUser()->getCivility()->getTitle()), $this->getUser()->getForename(), $this->getUser()->getSurname());
280 //Unsupported offense
282 header('Content-Type: text/plain');
287 //Send common headers
288 header('Content-Type: application/pdf');
290 //Send remaining headers
291 header('Cache-Control: private, max-age=0, must-revalidate');
292 header('Pragma: public');
294 //Send content-length
295 header('Content-Length: '.strlen($output));
304 # $message = (new TemplatedEmail())
306 # ->from(new Address($data['mail'], $data['name']))
308 # //XXX: remove the debug set in vendor/symfony/mime/Address.php +46
309 # ->to(new Address($this->config['contact']['mail'], $this->config['contact']['title']))
311 # ->subject($data['subject'])
313 # //Set path to twig templates
314 # ->htmlTemplate('@RapsysAir/mail/contact.html.twig')
315 # ->textTemplate('@RapsysAir/mail/contact.text.twig')
320 # 'subject' => $data['subject'],
321 # 'message' => strip_tags($data['message']),
325 # //Try sending message
326 # //XXX: mail delivery may silently fail
329 # $mailer->send($message);
331 # //Redirect on the same route with sent=1 to cleanup form
332 # return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+$request->get('_route_params'));
333 # //Catch obvious transport exception
334 # } catch(TransportExceptionInterface $e) {
335 # if ($message = $e->getMessage()) {
336 # //Add error message mail unreachable
337 # $form->get('mail')->addError(new FormError($this->translator->trans('Unable to contact: %mail%: %message%', ['%mail%' => $this->config['contact']['mail'], '%message%' => $this->translator->trans($message)])));
339 # //Add error message mail unreachable
340 # $form->get('mail')->addError(new FormError($this->translator->trans('Unable to contact: %mail%', ['%mail%' => $this->config['contact']['mail']])));
347 return $this->render('@RapsysAir/default/dispute.html.twig', ['form' => $form->createView(), 'sent' => $request->query
->get('sent', 0)]+
$this->context
);
353 * @desc Display all granted sessions with an application or login form
355 * @param Request $request The request instance
356 * @return Response The rendered view
358 public function index(Request
$request): Response
{
360 $doctrine = $this->getDoctrine();
363 $this->context
['page']['title'] = $this->translator
->trans('Argentine Tango in Paris');
366 $this->context
['page']['description'] = $this->translator
->trans('Outdoor Argentine Tango session calendar in Paris');
369 $this->context
['keywords'] = [
370 $this->translator
->trans('Argentine Tango'),
371 $this->translator
->trans('Paris'),
372 $this->translator
->trans('outdoor'),
373 $this->translator
->trans('calendar'),
374 $this->translator
->trans('Libre Air')
378 //XXX: only valid for home page
379 $this->context
['facebook']['metas']['og:type'] = 'website';
382 $period = new \
DatePeriod(
383 //Start from first monday of week
384 new \
DateTime('Monday this week'),
385 //Iterate on each day
386 new \
DateInterval('P1D'),
387 //End with next sunday and 4 weeks
389 $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week'
394 $calendar = $doctrine->getRepository(Session
::class)->fetchCalendarByDatePeriod($this->translator
, $period, null, $request->get('session'), !$this->isGranted('IS_AUTHENTICATED_REMEMBERED'));
397 //XXX: we want to display all active locations anyway
398 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period);
401 return $this->render('@RapsysAir/default/index.html.twig', ['calendar' => $calendar, 'locations' => $locations]+
$this->context
);
403 //Set Cache-Control must-revalidate directive
404 //TODO: add a javascript forced refresh after 1h ? or header refresh ?
405 #$response->setPublic(true);
406 #$response->setMaxAge(300);
407 #$response->mustRevalidate();
408 ##$response->setCache(['public' => true, 'max_age' => 300]);
410 //Return the response
415 * The organizer regulation page
417 * @desc Display the organizer regulation policy
419 * @param Request $request The request instance
420 * @return Response The rendered view
422 public function organizerRegulation(Request
$request): Response
{
424 $this->context
['page']['title'] = $this->translator
->trans('Organizer regulation');
427 $this->context
['page']['description'] = $this->translator
->trans('Libre Air organizer regulation');
430 $this->context
['keywords'] = [
431 $this->translator
->trans('organizer regulation'),
432 $this->translator
->trans('Libre Air')
436 $response = $this->render('@RapsysAir/default/organizer_regulation.html.twig', $this->context
);
439 $response->setEtag(md5($response->getContent()));
440 $response->setPublic();
441 $response->isNotModified($request);
448 * The terms of service page
450 * @desc Display the terms of service policy
452 * @param Request $request The request instance
453 * @return Response The rendered view
455 public function termsOfService(Request
$request): Response
{
457 $this->context
['page']['title'] = $this->translator
->trans('Terms of service');
460 $this->context
['page']['description'] = $this->translator
->trans('Libre Air terms of service');
463 $this->context
['keywords'] = [
464 $this->translator
->trans('terms of service'),
465 $this->translator
->trans('Libre Air')
469 $response = $this->render('@RapsysAir/default/terms_of_service.html.twig', $this->context
);
472 $response->setEtag(md5($response->getContent()));
473 $response->setPublic();
474 $response->isNotModified($request);
481 * The frequently asked questions page
483 * @desc Display the frequently asked questions
485 * @param Request $request The request instance
486 * @return Response The rendered view
488 public function frequentlyAskedQuestions(Request
$request): Response
{
490 $this->context
['page']['title'] = $this->translator
->trans('Frequently asked questions');
493 $this->context
['page']['description'] = $this->translator
->trans('Libre Air frequently asked questions');
496 $this->context
['keywords'] = [
497 $this->translator
->trans('frequently asked questions'),
498 $this->translator
->trans('faq'),
499 $this->translator
->trans('Libre Air')
503 $response = $this->render('@RapsysAir/default/frequently_asked_questions.html.twig', $this->context
);
506 $response->setEtag(md5($response->getContent()));
507 $response->setPublic();
508 $response->isNotModified($request);
515 * Return the bundle alias
519 public function getAlias(): string {
528 /*protected function render(string $view, array $parameters = [], Response $response = null): Response {
530 return parent::render($view, $parameters, $response);