src/Controller/Front/MachineController.php line 211

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Manager\InfoManager;
  4. use App\Service\CRM\ApiClient;
  5. use App\Traits\RecaptchaTrait;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use App\Service\Mail\{PromoMailPartsMailMachineMailServiceMail};
  14. use App\Manager\{PromoManagerMachineManagerServiceManagerCategoryManager};
  15. use App\Form\Front\{FormPromoTypeFormPartsTypeFormMachineTypeFormServiceType};
  16. use App\Manager\{FormPromoManagerFormPartsManagerFormMachineManagerFormServiceManager};
  17. use App\Manager\{InfoPromoManagerInfoPartsManagerInfoMachineManagerInfoServiceManager};
  18. class MachineController extends AbstractController
  19. {
  20.     use RecaptchaTrait;
  21.     
  22.     protected array $locals = [];
  23.     public function __construct(RequestStack $requestStackInfoManager $infoManager)
  24.     {
  25.         $this->requestStack $requestStack;
  26.         $this->infoManager $infoManager;
  27.         $this->locals['menu_active'] = '';
  28.     }
  29.     /**
  30.      * @Route("/camiones/{slug}/", name="trucks_cat")
  31.      */
  32.     public function trucksCat(Request $requestMachineManager $mmCategoryManager $cmInfoMachineManager $immPaginatorInterface $paginator$slug)
  33.     {
  34.         $this->locals['machines'] = $mm->listByCategory($slug);
  35.         $this->locals['machines'] = $paginator->paginate(
  36.             $this->locals['machines'],
  37.             $request->query->getInt('page'1),
  38.             12,
  39.         );
  40.         if ($request->query->get('ajax'false) == true) {
  41.             $response = new Response($this->renderView('front/ajax/trucks.html.twig'$this->locals), 200);
  42.             $response->headers->set('X-Robots-Tag''noindex, nofollow');
  43.             return $response;
  44.         }
  45.         $this->locals['menu_active'] = 'trucks';
  46.         $this->locals['category'] = $cm->bySlug($slug);
  47.         $this->locals['home'] = $imm->find(1);
  48.         $this->locals['slug'] = $slug;
  49.         $response = new Response($this->renderView('front/machine/trucks.html.twig'$this->locals), 200);
  50.         return $response;
  51.     }
  52.     /**
  53.      * @Route("/camiones/", name="trucks")
  54.      */
  55.     public function trucks(Request $requestMachineManager $mmCategoryManager $cmInfoMachineManager $immPaginatorInterface $paginator)
  56.     {
  57.         $this->locals['machines'] = $mm->listByCategory(null);
  58.         $this->locals['machines'] = $paginator->paginate(
  59.             $this->locals['machines'],
  60.             $request->query->getInt('page'1),
  61.             12,
  62.         );
  63.         if ($request->query->get('ajax'false) == true) {
  64.             $response = new Response($this->renderView('front/ajax/trucks.html.twig'$this->locals), 200);
  65.             $response->headers->set('X-Robots-Tag''noindex, nofollow');
  66.             return $response;
  67.         }
  68.         $this->locals['menu_active'] = 'trucks';
  69.         $this->locals['category'] = null//$cm->bySlug($slug);
  70.         $this->locals['home'] = $imm->find(1);
  71.         $this->locals['slug'] = ''//$slug;
  72.         $response = new Response($this->renderView('front/machine/trucks.html.twig'$this->locals), 200);
  73.         return $response;
  74.     }
  75.     /**
  76.      * @Route("/camion/{slug}/", name="truck")
  77.      * @Template("front/machine/detail.html.twig")
  78.      */
  79.     public function truck(Request $requestString $slugMachineManager $mmFormMachineManager $fmmInfoMachineManager $immMachineMail $mailApiClient $apiclient)
  80.     {
  81.         $entity $fmm->create();
  82.         $detail $mm->bySlug($slug);
  83.         $form $this->createForm(FormMachineType::class, $entity, [
  84.             'action' => $this->generateUrl('truck', ['slug' => $detail->getSlug()]),
  85.             'method' => 'POST',
  86.         ]);
  87.         if ($request->isMethod('POST')) {
  88.             $entity->setTypeMachine($detail->getCategory()->getTitleCrm());
  89.             $entity->setTypeModel($detail->getCodeCrm());
  90.             $form->handleRequest($request);
  91.             if ($form->isValid() && $this->validateGoogleCaptcha()) {
  92.                 
  93.                 $fmm->save($entity);
  94.                 //$mail->load($entity)->send();
  95.                 //send to CRM
  96.                 $result $apiclient->sendLead($entity);
  97.                 return $this->redirectToRoute('thanks_machine');
  98.             } else {
  99.                 //dump($form->getErrors(true, true)); exit;
  100.             }
  101.         }
  102.         $this->locals['form'] = $form->createView();
  103.         $this->locals['home'] = $imm->find(1);
  104.         $this->locals['detail'] = $detail;
  105.         $this->locals['menu_active'] = 'trucks';
  106.         return $this->locals;
  107.     }
  108.     /**
  109.      * @Route("/promociones/", name="promos", methods={"POST", "GET"})
  110.      * @Template("front/machine/promos.html.twig")
  111.      */
  112.     public function promos(Request $requestPromoManager $pmInfoPromoManager $ipmFormPromoManager $fpmPromoMail $mail)
  113.     {
  114.         $entity $fpm->create();
  115.         $form $this->createForm(FormPromoType::class, $entity, [
  116.             'action' => $this->generateUrl('promos'),
  117.             'method' => 'POST',
  118.         ]);
  119.         if ($request->isMethod('POST')) {
  120.             $form->handleRequest($request);
  121.             if ($form->isValid() && $this->validateGoogleCaptcha()) {
  122.                 $fpm->save($entity);
  123.                 $mail->load($entity)->send();
  124.                 return $this->redirectToRoute('thanks_promo');
  125.             } else {
  126.                 //dump($form->getErrors(true, true)); exit;
  127.             }
  128.         }
  129.         $this->locals['form'] = $form->createView();
  130.         $this->locals['home'] = $ipm->find(1);
  131.         $this->locals['promos'] = $pm->listActive();
  132.         $this->locals['menu_active'] = 'promos';
  133.         return $this->locals;
  134.     }
  135.     /**
  136.      * @Route("/repuestos/", name="parts", methods={"POST", "GET"})
  137.      * @Template("front/machine/parts.html.twig")
  138.      */
  139.     public function parts(Request $requestInfoPartsManager $ipmFormPartsManager $fpmPartsMail $mail)
  140.     {
  141.         $entity $fpm->create();
  142.         $form $this->createForm(FormPartsType::class, $entity, [
  143.             'action' => $this->generateUrl('parts'),
  144.             'method' => 'POST',
  145.         ]);
  146.         if ($request->isMethod('POST')) {
  147.             $form->handleRequest($request);
  148.             if ($form->isValid() && $this->validateGoogleCaptcha()) {
  149.                 $fpm->save($entity);
  150.                 $mail->load($entity)->send();
  151.                 return $this->redirectToRoute('thanks_parts');
  152.             } else {
  153.                 //dump($form->getErrors(true, true)); exit;
  154.             }
  155.         }
  156.         $this->locals['form'] = $form->createView();
  157.         $this->locals['home'] = $ipm->find(1);
  158.         $this->locals['menu_active'] = 'parts';
  159.         return $this->locals;
  160.     }
  161.     /**
  162.      * @Route("/servicios/", name="services")
  163.      * @Template("front/machine/services.html.twig")
  164.      */
  165.     public function services(ServiceManager $smInfoServiceManager $ism): array
  166.     {
  167.         $this->locals['home'] = $ism->find(1);
  168.         $this->locals['services'] = $sm->listActive();
  169.         $this->locals['menu_active'] = 'services';
  170.         return $this->locals;
  171.     }
  172.     /**
  173.      * @Route("/servicio/{slug}/", name="service", methods={"POST", "GET"})
  174.      * @Template("front/machine/service.html.twig")
  175.      */
  176.     public function service(Request $requestString $slugServiceManager $smFormServiceManager $fsmServiceMail $mail)
  177.     {
  178.         $entity $fsm->create();
  179.         $form $this->createForm(FormServiceType::class, $entity, [
  180.             'action' => $this->generateUrl('service', ['slug' => $slug]),
  181.             'method' => 'POST',
  182.         ]);
  183.         if ($request->isMethod('POST')) {
  184.             $form->handleRequest($request);
  185.             if ($form->isValid() && $this->validateGoogleCaptcha()) {
  186.                 $fsm->save($entity);
  187.                 $mail->load($entity)->send();
  188.                 return $this->redirectToRoute('thanks_service');
  189.             } else {
  190.                 //dump($form->getErrors(true, true)); exit;
  191.             }
  192.         }
  193.         $this->locals['form'] = $form->createView();
  194.         $this->locals['detail'] = $sm->bySlug($slug);
  195.         $this->locals['menu_active'] = 'services';
  196.         return $this->locals;
  197.     }
  198. }