3 namespace Rapsys\AirBundle\Controller
; 
   5 use Rapsys\AirBundle\Entity\Application
; 
   6 use Rapsys\AirBundle\Entity\Session
; 
   7 use Symfony\Bridge\Twig\Mime\TemplatedEmail
; 
   8 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController
; 
   9 use Symfony\Component\DependencyInjection\ContainerInterface
; 
  10 use Symfony\Component\Form\FormError
; 
  11 use Symfony\Component\HttpFoundation\Request
; 
  12 use Symfony\Component\Mailer\Exception\TransportExceptionInterface
; 
  13 use Symfony\Component\Mailer\MailerInterface
; 
  14 use Symfony\Component\Mime\Address
; 
  15 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
; 
  16 use Symfony\Component\Routing\RouterInterface
; 
  17 use Symfony\Component\Translation\TranslatorInterface
; 
  18 use Rapsys\UserBundle\Utils\Slugger
; 
  20 class DefaultController 
extends AbstractController 
{ 
  34         protected $translator; 
  37          * Inject container and translator interface 
  39          * @param ContainerInterface $container The container instance 
  40          * @param RouterInterface $router The router instance 
  41          * @param Slugger $slugger The slugger instance 
  42          * @param TranslatorInterface $translator The translator instance 
  44         public function __construct(ContainerInterface 
$container, RouterInterface 
$router, Slugger 
$slugger, TranslatorInterface 
$translator) { 
  46                 $this->config 
= $container->getParameter($this->getAlias()); 
  49                 $this->router 
= $router; 
  52                 $this->slugger 
= $slugger; 
  55                 $this->translator 
= $translator; 
  59                         'copy_long' => $translator->trans($this->config
['copy']['long']), 
  60                         'copy_short' => $translator->trans($this->config
['copy']['short']), 
  61                         'site_ico' => $this->config
['site']['ico'], 
  62                         'site_logo' => $this->config
['site']['logo'], 
  63                         'site_png' => $this->config
['site']['png'], 
  64                         'site_svg' => $this->config
['site']['svg'], 
  65                         'site_title' => $translator->trans($this->config
['site']['title']), 
  66                         'site_url' => $router->generate($this->config
['site']['url']) 
  73          * @desc Send a contact mail to configured contact 
  75          * @param Request $request The request instance 
  76          * @param MailerInterface $mailer The mailer instance 
  78          * @return Response The rendered view or redirection 
  80         public function contact(Request 
$request, MailerInterface 
$mailer) { 
  82                 $section = $this->translator
->trans('Contact'); 
  85                 $title = $section.' - '.$this->translator
->trans($this->config
['site']['title']); 
  87                 //Create the form according to the FormType created previously. 
  88                 //And give the proper parameters 
  89                 $form = $this->createForm('Rapsys\AirBundle\Form\ContactType', null, [ 
  90                         // To set the action use $this->generateUrl('route_identifier') 
  91                         'action' => $this->generateUrl('rapsys_air_contact'), 
  95                 if ($request->isMethod('POST')) { 
  96                         // Refill the fields in case the form is not valid. 
  97                         $form->handleRequest($request); 
  99                         if ($form->isValid()) { 
 101                                 $data = $form->getData(); 
 104                                 $message = (new TemplatedEmail()) 
 106                                         ->from(new Address($data['mail'], $data['name'])) 
 108                                         //XXX: remove the debug set in vendor/symfony/mime/Address.php +46 
 109                                         ->to(new Address($this->config
['contact']['mail'], $this->config
['contact']['name'])) 
 111                                         ->subject($data['subject']) 
 113                                         //Set path to twig templates 
 114                                         ->htmlTemplate('@RapsysAir/mail/contact.html.twig') 
 115                                         ->textTemplate('@RapsysAir/mail/contact.text.twig') 
 120                                                         'subject' => $data['subject'], 
 121                                                         'message' => strip_tags($data['message']), 
 125                                 //Try sending message 
 126                                 //XXX: mail delivery may silently fail 
 129                                         $mailer->send($message); 
 131                                         //Redirect on the same route with sent=1 to cleanup form 
 132                                         return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+
$request->get('_route_params')); 
 133                                 //Catch obvious transport exception 
 134                                 } catch(TransportExceptionInterface 
$e) { 
 135                                         if ($message = $e->getMessage()) { 
 136                                                 //Add error message mail unreachable 
 137                                                 $form->get('mail')->addError(new FormError($this->translator
->trans('Unable to contact: %mail%: %message%', ['%mail%' => $this->config
['contact']['mail'], '%message%' => $this->translator
->trans($message)]))); 
 139                                                 //Add error message mail unreachable 
 140                                                 $form->get('mail')->addError(new FormError($this->translator
->trans('Unable to contact: %mail%', ['%mail%' => $this->config
['contact']['mail']]))); 
 147                 return $this->render('@RapsysAir/form/contact.html.twig', ['title' => $title, 'section' => $section, 'form' => $form->createView(), 'sent' => $request->query
->get('sent', 0)]+
$this->context
); 
 153          * @desc Welcome the user 
 155          * @return Response The rendered view 
 157         public function index() { 
 159                 $section = $this->translator
->trans('Index'); 
 162                 $title = $section.' - '.$this->context
['site_title']; 
 165                 return $this->render('@RapsysAir/default/index.html.twig', ['title' => $title, 'section' => $section]+
$this->context
); 
 169          * The regulation page 
 171          * @desc Display the regulation policy 
 173          * @return Response The rendered view 
 175         public function regulation() { 
 177                 $section = $this->translator
->trans('Regulation'); 
 180                 $title = $section.' - '.$this->context
['site_title']; 
 183                 return $this->render('@RapsysAir/default/regulation.html.twig', ['title' => $title, 'section' => $section]+
$this->context
); 
 187          * Return the bundle alias 
 191         public function getAlias() {