src/Controller/Frontend/FrontendController.php line 166

Open in your IDE?
  1. <?php
  2. // src/Controller/Frontend/FrontendController.php
  3. namespace App\Controller\Frontend;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use App\Entity\Blog;
  6. use App\Entity\Country;
  7. use App\Entity\Picture;
  8. use App\Repository\CategoryRepository;
  9. use App\Entity\Project;
  10. use App\Entity\ProjectImage;
  11. use App\Entity\ProjectAmenities;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  16. use Symfony\Component\Security\Core\Security;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use App\Service\MailHelper;
  19. use Symfony\Component\Asset\Packages;
  20. use Symfony\Component\HttpFoundation\RequestStack;
  21. class FrontendController extends AbstractController
  22. {
  23.     
  24.  
  25.     /**
  26.      * @Route("/", name="homepage_website", methods={"GET", "POST"})
  27.      */
  28.     public function homepage(Request $requestEntityManagerInterface $entityManager,  SessionInterface $session): Response
  29.     {
  30.         if ($request->isMethod('POST')) {
  31.           $cid $request->request->get('cid');
  32.           $session->set('cid'$cid);
  33.         }else{
  34.           $cid $session->get('cid'1);
  35.         }
  36.         $countries $entityManager->getRepository(Country::class)->findBy(["is_active" => 1]);               
  37.         $country $entityManager->getRepository(Country::class)->findOneBy(["countryId" => $cid]);               
  38.         if ($session->has('send_email')) {
  39.             $send_email $session->get('send_email');
  40.             $session->remove('send_email');
  41.         } else {
  42.             $send_email "";  
  43.         }
  44.         $pictures $entityManager->getRepository(Picture::class)->findBy(["is_active" => 1]);    
  45.         
  46.            return $this->render('website/index.html.twig', [
  47.            "cid" => $cid,
  48.            "country" => $country,
  49.            "countries" => $countries,
  50.            "send_email" => $send_email,
  51.            "pictures" => $pictures
  52.         ]);
  53.         
  54.     }
  55.     
  56.     /**
  57.      * @Route("/partners_website", name="homepage_partner", methods={"GET", "POST"})
  58.      */
  59.     public function partnersPage(Request $requestEntityManagerInterface $entityManagerSessionInterface $session): Response
  60.     {
  61.         if ($request->isMethod('POST')) {
  62.           $cid $request->request->get('cid');
  63.           $session->set('cid'$cid);
  64.         }else{
  65.           $cid $session->get('cid'1);
  66.         }
  67.         $countries $entityManager->getRepository(Country::class)->findBy(["is_active" => 1]);               
  68.         $country $entityManager->getRepository(Country::class)->findOneBy(["countryId" => $cid]);    
  69.         
  70.               
  71.         if ($session->has('send_email')) {
  72.             $send_email $session->get('send_email');
  73.             $session->remove('send_email');
  74.         } else {
  75.             $send_email "";  
  76.         }
  77.         $pictures $entityManager->getRepository(Picture::class)->findBy(["is_active" => 1]);    
  78.         
  79.         return $this->render('website/partners.html.twig', [
  80.             "cid" => $cid,
  81.             "country" => $country,
  82.             "countries" => $countries,
  83.             "send_email" => $send_email,
  84.             "pictures" => $pictures
  85.             
  86.         ]);
  87.         
  88.     }
  89.     
  90.     /**
  91.      * @Route("/service_website", name="homepage_service", methods={"GET", "POST"})
  92.      */
  93.     public function servicepage(Request $requestEntityManagerInterface $entityManagerSessionInterface $session): Response
  94.     {
  95.         
  96.         if ($request->isMethod('POST')) {
  97.           $cid $request->request->get('cid');
  98.           $session->set('cid'$cid);
  99.         }else{
  100.           $cid $session->get('cid'1);
  101.         }
  102.         $countries $entityManager->getRepository(Country::class)->findBy(["is_active" => 1]);               
  103.         $country $entityManager->getRepository(Country::class)->findOneBy(["countryId" => $cid]);
  104.         
  105.         if ($session->has('send_email')) {
  106.             $send_email $session->get('send_email');
  107.             $session->remove('send_email');
  108.         } else {
  109.             $send_email "";  
  110.         }
  111.         
  112.         return $this->render('website/service.html.twig', [
  113.           "page" => 1,
  114.           "cid" => $cid,
  115.           "country" => $country,
  116.           "countries" => $countries,
  117.           "send_email" => $send_email
  118.         ]);
  119.         
  120.     }
  121.     
  122.     /**
  123.      * @Route("/us_website", name="homepage_us", methods={"GET", "POST"})
  124.      */
  125.     public function uspage(Request $requestEntityManagerInterface $entityManagerSessionInterface $session): Response
  126.     {
  127.               
  128.         if ($request->isMethod('POST')) {
  129.           $cid $request->request->get('cid');
  130.           $session->set('cid'$cid);
  131.         }else{
  132.           $cid $session->get('cid'1);
  133.         }
  134.         $countries $entityManager->getRepository(Country::class)->findBy(["is_active" => 1]);               
  135.         $country $entityManager->getRepository(Country::class)->findOneBy(["countryId" => $cid]);
  136.          
  137.         if ($session->has('send_email')) {
  138.             $send_email $session->get('send_email');
  139.             $session->remove('send_email');
  140.         } else {
  141.             $send_email "";  
  142.         }
  143.         
  144.         return $this->render('website/us.html.twig', [
  145.             "cid" => $cid,
  146.             "country" => $country,
  147.             "countries" => $countries,
  148.             "send_email" => $send_email
  149.         ]);
  150.         
  151.     }
  152.     
  153.     
  154.     
  155.     /**
  156.      * @Route("/blog_website", name="homepage_blog", methods={"GET", "POST"})
  157.      */
  158.     public function blogpage(Request $request EntityManagerInterface $entityManagerSessionInterface $session): Response
  159.     {
  160.         if ($request->isMethod('POST')) {
  161.           $cid $request->request->get('cid');
  162.           $session->set('cid'$cid);
  163.         }else{
  164.           $cid $session->get('cid'1);
  165.         }
  166.         $countries $entityManager->getRepository(Country::class)->findBy(["is_active" => 1]);               
  167.         $country $entityManager->getRepository(Country::class)->findOneBy(["countryId" => $cid]);
  168.         
  169.         //$blogs = $entityManager->getRepository(Blog::class)->findBy(["is_active" => 1, "is_public" => 1]);               
  170.         $page $request->query->getInt('page'1); // Valor por defecto 1
  171.         $limit 8// Número de registros por página
  172.         $offset = ($page 1) * $limit// Cálculo del offset
  173.         
  174.         // Obtener el repositorio de la entidad Blog
  175.         $blogRepository $entityManager->getRepository(Blog::class);
  176.         
  177.         // Crear la consulta para obtener los registros
  178.         $query $blogRepository->createQueryBuilder('b')
  179.             ->where('b.is_active = 1')  // Condición para is_active
  180.             ->andWhere('b.is_public = 1'// Condición para is_public
  181.             ->orderBy('b.created_at''DESC'// Suponiendo que tienes un campo createdAt para ordenar
  182.             ->setFirstResult($offset// Establece el offset
  183.             ->setMaxResults($limit// Establece el límite de registros
  184.             ->getQuery();
  185.         
  186.         // Ejecutar la consulta
  187.         $blogs $query->getResult();
  188.         
  189.         if ($session->has('send_email')) {
  190.             $send_email $session->get('send_email');
  191.             $session->remove('send_email');
  192.         } else {
  193.             $send_email "";  
  194.         }
  195.          
  196.         return $this->render('website/blog.html.twig', [
  197.           "list"=> $blogs,
  198.           "cid" => $cid,
  199.           "country" => $country,
  200.           "countries" => $countries,
  201.           "send_email" => $send_email
  202.         ]);
  203.         
  204.     }
  205.     
  206.     
  207.     /**
  208.      * @Route("/blog_more_website", name="homepage_blog_more", methods={"GET", "POST"})
  209.      */
  210.     public function blogMorepage(Request $request EntityManagerInterface $entityManager): Response
  211.     {
  212.         $page 1000;
  213.         if($request->query->has("page")){
  214.            $page $request->get("page");
  215.         }
  216.         
  217.         $limit 8// Número de registros por página
  218.         $offset = ($page 1) * $limit// Cálculo del offset
  219.         
  220.         // Obtener el repositorio de la entidad Blog
  221.         $blogRepository $entityManager->getRepository(Blog::class);
  222.         
  223.         // Crear la consulta para obtener los registros
  224.         $query $blogRepository->createQueryBuilder('b')
  225.             ->where('b.is_active = 1')  // Condición para is_active
  226.             ->andWhere('b.is_public = 1'// Condición para is_public
  227.             ->orderBy('b.created_at''DESC'// Suponiendo que tienes un campo createdAt para ordenar
  228.             ->setFirstResult($offset// Establece el offset
  229.             ->setMaxResults($limit// Establece el límite de registros
  230.             ->getQuery();
  231.         
  232.         // Ejecutar la consulta
  233.         $blogs $query->getResult();
  234.     
  235.         return $this->render('website/blog_more.html.twig', [
  236.            "list" => $blogs
  237.         ]);
  238.     }
  239.     
  240.     
  241.     
  242.     /**
  243.      * @Route("/blog_search_website", name="homepage_blog_search", methods={"GET", "POST"})
  244.      */
  245.     public function searchMorepage(Request $request EntityManagerInterface $entityManager): Response
  246.     {
  247.         $search "";
  248.         if($request->query->has("search")){
  249.            $search $request->get("search");
  250.         }
  251.         
  252.         
  253.         // Obtener el repositorio de la entidad Blog
  254.         $blogRepository $entityManager->getRepository(Blog::class);
  255.         
  256.         // Crear la consulta para obtener los registros
  257.         $query $blogRepository->createQueryBuilder('b')
  258.             ->where('b.is_active = 1')  // Condición para is_active
  259.             ->andWhere('b.is_public = 1'
  260.             ->andWhere('b.description LIKE :value'
  261.             ->setParameter('value''%'.$search.'%')
  262.             ->orderBy('b.created_at''DESC'// Suponiendo que tienes un campo createdAt para ordenar
  263.             ->getQuery();
  264.         
  265.         // Ejecutar la consulta
  266.         $blogs $query->getResult();
  267.     
  268.         return $this->render('website/blog_more.html.twig', [
  269.            "list" => $blogs,
  270.            "search" => $search
  271.         ]);
  272.     }
  273.     
  274.     
  275.     
  276.     /**
  277.      * @Route("/blog_view_website", name="homepage_blog_view", methods={"GET", "POST"})
  278.      */
  279.     public function blogViewpage(Request $request EntityManagerInterface $entityManager): Response
  280.     {
  281.         
  282.         if($request->query->has("blog")){
  283.            $selected_blog_id $request->get("blog");
  284.          }else{
  285.            return $this->redirectToRoute('homepage_blog', [], Response::HTTP_SEE_OTHER);
  286.         
  287.          }
  288.          $blog $entityManager->getRepository(Blog::class)->findOneBy(["blogId" => $selected_blog_id]);    
  289.          $recomended $entityManager->getRepository(Blog::class)->getRecomended($selected_blog_id);    
  290.          $currentUrl urlencode($request->getUri());
  291.          return $this->render('website/blog_view.html.twig', [
  292.            "blog" => $blog,
  293.            "recomended" => $recomended,
  294.            "currentUrl" => $currentUrl
  295.         ]);
  296.         
  297.         
  298.     }
  299.     
  300.     /**
  301.      * @Route("/contact_website", name="homepage_contact", methods={"GET", "POST"})
  302.      */
  303.     public function contactpage(Request $request EntityManagerInterface $entityManagerSessionInterface $session): Response
  304.     {
  305.       
  306.         if ($request->isMethod('POST')) {
  307.           $cid $request->request->get('cid');
  308.           $session->set('cid'$cid);
  309.         }else{
  310.           $cid $session->get('cid'1);
  311.         }
  312.         $countries $entityManager->getRepository(Country::class)->findBy(["is_active" => 1]);               
  313.         $country $entityManager->getRepository(Country::class)->findOneBy(["countryId" => $cid]);
  314.         
  315.         if ($session->has('send_email')) {
  316.             $send_email $session->get('send_email');
  317.             $session->remove('send_email');
  318.         } else {
  319.             $send_email "";  
  320.         }
  321.         
  322.         return $this->render('website/contact.html.twig', [
  323.           "cid" => $cid,
  324.           "country" => $country,
  325.           "countries" => $countries,
  326.           "send_email" => $send_email
  327.         ]);
  328.         
  329.     }
  330.     
  331.     /**
  332.      * @Route("/contact_send_website", name="homepage_contact_send", methods={"GET", "POST"})
  333.      */
  334.     public function contactSend(Packages $assets,  RequestStack $requestStackRequest $request ,EntityManagerInterface $entityManagerMailHelper $mailHelperSessionInterface $session): Response
  335.     {
  336.       
  337.         $relativeUrl $assets->getUrl('assets/images/logo.png');        
  338.         $request $requestStack->getCurrentRequest();
  339.         $absoluteUrl $request->getSchemeAndHttpHost() . $relativeUrl;
  340.         
  341.       
  342.         $to "marco.cancino@digifact.com";
  343.         
  344.         $return "homepage_website";
  345.         if($request->request->has('from')){
  346.           $return $request->get('from');
  347.         }
  348.         
  349.         
  350.         if($request->request->has('from2')){
  351.           $return $request->get('from2');
  352.         }
  353.         $name $request->get('name');
  354.         $country $request->get('country');
  355.         $email $request->get('email');
  356.         $phone $request->get('phone');
  357.         $business "";
  358.         if($request->request->has('business')){
  359.           $business $request->get('business');
  360.         }
  361.         $nit "";
  362.         if($request->request->has('nit')){
  363.             $nit $request->get('nit');
  364.         }
  365.         
  366.         if( $request->request->has('nit') ){
  367.             $title "Contacto pagina web Digifact";
  368.         }else{
  369.             $title "Contacto socio pagina web Digifact";
  370.         }
  371.         
  372.         
  373.                             
  374.         
  375.         $content "Nuevo contacto desde la pagina web de Digifact. <br><br><b>Nombre:</b> $name<br><b>País:</b> $country  <br><b>Teléfono:</b> $phone<br><b>Email:</b> $email";
  376.         if($request->request->has('business')){
  377.           $content $content."<br><b>Empresa:</b> $business;
  378.         }
  379.         if($request->request->has('nit')){
  380.           $content $content."<br><b>Identificador tributario:</b> $nit;
  381.         }
  382.         $mailHelper->sendEmail($to$title$content$absoluteUrl) ;  
  383.         
  384.         
  385.         $session->set('send_email''1');
  386.         return $this->redirectToRoute($return, [], Response::HTTP_SEE_OTHER);
  387.          
  388.         
  389.     }
  390.     
  391.     
  392.   }