src/Controller/Front/ModelsController.php line 212

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Controller\Core\BaseFrontController;
  4. use App\Entity\FormTruck;
  5. use App\Entity\Model;
  6. use App\Entity\Models;
  7. use App\Form\Front\FormTruckType;
  8. use App\Manager\BusFilterModelManager;
  9. use App\Manager\BusFilterPBVManager;
  10. use App\Manager\BusFilterPowerManager;
  11. use App\Manager\BusFilterTonnageManager;
  12. use App\Manager\BusManager;
  13. use App\Manager\FormTruckManager;
  14. use App\Manager\ModelManager;
  15. use App\Manager\ModelsManager;
  16. use App\Manager\TruckFilterModelManager;
  17. use App\Manager\TruckFilterPowerManager;
  18. use App\Manager\TruckFilterTonnageManager;
  19. use App\Manager\TruckFilterTractionManager;
  20. use App\Manager\TruckFilterTypeManager;
  21. use App\Manager\TruckManager;
  22. use App\Service\Mail\ModelMail;
  23. use Knp\Component\Pager\PaginatorInterface;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  25. use Symfony\Component\HttpFoundation\RedirectResponse;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  28. use Symfony\Component\Routing\Annotation\Route;
  29. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  30. class ModelsController extends BaseFrontController
  31. {
  32.     protected array $locals = [];
  33.     const FORM_TRUCK 'sd_form_truck_entity';
  34.     const FORM_BUS 'sd_form_bus_entity';
  35.     /**
  36.      * @Route("/volkswagen", name="model_list")
  37.      * @Template("front/models/list.html.twig")
  38.      */
  39.     public function home(
  40.         Request $request,
  41.         TruckFilterModelManager $truckFilterModelManager,
  42.         TruckFilterTractionManager $truckFilterTractionManager,
  43.         TruckFilterTypeManager $truckFilterTypeManager,
  44.         TruckFilterPowerManager $truckFilterPowerManager,
  45.         TruckFilterTonnageManager $truckFilterTonnageManager,
  46.         BusFilterModelManager $busFilterModelManager,
  47.         BusFilterPBVManager $busFilterPBVManager,
  48.         BusFilterPowerManager $busFilterPowerManager,
  49.         TruckManager $truckManager,
  50.         BusManager $busManager,
  51.         ModelManager $modelManager,
  52.         ModelsManager $modelsManager,
  53.         PaginatorInterface $paginator
  54.     ): array
  55.     {
  56.         $params $request->query->all();
  57.         $page $request->query->getInt('page'1);
  58.         $trucks $truckManager->filter($params);
  59.         $buses $busManager->filter($params);
  60.         $models $modelManager->byTrucksAndBuses($trucks$buses);
  61.         $models $paginator->paginate($models$page12);
  62.         /** @var Models $info */
  63.         $info $modelsManager->find(1);
  64.         $this->locals['truck_filter_model'] = $truckFilterModelManager->valid();
  65.         $this->locals['truck_filter_traction'] = $truckFilterTractionManager->valid();
  66.         $this->locals['truck_filter_type'] = $truckFilterTypeManager->valid();
  67.         $this->locals['truck_filter_power'] = $truckFilterPowerManager->valid();
  68.         $this->locals['truck_filter_tonnage'] = $truckFilterTonnageManager->valid();
  69.         $this->locals['bus_filter_model'] = $busFilterModelManager->valid();
  70.         $this->locals['bus_filter_pbv'] = $busFilterPBVManager->valid();
  71.         $this->locals['bus_filter_power'] = $busFilterPowerManager->valid();
  72.         $this->locals['models'] = $models;
  73.         $this->locals['type'] = 'both';
  74.         $this->locals['base_url'] = $this->generateUrl('model_list');
  75.         $this->locals['sd'] = $info;
  76.         $this->locals['sd_title'] = $info->getBothTitle();
  77.         $this->locals['sd_description'] = $info->getBothDescription();
  78.         return $this->locals;
  79.     }
  80.     /**
  81.      * @Route("/volkswagen-camiones", name="model_trucks")
  82.      * @Template("front/models/list.html.twig")
  83.      */
  84.     public function trucks(
  85.         Request $request,
  86.         TruckFilterModelManager $truckFilterModelManager,
  87.         TruckFilterTractionManager $truckFilterTractionManager,
  88.         TruckFilterTypeManager $truckFilterTypeManager,
  89.         TruckFilterPowerManager $truckFilterPowerManager,
  90.         TruckFilterTonnageManager $truckFilterTonnageManager,
  91.         TruckManager $truckManager,
  92.         ModelsManager $modelsManager,
  93.         PaginatorInterface $paginator
  94.     ): array
  95.     {
  96.         $params $request->query->all();
  97.         $page $request->query->getInt('page'1);
  98.         $trucks $truckManager->filter($params);
  99.         $trucks $paginator->paginate($trucks$page12);
  100.         /** @var Models $info */
  101.         $info $modelsManager->find(1);
  102.         $this->locals['truck_filter_model'] = $truckFilterModelManager->valid();
  103.         $this->locals['truck_filter_traction'] = $truckFilterTractionManager->valid();
  104.         $this->locals['truck_filter_type'] = $truckFilterTypeManager->valid();
  105.         $this->locals['truck_filter_power'] = $truckFilterPowerManager->valid();
  106.         $this->locals['truck_filter_tonnage'] = $truckFilterTonnageManager->valid();
  107.         $this->locals['models'] = $trucks;
  108.         $this->locals['type'] = Model::TYPE_TRUCK;
  109.         $this->locals['base_url'] = $this->generateUrl('model_trucks');
  110.         $this->locals['sd'] = $info;
  111.         $this->locals['sd_title'] = $info->getTrucksTitle();
  112.         $this->locals['sd_description'] = $info->getTrucksDescription();
  113.         return $this->locals;
  114.     }
  115.     /**
  116.      * @Route("/volkswagen-buses", name="model_buses")
  117.      * @Template("front/models/list.html.twig")
  118.      */
  119.     public function buses(
  120.         Request $request,
  121.         BusFilterModelManager $busFilterModelManager,
  122.         BusFilterPBVManager $busFilterPBVManager,
  123.         BusFilterPowerManager $busFilterPowerManager,
  124.         BusFilterTonnageManager $busFilterTonnageManager,
  125.         BusManager $busManager,
  126.         ModelsManager $modelsManager,
  127.         PaginatorInterface $paginator
  128.     ): array
  129.     {
  130.         $params $request->query->all();
  131.         $page $request->query->getInt('page'1);
  132.         $buses $busManager->filter($params);
  133.         $buses $paginator->paginate($buses$page12);
  134.         /** @var Models $info */
  135.         $info $modelsManager->find(1);
  136.         $this->locals['bus_filter_model'] = $busFilterModelManager->valid();
  137.         $this->locals['bus_filter_pbv'] = $busFilterPBVManager->valid();
  138.         $this->locals['bus_filter_power'] = $busFilterPowerManager->valid();
  139.         $this->locals['bus_filter_tonnage'] = $busFilterTonnageManager->valid();
  140.         $this->locals['models'] = $buses;
  141.         $this->locals['type'] = Model::TYPE_BUS;
  142.         $this->locals['base_url'] = $this->generateUrl('model_buses');
  143.         $this->locals['sd'] = $info;
  144.         $this->locals['sd_title'] = $info->getBusesTitle();
  145.         $this->locals['sd_description'] = $info->getBusesDescription();
  146.         return $this->locals;
  147.     }
  148.     /**
  149.      * @Route("/camion/{slug}", name="model_detail", methods={"GET"})
  150.      * @Template("front/models/detail_truck.html.twig")
  151.      */
  152.     public function detailTruck(string $slugRequest $requestTruckManager $truckManagerModelsManager $modelsManager): array
  153.     {
  154.         $truck $truckManager->bySlug($slug);
  155.         if (is_null($truck)) {
  156.             throw new NotFoundHttpException('Camión no encontrado');
  157.         }
  158.         $entity $this->getFormSession(self::FORM_TRUCK, new FormTruck());
  159.         $form $this->getFormView(FormTruckType::class, $entity'model_detail_action', ['slug' => $slug]);
  160.         $referer $request->headers->get('referer');
  161.         $sd $modelsManager->find(1);
  162.         $this->locals['back_url'] = ($referer and $referer != $this->generateUrl('model_detail', ['slug' => $slug], UrlGeneratorInterface::ABSOLUTE_URL)) ? $referer $this->generateUrl('model_list');
  163.         $this->locals['truck'] = $truck;
  164.         $this->locals['form'] = $form;
  165.         $this->locals['sd'] = $sd;
  166.         return $this->locals;
  167.     }
  168.     /**
  169.      * @Route("/camion/{slug}", name="model_detail_action", methods={"POST"})
  170.      */
  171.     public function detailTruckAction(string $slugRequest $requestFormTruckManager $manager): RedirectResponse
  172.     {
  173.         $entity = new FormTruck();
  174.         $form $this->getForm(FormTruckType::class, $entity'model_detail_action', ['slug' => $slug]);
  175.         $form->handleRequest($request);
  176.         if ($form->isValid()) {
  177.             $manager->save($entity);
  178.             return $this->redirectToRoute('thanks_slug', ['slug' => 'cotizar-camion']);
  179.         }
  180.         $this->saveFormSession(self::FORM_TRUCK$entity);
  181.         return $this->redirectToRoute('model_detail', ['slug' => $slug]);
  182.     }
  183.     /**
  184.      * @Route("/bus/{slug}", name="modelbus_detail", methods={"GET"})
  185.      * @Template("front/models/detail_bus.html.twig")
  186.      */
  187.     public function detailBus(string $slugRequest $requestBusManager $busManagerModelsManager $modelsManager): array
  188.     {
  189.         $truck $busManager->bySlug($slug);
  190.         if (is_null($truck)) {
  191.             throw new NotFoundHttpException('Camión no encontrado');
  192.         }
  193.         $entity $this->getFormSession(self::FORM_BUS, new FormTruck());
  194.         $form $this->getFormView(FormTruckType::class, $entity'modelbus_detail_action', ['slug' => $slug]);
  195.         $referer $request->headers->get('referer');
  196.         $sd $modelsManager->find(1);
  197.         $this->locals['back_url'] = ($referer and $referer != $this->generateUrl('modelbus_detail', ['slug' => $slug], UrlGeneratorInterface::ABSOLUTE_URL)) ? $referer $this->generateUrl('model_list');
  198.         $this->locals['truck'] = $truck;
  199.         $this->locals['form'] = $form;
  200.         $this->locals['sd'] = $sd;
  201.         return $this->locals;
  202.     }
  203.     /**
  204.      * @Route("/bus/{slug}", name="modelbus_detail_action", methods={"POST"})
  205.      */
  206.     public function detailBusAction(string $slugRequest $requestFormTruckManager $managerModelMail $mail): RedirectResponse
  207.     {
  208.         $entity = new FormTruck();
  209.         $form $this->getForm(FormTruckType::class, $entity'modelbus_detail_action', ['slug' => $slug]);
  210.         $form->handleRequest($request);
  211.         if ($form->isValid()) {
  212.             $manager->save($entity);
  213.             $mail->load($entity, ['is_bus' => true])->send();
  214.             return $this->redirectToRoute('thanks_slug', ['slug' => 'cotizar-camion']);
  215.         }
  216.         $this->saveFormSession(self::FORM_BUS$entity);
  217.         return $this->redirectToRoute('model_detail', ['slug' => $slug]);
  218.     }
  219. }