src/Controller/DefaultController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Utils\DefaultService;
  4. use ReCaptcha\ReCaptcha;
  5. use ReCaptcha\RequestMethod\CurlPost;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. class DefaultController extends AbstractController
  10. {
  11.     private $defaultService;
  12.     public function __construct(DefaultService $defaultService)
  13.     {
  14.         $this->defaultService $defaultService;
  15.     }
  16.     public function index()
  17.     {
  18.         //Metaetiquetas para la pagina principal
  19.         $url 'homefrontend';
  20.         //seo on page
  21.         $seo_on_page $this->defaultService->DevolverSeoOnPage($url);
  22.         // highlighted
  23.         $highlighted $this->defaultService->DevolverHighlighted();
  24.         // about
  25.         $about $this->defaultService->DevolverAbout();
  26.         // board
  27.         $board $this->defaultService->ListarBoard();
  28.         // banners
  29.         $banners $this->defaultService->ListarBanners();
  30.         // faqs
  31.         $faqs $this->defaultService->ListarFaqs();
  32.         return $this->render('frontend/default/index.html.twig', array(
  33.             'seo_on_page' => $seo_on_page,
  34.             'highlighted' => $highlighted,
  35.             'about' => $about,
  36.             'board' => $board,
  37.             'banners' => $banners,
  38.             'faqs' => $faqs
  39.         ));
  40.     }
  41.     public function error404()
  42.     {
  43.         //Metaetiquetas para la pagina principal
  44.         $url 'error404';
  45.         $seo_on_page $this->defaultService->DevolverSeoOnPage($url);
  46.         $response = new Response(""400);
  47.         return $this->render('frontend/error404.html.twig', array(
  48.             'seo_on_page' => $seo_on_page
  49.         ), $response
  50.         );
  51.     }
  52.     public function contacto(Request $request)
  53.     {
  54.         //Metaetiquetas para la pagina principal
  55.         $url 'contacto';
  56.         $seo_on_page $this->defaultService->DevolverSeoOnPage($url);
  57.         $datos_contacto $this->defaultService->ListarFooterDatos();
  58.         //Recaptcha
  59.         $recaptcha_publick_key $this->getParameter('recaptcha_publick_key');
  60.         if ($request->getMethod() == "POST") {
  61.             $nombre $request->get('nombre');
  62.             $email $request->get('email');
  63.             $mensaje $request->get('mensaje');
  64.             $recaptcha_response $request->get('g-recaptcha-response');
  65.             $secret $this->getParameter('recaptcha_private_key');
  66.             $recaptcha = new ReCaptcha($secret, new CurlPost());
  67.             $result_recaptcha $recaptcha->verify($recaptcha_response$_SERVER['REMOTE_ADDR']);
  68.             if ($result_recaptcha->isSuccess()) {
  69.                 $this->defaultService->ProcesarContacto($nombre$email$mensaje);
  70.                 return $this->redirectToRoute('contactoenviado');
  71.             } else {
  72.                 $error "";
  73.                 foreach ($result_recaptcha->getErrorCodes() as $code) {
  74.                     $error $code ', ';
  75.                 }
  76.                 return $this->render('frontend/default/contacto.html.twig', array(
  77.                         'seo_on_page' => $seo_on_page,
  78.                         'datos_contacto' => $datos_contacto,
  79.                         'recaptcha_publick_key' => $recaptcha_publick_key,
  80.                         'message' => $error
  81.                     )
  82.                 );
  83.             }
  84.         }
  85.         return $this->render('frontend/default/contacto.html.twig', array(
  86.                 'seo_on_page' => $seo_on_page,
  87.                 'datos_contacto' => $datos_contacto,
  88.                 'recaptcha_publick_key' => $recaptcha_publick_key
  89.             )
  90.         );
  91.     }
  92.     public function contactoenviado(Request $request)
  93.     {
  94.         //Metaetiquetas para la pagina principal
  95.         $url 'contactoenviado';
  96.         $seo_on_page $this->defaultService->DevolverSeoOnPage($url);
  97.         $datos_contacto $this->defaultService->ListarFooterDatos();
  98.         return $this->render('frontend/default/contactoenviado.html.twig', array(
  99.                 'seo_on_page' => $seo_on_page,
  100.                 'datos_contacto' => $datos_contacto,
  101.             )
  102.         );
  103.     }
  104.     /**
  105.      * para renderizar el footer
  106.      * @return Response
  107.      */
  108.     public function mostrarFooter()
  109.     {
  110.         //Categorias
  111.         $footer_datos $this->defaultService->ListarFooterDatos();
  112.         return $this->render('frontend/block/footer.html.twig', array(
  113.                 'footer_datos' => $footer_datos,
  114.             )
  115.         );
  116.     }
  117. }