src/Controller/FrontEndBundle/DefaultController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller\FrontEndBundle;
  3. use App\Entity\Group;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use App\Entity\Groupconfigapp;
  12. use App\Services\ImageService;
  13. use Symfony\Component\Mailer\MailerInterface;
  14. use Symfony\Component\Mime\Email;
  15. use App\Services\KlentyService;
  16. class DefaultController extends AbstractController
  17. {
  18.     public function getCountryCode($ip)
  19.     {
  20.         //$fakeIp = "186.152.100.150";
  21.         $fakeIp "35.168.130.76";
  22.         //Your BIN database file path
  23.         $db = new \IP2Location\Database ('../src/Database/IP2LOCATION-LITE-DB1.BIN'\IP2Location\Database::FILE_IO);
  24.         $ipToSearch $ip == "::1" $fakeIp $ip ;
  25.         $records $db->lookup($ipToSearch\IP2Location\Database::ALL);
  26.                         
  27.         return $records["countryCode"];
  28.     }        
  29.     
  30.     /**
  31.      * @Route("/", name="homepage")
  32.      */
  33.     public function indexAction(Request $request)
  34.     {
  35.         $ip$request->getClientIp();
  36.         $countryCode $this->getCountryCode($ip);
  37.         
  38.         $renderPage 'FrontEndBundle/default/index.html.twig';
  39.         switch ($countryCode) {
  40.             case "AR":
  41.                 $renderPage 'FrontEndBundle/default/AR/index.html.twig';
  42.                 break;
  43.             case "MX":
  44.                 $renderPage 'FrontEndBundle/default/index.html.twig';
  45.                 break;
  46.             default:    
  47.                 $renderPage 'FrontEndBundle/default/index.html.twig';
  48.         }
  49.         $name 'Pedidos Free';
  50.         return $this->render(
  51.             $renderPage,
  52.             array(
  53.                 'name' => $name
  54.             )
  55.         );
  56.     }
  57.         /**
  58.      * @Route("sistema-de-pedidos-online-para-restaurante", name="sistema-de-pedidos-online-para-restaurante")
  59.      */
  60.     public function sistemaParaRestaurantesAction()
  61.     {
  62.         $name 'Pedidos Free';
  63.         return $this->render(
  64.             'FrontEndBundle/default/index-restaurant.html.twig',
  65.             array(
  66.                 'name' => $name
  67.             )
  68.         );
  69.     }
  70.     
  71.     /**
  72.      * @Route("/es-mx/", name="es-mx")
  73.      */
  74.     public function indexMxAction()
  75.     {
  76.         $name 'Pedidos Free';
  77.         return $this->render(
  78.             'FrontEndBundle/default/index.html.twig',
  79.             array(
  80.                 'name' => $name
  81.             )
  82.         );
  83.     }
  84.     /**
  85.      * @Route("/es-ar/", name="es-ar")
  86.      */
  87.     public function indexArAction()
  88.     {
  89.         $name 'Pedidos Free';
  90.         return $this->render(
  91.             'FrontEndBundle/default/index-ar.html.twig',
  92.             array(
  93.                 'name' => $name
  94.             )
  95.         );
  96.     }
  97.     /**
  98.      * @Route("/contacto", name="contacto")
  99.      */
  100.     public function contactAction()
  101.     {
  102.         $name 'Pedidos Free';
  103.         return $this->render(
  104.             'FrontEndBundle/default/contact.html.twig',
  105.             array(
  106.                 'name' => $name
  107.             )
  108.         );
  109.     }
  110.     /**
  111.      * @Route("/thanks", name="thanks")
  112.      */
  113.     public function thanksAction()
  114.     {
  115.         $name 'Pedidos Free';
  116.         return $this->render(
  117.             'FrontEndBundle/default/thanks.html.twig',
  118.             array(
  119.                 'name' => $name
  120.             )
  121.         );
  122.     }
  123.     /**
  124.      * @Route("/precios", name="precios")
  125.      */
  126.     public function preciosAction(Request $request)
  127.     {
  128.         $ip$request->getClientIp();
  129.         $countryCode $this->getCountryCode($ip);
  130.         
  131.         $renderPage 'FrontEndBundle/default/price.html.twig';
  132.         switch ($countryCode) {
  133.             case "AR":
  134.                 $renderPage 'FrontEndBundle/default/AR/price.html.twig';
  135.                 break;
  136.             case "MX":
  137.                 $renderPage 'FrontEndBundle/default/price.html.twig';
  138.                 break;
  139.             default:    
  140.                 $renderPage 'FrontEndBundle/default/price.html.twig';
  141.         }
  142.         $name 'Pedidos Free';
  143.         return $this->render(
  144.             $renderPage,
  145.             array(
  146.                 'name' => $name
  147.             )
  148.         );
  149.     }
  150.     /**
  151.      * @Route("/historias-de-exito", name="historias-de-exito")
  152.      */
  153.     public function historiasDeExitoAction()
  154.     {
  155.         $name 'Pedidos Free';
  156.         return $this->render(
  157.             'FrontEndBundle/default/history-success.html.twig',
  158.             array(
  159.                 'name' => $name
  160.             )
  161.         );
  162.     }
  163.     /**
  164.      * @Route("/preguntas-frecuentes", name="preguntas-frecuentes")
  165.      */
  166.     public function historiasDeExittAction()
  167.     {
  168.         $name 'Pedidos Free';
  169.         return $this->render(
  170.             'FrontEndBundle/default/faqs.html.twig',
  171.             array(
  172.                 'name' => $name
  173.             )
  174.         );
  175.     }
  176.     /**
  177.      * @Route("/{namegroup}", name="group" )
  178.      * @Template("FrontEndBundle/landing/landing.html.twig")
  179.      */
  180.     public function groupAction($namegroupEntityManagerInterface $em,
  181.     ImageService $imageService)
  182.     
  183.     {
  184.         $group $em->getRepository(Group::class)->getGroupByUrl($namegroup);
  185.         // Segunda forma
  186.         // $groupconfigapp = $em->getRepository(Groupconfigapp::class)->getGroupConfigAppByGroupNameAndType($namegroup, $typeconfig);
  187.         if ($group && $group->getGroupconfigappsLanding()) {
  188.             $groupconfigapp $group->getGroupconfigappsLanding()[0];
  189.             $imagesResult $imageService->getPathImagesGroup($group);
  190.             
  191.             $pathimageheader = ($imagesResult['pathimageheader']) ? $imagesResult['pathimageheader'] : $groupconfigapp->getImageMain();
  192.             $pathimagelogo = ($imagesResult['pathimagelogo']) ? $imagesResult['pathimagelogo'] : $groupconfigapp->getImageLogo() ;
  193.             $pathimagelogo = ($imagesResult['pathimagelogo']) ? $imagesResult['pathimagelogo'] : $groupconfigapp->getImageLogo() ;
  194.             $pathimagefavicon = ($imagesResult['pathimagefavicon']) ? $imagesResult['pathimagefavicon'] : $groupconfigapp->getImageLogo() ;
  195.             
  196.              return $this->render('FrontEndBundle/landing/landing.html.twig', array(
  197.                 'name' => "Pedidos Free",
  198.                 'namegroup' =>$namegroup,
  199.                 'typeapplication' => $group->getTypeapplication(),
  200.                 'headtitle' => $groupconfigapp->getHeadTitle(),
  201.                 'headmetadescription' => $groupconfigapp->getHeadMetaDescription(),
  202.                 'headmetakeywords' => $groupconfigapp->getHeadMetaKeywords(),
  203.                 'headerdescription' => $groupconfigapp->getHeaderDescription(),
  204.                 'middledescription1' => $groupconfigapp->getMiddleDescription1(),
  205.                 'middledescription2' => $groupconfigapp->getMiddleDescription2(),
  206.                 'fotterdescription' => $groupconfigapp->getFooterDescription(),
  207.                 'urlappweb' => $groupconfigapp->getUrlAppWeb(),
  208.                 'imagemain' => $pathimageheader ,
  209.                 'imagecellphone' => $groupconfigapp->getImageCellPhone(),
  210.                 'imagelogo' => $pathimagelogo,
  211.                 'pathimagefavicon' => $pathimagefavicon,
  212.                 'facebookfanpage' => $groupconfigapp->getFacebookFanPage(),
  213.                 'playstoreurl' => $group->getPlaystoreLink(),
  214.                 'applestoreurl' => $group->getApplestoreLink()
  215.             ));
  216.         } else {
  217.             throw $this->createNotFoundException('La página no existe.');
  218.         }
  219.     }
  220.     /**
  221.      * @Route("/front/send-email-contact", name="send-email-contact")
  222.      * @Method("POST")
  223.      *
  224.      */
  225.     public function sendEmailContact(Request $requestMailerInterface $mailer)
  226.     {
  227.         $respArray = array();
  228.         $respArray['result'] = true;
  229.         $respArray['messages'] = '';
  230.         $whatsappLink =  "https://api.whatsapp.com/send?phone=" str_replace("+"""htmlspecialchars($request->request->get('phone')));
  231.         $body "<b> Nombre : </b>" .  htmlspecialchars($request->request->get('name'));
  232.         $body .= "<br><b>Local: </b>" htmlspecialchars($request->request->get('company'));
  233.         $body .= "<br><b>Antiguedad: </b>" htmlspecialchars($request->request->get('seniority'));
  234.         $body .= "<br><b>Tipo de local: </b>" htmlspecialchars($request->request->get('industry'));
  235.         $body .= "<br><b>DELIVERY PROPIO: </b>" htmlspecialchars($request->request->get('deliveryown'));
  236.         $body .= "<br><b>Email: </b>" trim(htmlspecialchars($request->request->get('email')));
  237.         $body .= "<br><b>Telefono: </b>" htmlspecialchars($request->request->get('phone'));
  238.         $body .= "<br><b>Horario de contacto: </b>" htmlspecialchars($request->request->get('schedule_day'));
  239.         $body .= "<br><b>Pais: </b>" htmlspecialchars(strtoupper($request->request->get('country')));
  240.         $body .= "<br><b>Ciudad: </b>" htmlspecialchars($request->request->get('city'));
  241.         $body .= "<br><b>Mensaje: </b>" .  htmlspecialchars($request->request->get('notes'));
  242.         $body .= "<br><b>source: </b>" .  htmlspecialchars($request->request->get('source'));
  243.         $body .= "<br><b>utm_source: </b>" .  htmlspecialchars($request->request->get('utm_source'));
  244.         $body .= "<br><b>utm_medium: </b>" .  htmlspecialchars($request->request->get('utm_medium'));
  245.         $body .= "<br><b>utm_campaign: </b>" .  htmlspecialchars($request->request->get('utm_campaign'));
  246.         $body .= "<br><b>Existe en klenty: </b>" .  htmlspecialchars($request->request->get('exist'));
  247.         $email = (new Email())
  248.             ->from('ventas@pedidosfree.com.ar')
  249.             ->to("manfredihj@gmail.com")
  250.             //->cc('cc@example.com')
  251.             //->bcc('manfredihj@gmail.com')
  252.             //->replyTo('fabien@example.com')
  253.             //->priority(Email::PRIORITY_HIGH)
  254.             ->subject('Consulta Pedidos Free WEB')
  255.             ->text('Consulta Pedidos Free WEB')
  256.             ->html($body);
  257.         try {
  258.             $mailer->send($email);
  259.             $respArray['messages'] = 'Mail enviado correctamente.';
  260.         } catch (\Exception $e) {
  261.             $respArray['messages'] =  'Error al enviar el mail.';
  262.             $respArray['result'] = false;
  263.         }
  264.         $response = new Response(json_encode($respArray));
  265.         return $response;
  266.     }
  267.     /**
  268.      * @Route("/front/validate-prospect", name="validate-prospect")
  269.      * @Method("POST")
  270.      *
  271.      */
  272.     public function validateProspect(Request $requestKlentyService $klentyService)
  273.     {
  274.         $respArray = array();
  275.         $respArray['result'] = true;
  276.         $respArray['messages'] = '';
  277.         $existfalse;
  278.         $email trim(htmlspecialchars($request->request->get('email')));
  279.     
  280.         try {
  281.             $exist $klentyService->checkIfProspectExist($email);
  282.         } catch (\Exception $e) {
  283.             $respArray['messages'] =  'error al validar el prospecto.';
  284.             $respArray['result'] = false;
  285.         }
  286.         $respArray['exist'] = $exist;
  287.         $response = new Response(json_encode($respArray));
  288.         return $response;
  289.     }
  290. }