src/Controller/Site/ContentController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Site;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class ContentController extends Controller
  7. {
  8.     /**
  9.      * @Route("/", name="raiz")
  10.      */
  11.     public function indexRaiz(Request $request)
  12.     {
  13.         return $this->redirectToRoute('homepage', ['_locale' => 'es']);
  14.     }
  15.     
  16.     /**
  17.      * @Route("/{_locale}/", name="homepage", methods={"GET","POST"}, requirements={"_locale" = "es|en"})
  18.      */
  19.     public function index(Request $request)
  20.     {
  21.         $em $this->getDoctrine()->getManager();
  22.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('inicio');
  23.         return $this->render('site/content/index.html.twig', [
  24.             'page' => $page,
  25.         ]);
  26.     }
  27.     /**
  28.      * @Route("/{_locale}/oferta", name="landing", requirements={"_locale" = "es|en"})
  29.      */
  30.     public function landing(Request $request)
  31.     {
  32.         $em $this->getDoctrine()->getManager();
  33.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('landing');
  34.         return $this->render('site/content/landing.html.twig', [
  35.             'page' => $page,
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/{_locale}/oferta-thanks", name="landing_thanks", requirements={"_locale" = "es|en"})
  40.      */
  41.     public function landingThanks(Request $request)
  42.     {
  43.         $em $this->getDoctrine()->getManager();
  44.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('landing');
  45.         return $this->render('site/content/landing-thanks.html.twig', [
  46.             'page' => $page,
  47.         ]);
  48.     }
  49.     /**
  50.      *    Example:
  51.      *    $this->editDocument([
  52.      *       '[name]' => 'Adam Frame',
  53.      *       '[address]' => '14 Eton Dorney Walk, Riverside Close, Andover SP11 6YL',
  54.      *    ]);.
  55.      *
  56.      * TODO: Add Filename as parameter
  57.      *
  58.      * @param bool $replacements
  59.      */
  60.     public function editDocument($replacements false)
  61.     {
  62.         $template_file_name __DIR__.'/../../../template.docx';
  63.         if (!is_file($template_file_name)) {
  64.             exit('No file');
  65.         }
  66.         $rand_no rand(111111999999);
  67.         $fileName 'results_'.$rand_no.'.docx';
  68.         $folder __DIR__.'/../../../pdf/results_';
  69.         $full_path $folder.'/'.$fileName;
  70.         try {
  71.             if (!file_exists($folder)) {
  72.                 mkdir($folder);
  73.             }
  74.             //Copy the Template file to the Result Directory
  75.             copy($template_file_name$full_path);
  76.             // add calss Zip Archive
  77.             $zip_val = new \ZipArchive();
  78.             //Docx file is nothing but a zip file. Open this Zip File
  79.             if (true == $zip_val->open($full_path)) {
  80.                 // In the Open XML Wordprocessing format content is stored.
  81.                 // In the document.xml file located in the word directory.
  82.                 $key_file_name 'word/document.xml';
  83.                 $message $zip_val->getFromName($key_file_name);
  84.                 $timestamp date('d-M-Y H:i:s');
  85.                 // this data Replace the placeholders with actual values
  86.                 $message str_replace('[dni]''Replaced dni'$message);
  87.                 if (is_array($replacements)) {
  88.                     foreach ($replacements as $string => $replacement) {
  89.                         $message str_replace($string$replacement$message);
  90.                     }
  91.                 }
  92.                 //Replace the content with the new content created above.
  93.                 $zip_val->addFromString($key_file_name$message);
  94.                 $zip_val->close();
  95.             }
  96.         } catch (Exception $exc) {
  97.             $error_message 'Error creating the Word Document';
  98.         }
  99.     }
  100.     /**
  101.      * @Route("/{_locale}/personalizada", name="personalized_landing", methods={"GET"}, requirements={"_locale" = "es|en"})
  102.      */
  103.     public function personalizedLanding(Request $request)
  104.     {
  105.         $em $this->getDoctrine()->getManager();
  106.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('personalizada');
  107.         return $this->render('site/content/personalized_landing.html.twig', [
  108.             'page' => $page,
  109.         ]);
  110.     }
  111.     /**
  112.      * @Route("/{_locale}/autonomos", name="self_employed_landing", methods={"GET"}, requirements={"_locale" = "es|en"})
  113.      */
  114.     public function selfEmployedLanding(Request $request)
  115.     {
  116.         $em $this->getDoctrine()->getManager();
  117.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('autonomos');
  118.         return $this->render('site/content/self_employed_landing.html.twig', [
  119.             'page' => $page,
  120.         ]);
  121.     }
  122.     /**
  123.      * @Route("/{_locale}/pymes", name="small_company_landing", methods={"GET"}, requirements={"_locale" = "es|en"})
  124.      */
  125.     public function smallCompanyLanding(Request $request)
  126.     {
  127.         $em $this->getDoctrine()->getManager();
  128.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('pymes');
  129.         return $this->render('site/content/small_company_landing.html.twig', [
  130.             'page' => $page,
  131.         ]);
  132.     }
  133.     /**
  134.      * @Route("/{_locale}/nominas", name="salaries_landing", methods={"GET"}, requirements={"_locale" = "es|en"})
  135.      */
  136.     public function salariesLanding(Request $request)
  137.     {
  138.         $em $this->getDoctrine()->getManager();
  139.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('nominas');
  140.         return $this->render('site/content/salaries_landing.html.twig', [
  141.             'page' => $page,
  142.             'imageCabecera' => 'fondo-hojas.png',
  143.         ]);
  144.     }
  145.     /**
  146.      * @Route("/{_locale}/irpf", name="tax_landing", methods={"GET"}, requirements={"_locale" = "es|en"})
  147.      */
  148.     public function taxLanding(Request $request)
  149.     {
  150.         $em $this->getDoctrine()->getManager();
  151.         $page $em->getRepository('App\Entity\Page')->findOneBySlug('irpf');
  152.         return $this->render('site/content/tax_landing.html.twig', [
  153.             'page' => $page,
  154.             'imageCabecera' => 'fondo-hojas.png',
  155.         ]);
  156.     }
  157. }