3 namespace Rapsys\AirBundle\Controller
;
5 use Symfony\Bridge\Twig\Mime\TemplatedEmail
;
6 use Symfony\Component\Form\FormError
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Symfony\Component\HttpFoundation\Response
;
9 use Symfony\Component\Mailer\Exception\TransportExceptionInterface
;
10 use Symfony\Component\Mailer\MailerInterface
;
11 use Symfony\Component\Mime\Address
;
13 use Rapsys\AirBundle\Entity\Location
;
14 use Rapsys\AirBundle\Entity\Session
;
15 use Rapsys\AirBundle\Pdf\DisputePdf
;
17 class DefaultController
extends AbstractController
{
21 * @desc Display the about informations
23 * @param Request $request The request instance
24 * @return Response The rendered view
26 public function about(Request
$request): Response
{
28 $this->context
['title'] = $this->translator
->trans('About');
31 $this->context
['description'] = $this->translator
->trans('Libre Air about');
34 $this->context
['keywords'] = [
35 $this->translator
->trans('about'),
36 $this->translator
->trans('Libre Air')
40 $response = $this->render('@RapsysAir/default/about.html.twig', $this->context
);
41 $response->setEtag(md5($response->getContent()));
42 $response->setPublic();
43 $response->isNotModified($request);
52 * @desc Send a contact mail to configured contact
54 * @param Request $request The request instance
55 * @param MailerInterface $mailer The mailer instance
57 * @return Response The rendered view or redirection
59 public function contact(Request
$request, MailerInterface
$mailer): Response
{
61 $this->context
['title'] = $this->translator
->trans('Contact');
64 $this->context
['description'] = $this->translator
->trans('Contact Libre Air');
67 $this->context
['keywords'] = [
68 $this->translator
->trans('contact'),
69 $this->translator
->trans('Libre Air'),
70 $this->translator
->trans('outdoor'),
71 $this->translator
->trans('Argentine Tango'),
72 $this->translator
->trans('calendar')
75 //Create the form according to the FormType created previously.
76 //And give the proper parameters
77 $form = $this->createForm('Rapsys\AirBundle\Form\ContactType', null, [
78 'action' => $this->generateUrl('rapsys_air_contact'),
82 if ($request->isMethod('POST')) {
83 // Refill the fields in case the form is not valid.
84 $form->handleRequest($request);
86 if ($form->isValid()) {
88 $data = $form->getData();
91 $message = (new TemplatedEmail())
93 ->from(new Address($data['mail'], $data['name']))
95 ->to(new Address($this->context
['contact']['mail'], $this->context
['contact']['title']))
97 ->subject($data['subject'])
99 //Set path to twig templates
100 ->htmlTemplate('@RapsysAir/mail/contact.html.twig')
101 ->textTemplate('@RapsysAir/mail/contact.text.twig')
106 'subject' => $data['subject'],
107 'message' => strip_tags($data['message']),
111 //Try sending message
112 //XXX: mail delivery may silently fail
115 $mailer->send($message);
117 //Redirect on the same route with sent=1 to cleanup form
118 return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+
$request->get('_route_params'));
119 //Catch obvious transport exception
120 } catch(TransportExceptionInterface
$e) {
121 if ($message = $e->getMessage()) {
122 //Add error message mail unreachable
123 $form->get('mail')->addError(new FormError($this->translator
->trans('Unable to contact: %mail%: %message%', ['%mail%' => $this->context
['contact']['mail'], '%message%' => $this->translator
->trans($message)])));
125 //Add error message mail unreachable
126 $form->get('mail')->addError(new FormError($this->translator
->trans('Unable to contact: %mail%', ['%mail%' => $this->context
['contact']['mail']])));
133 return $this->render('@RapsysAir/form/contact.html.twig', ['form' => $form->createView(), 'sent' => $request->query
->get('sent', 0)]+
$this->context
);
139 * @desc Generate a dispute document
141 * @param Request $request The request instance
142 * @param MailerInterface $mailer The mailer instance
144 * @return Response The rendered view or redirection
146 public function dispute(Request
$request, MailerInterface
$mailer): Response
{
147 //Prevent non-guest to access here
148 $this->denyAccessUnlessGranted('ROLE_USER', null, $this->translator
->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator
->trans('User')]));
151 $this->context
['title'] = $this->translator
->trans('Dispute');
154 $this->context
['description'] = $this->translator
->trans('Libre Air dispute');
157 $this->context
['keywords'] = [
158 $this->translator
->trans('dispute'),
159 $this->translator
->trans('Libre Air'),
160 $this->translator
->trans('outdoor'),
161 $this->translator
->trans('Argentine Tango'),
162 $this->translator
->trans('calendar')
165 //Create the form according to the FormType created previously.
166 //And give the proper parameters
167 $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.'], [
168 'action' => $this->generateUrl('rapsys_air_dispute'),
172 if ($request->isMethod('POST')) {
173 // Refill the fields in case the form is not valid.
174 $form->handleRequest($request);
176 if ($form->isValid()) {
178 $data = $form->getData();
181 if (!empty($data['offense']) && $data['offense'] == 'gathering') {
183 $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());
185 } elseif (!empty($data['offense'] && $data['offense'] == 'traffic')) {
187 $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());
188 //Unsupported offense
190 header('Content-Type: text/plain');
195 //Send common headers
196 header('Content-Type: application/pdf');
198 //Send remaining headers
199 header('Cache-Control: private, max-age=0, must-revalidate');
200 header('Pragma: public');
202 //Send content-length
203 header('Content-Length: '.strlen($output));
212 # $message = (new TemplatedEmail())
214 # ->from(new Address($data['mail'], $data['name']))
216 # //XXX: remove the debug set in vendor/symfony/mime/Address.php +46
217 # ->to(new Address($this->config['contact']['mail'], $this->config['contact']['title']))
219 # ->subject($data['subject'])
221 # //Set path to twig templates
222 # ->htmlTemplate('@RapsysAir/mail/contact.html.twig')
223 # ->textTemplate('@RapsysAir/mail/contact.text.twig')
228 # 'subject' => $data['subject'],
229 # 'message' => strip_tags($data['message']),
233 # //Try sending message
234 # //XXX: mail delivery may silently fail
237 # $mailer->send($message);
239 # //Redirect on the same route with sent=1 to cleanup form
240 # return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+$request->get('_route_params'));
241 # //Catch obvious transport exception
242 # } catch(TransportExceptionInterface $e) {
243 # if ($message = $e->getMessage()) {
244 # //Add error message mail unreachable
245 # $form->get('mail')->addError(new FormError($this->translator->trans('Unable to contact: %mail%: %message%', ['%mail%' => $this->config['contact']['mail'], '%message%' => $this->translator->trans($message)])));
247 # //Add error message mail unreachable
248 # $form->get('mail')->addError(new FormError($this->translator->trans('Unable to contact: %mail%', ['%mail%' => $this->config['contact']['mail']])));
255 return $this->render('@RapsysAir/default/dispute.html.twig', ['form' => $form->createView(), 'sent' => $request->query
->get('sent', 0)]+
$this->context
);
261 * @desc Display all granted sessions with an application or login form
263 * @param Request $request The request instance
264 * @return Response The rendered view
266 public function index(Request
$request): Response
{
268 $doctrine = $this->getDoctrine();
271 $this->context
['title'] = $this->translator
->trans('Argentine Tango in Paris');
274 $this->context
['description'] = $this->translator
->trans('Outdoor Argentine Tango session calendar in Paris');
277 $this->context
['keywords'] = [
278 $this->translator
->trans('Argentine Tango'),
279 $this->translator
->trans('Paris'),
280 $this->translator
->trans('outdoor'),
281 $this->translator
->trans('calendar'),
282 $this->translator
->trans('Libre Air')
286 //XXX: only valid for home page
287 $this->context
['facebook']['metas']['og:type'] = 'website';
290 $period = new \
DatePeriod(
291 //Start from first monday of week
292 new \
DateTime('Monday this week'),
293 //Iterate on each day
294 new \
DateInterval('P1D'),
295 //End with next sunday and 4 weeks
297 $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week'
302 $calendar = $doctrine->getRepository(Session
::class)->fetchCalendarByDatePeriod($this->translator
, $period, null, $request->get('session'), !$this->isGranted('IS_AUTHENTICATED_REMEMBERED'), $request->getLocale());
305 //XXX: we want to display all active locations anyway
306 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period);
309 return $this->render('@RapsysAir/default/index.html.twig', ['calendar' => $calendar, 'locations' => $locations]+
$this->context
);
311 //Set Cache-Control must-revalidate directive
312 //TODO: add a javascript forced refresh after 1h ? or header refresh ?
313 #$response->setPublic(true);
314 #$response->setMaxAge(300);
315 #$response->mustRevalidate();
316 ##$response->setCache(['public' => true, 'max_age' => 300]);
318 //Return the response
323 * The organizer regulation page
325 * @desc Display the organizer regulation policy
327 * @param Request $request The request instance
328 * @return Response The rendered view
330 public function organizerRegulation(Request
$request): Response
{
332 $this->context
['title'] = $this->translator
->trans('Organizer regulation');
335 $this->context
['description'] = $this->translator
->trans('Libre Air organizer regulation');
338 $this->context
['keywords'] = [
339 $this->translator
->trans('organizer regulation'),
340 $this->translator
->trans('Libre Air')
344 $response = $this->render('@RapsysAir/default/organizer_regulation.html.twig', $this->context
);
347 $response->setEtag(md5($response->getContent()));
348 $response->setPublic();
349 $response->isNotModified($request);
356 * The terms of service page
358 * @desc Display the terms of service policy
360 * @param Request $request The request instance
361 * @return Response The rendered view
363 public function termsOfService(Request
$request): Response
{
365 $this->context
['title'] = $this->translator
->trans('Terms of service');
368 $this->context
['description'] = $this->translator
->trans('Libre Air terms of service');
371 $this->context
['keywords'] = [
372 $this->translator
->trans('terms of service'),
373 $this->translator
->trans('Libre Air')
377 $response = $this->render('@RapsysAir/default/terms_of_service.html.twig', $this->context
);
380 $response->setEtag(md5($response->getContent()));
381 $response->setPublic();
382 $response->isNotModified($request);
389 * The frequently asked questions page
391 * @desc Display the frequently asked questions
393 * @param Request $request The request instance
394 * @return Response The rendered view
396 public function frequentlyAskedQuestions(Request
$request): Response
{
398 $this->context
['title'] = $this->translator
->trans('Frequently asked questions');
401 $this->context
['description'] = $this->translator
->trans('Libre Air frequently asked questions');
404 $this->context
['keywords'] = [
405 $this->translator
->trans('frequently asked questions'),
406 $this->translator
->trans('faq'),
407 $this->translator
->trans('Libre Air')
411 $response = $this->render('@RapsysAir/default/frequently_asked_questions.html.twig', $this->context
);
414 $response->setEtag(md5($response->getContent()));
415 $response->setPublic();
416 $response->isNotModified($request);
427 /*protected function render(string $view, array $parameters = [], Response $response = null): Response {
429 return parent::render($view, $parameters, $response);