src/Controller/Front/PropertyController.php line 442

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Property;
  4. use App\Manager\InfoPropertyManager;
  5. use App\Manager\PropertyManager;
  6. use App\Manager\InfoFormManager;
  7. use App\Service\LocationIP\LocationIpInterface as LocationIP;
  8. use App\Service\Regionalization\Location;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use Symfony\Component\Asset\Package;
  18. use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
  19. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  20. use App\Interfaces\Csfr;
  21. use App\Manager\LandingScheduleManager;
  22. use App\Traits\FormTokenTrait;
  23. class PropertyController extends AbstractController implements Csfr
  24. {
  25.     use FormTokenTrait;
  26.     protected array $locals = [];
  27.     private RequestStack $requestStack;
  28.     public function __construct(RequestStack $requestStack)
  29.     {
  30.         $this->requestStack $requestStack;
  31.         $this->locals['menu_active'] = '';
  32.     }
  33.     public function getCsrfManager(): CsrfTokenManagerInterface
  34.     {
  35.         return $this->container->get('security.csrf.token_manager');
  36.     }
  37.     #[Route(path'/catalogo/'name'projects'methods: ['GET'])]
  38.     #[Template('front/property/properties.html.twig')]
  39.     public function propertiesAction(Request $requestInfoPropertyManager $ipmgrPropertyManager $pmgr): RedirectResponse|array
  40.     {
  41.         //if (!is_null($city = $this->getCitySession())) {
  42.         //    $parameters = array_merge(['city' => $city->getRegion()->getSlug()], $request->query->all());
  43.         //    return $this->redirectToRoute('projects_city', $parameters);
  44.         //}
  45.         $this->locals $this->properties($request$pmgr$ipmgr);
  46.         return $this->locals;
  47.     }
  48.     #[Route(path'/catalogo-{city}/'name'projects_city'methods: ['GET'])]
  49.     #[Template('front/property/properties.html.twig')]
  50.     public function propertiesCityAction(
  51.         //string $city, Request $request, InfoPropertyManager $ipmgr, PropertyManager $pmgr
  52.     ): RedirectResponse
  53.     {
  54.         //$this->locals = $this->properties($request, $pmgr, $ipmgr);
  55.         //$this->locals['region_city'] = $this->getCitySession();
  56.         //return $this->locals;
  57.         return $this->redirectToRoute('projects');
  58.     }
  59.     public function properties(Request $requestPropertyManager $pmgrInfoPropertyManager $ipmgr): array
  60.     {
  61.         $type_slug trim($request->query->get('sd_type'''));
  62.         $location_slug trim($request->query->get('sd_location'''));
  63.         $some trim($request->query->get('some''no'));
  64.         $types = [];
  65.         if ($some == 'yes') {
  66.             //solo cuando es de location piura y se requiere obtener todas las casas
  67.             $filter_types $pmgr->listTypesFilter();
  68.             foreach ($filter_types as $f) {
  69.                 if (str_contains($f['id'], 'casa')) {
  70.                     $types[] = $f['id'];
  71.                 }
  72.             }
  73.         }
  74.         $locals['home'] = $ipmgr->find(1);
  75.         $locals['list_items'] = $pmgr->search($type_slug$location_slug$types);
  76.         if ($location_slug) {
  77.             $locals['filter_types'] = $pmgr->listTypesFilter($location_slug);
  78.         }
  79.         return $locals;
  80.     }
  81.     #[Route(path'/asia/opciones/'name'asia_options'methods: ['GET'])]
  82.     #[Template('front/property/asia_options.html.twig')]
  83.     public function asiaOptionsAction(Request $requestInfoPropertyManager $ipmgr): array
  84.     {
  85.         $option $ipmgr->find(1);
  86.         $options = [
  87.             [
  88.                 'optionOnlyImage' => $option->getOptionAsiaCondOnlyImage(),
  89.                 'optionImage' => $option->getOptionAsiaCondImage(),
  90.                 'optionTitle' => $option->getOptionAsiaCondTitle(),
  91.                 'optionUrl' => $option->getOptionAsiaCondUrl(),
  92.                 'optionText' => $option->getOptionAsiaCondText(),
  93.                 'optionSequence' => $option->getOptionAsiaCondSequence(),
  94.                 'optionIsCasa' => true,
  95.                 'optionWithOpacity' => $option->getOptionAsiaCondWithOpacity()
  96.             ],
  97.             [
  98.                 'optionOnlyImage' => $option->getOptionAsiaLotesOnlyImage(),
  99.                 'optionImage' => $option->getOptionAsiaLotesImage(),
  100.                 'optionTitle' => $option->getOptionAsiaLotesTitle(),
  101.                 'optionUrl' => $option->getOptionAsiaLotesUrl(),
  102.                 'optionText' => $option->getOptionAsiaLotesText(),
  103.                 'optionSequence' => $option->getOptionAsiaLotesSequence(),
  104.                 'optionIsCasa' => false,
  105.                 'optionWithOpacity' => $option->getOptionAsiaLotesWithOpacity()
  106.             ]
  107.         ];
  108.         $options $this->orderOptions($options);
  109.         $page_title $option->getOptionAsiaPageTitle();
  110.         unset($option);
  111.         $this->locals['options'] = $options;
  112.         $this->locals['page_title'] = $page_title;
  113.         return $this->locals;
  114.     }
  115.     #[Route(path'/chilca/opciones/'name'chilca_options'methods: ['GET'])]
  116.     #[Template('front/property/chilca_options.html.twig')]
  117.     public function chilcaOptionsAction(Request $requestInfoPropertyManager $ipmgr): array
  118.     {
  119.         $option $ipmgr->find(1);
  120.         $options = [
  121.             [
  122.                 'optionOnlyImage' => $option->getOptionChilcaLotesOnlyImage(),
  123.                 'optionImage' => $option->getOptionChilcaLotesImage(),
  124.                 'optionTitle' => $option->getOptionChilcaLotesTitle(),
  125.                 'optionUrl' => $option->getOptionChilcaLotesUrl(),
  126.                 'optionText' => $option->getOptionChilcaLotesText(),
  127.                 'optionSequence' => $option->getOptionChilcaLotesSequence(),
  128.                 'optionIsCasa' => false,
  129.                 'optionWithOpacity' => $option->getOptionChilcaLotesWithOpacity()
  130.             ],
  131.             [
  132.                 'optionOnlyImage' => $option->getOptionChilcaCasasOnlyImage(),
  133.                 'optionImage' => $option->getOptionChilcaCasasImage(),
  134.                 'optionTitle' => $option->getOptionChilcaCasasTitle(),
  135.                 'optionUrl' => $option->getOptionChilcaCasasUrl(),
  136.                 'optionText' => $option->getOptionChilcaCasasText(),
  137.                 'optionSequence' => $option->getOptionChilcaCasasSequence(),
  138.                 'optionIsCasa' => true,
  139.                 'optionWithOpacity' => $option->getOptionChilcaCasasWithOpacity()
  140.             ]
  141.         ];
  142.         $options $this->orderOptions($options);
  143.         $page_title $option->getOptionChilcaPageTitle();
  144.         unset($option);
  145.         $this->locals['options'] = $options;
  146.         $this->locals['page_title'] = $page_title;
  147.         return $this->locals;
  148.     }
  149.     #[Route(path'/chiclayo/opciones/'name'chiclayo_options'methods: ['GET'])]
  150.     #[Template('front/property/chiclayo_options.html.twig')]
  151.     public function chiclayoOptionsAction(Request $requestInfoPropertyManager $ipmgr): array
  152.     {
  153.         $option $ipmgr->find(1);
  154.         $options = [
  155.             [
  156.                 'optionOnlyImage' => $option->getOptionChiclayoLotesOnlyImage(),
  157.                 'optionImage' => $option->getOptionChiclayoLotesImage(),
  158.                 'optionTitle' => $option->getOptionChiclayoLotesTitle(),
  159.                 'optionUrl' => $option->getOptionChiclayoLotesUrl(),
  160.                 'optionText' => $option->getOptionChiclayoLotesText(),
  161.                 'optionSequence' => $option->getOptionChiclayoLotesSequence(),
  162.                 'optionIsCasa' => false,
  163.                 'optionWithOpacity' => $option->getOptionChiclayoLotesWithOpacity()
  164.             ],
  165.             [
  166.                 'optionOnlyImage' => $option->getOptionChiclayoCasasOnlyImage(),
  167.                 'optionImage' => $option->getOptionChiclayoCasasImage(),
  168.                 'optionTitle' => $option->getOptionChiclayoCasasTitle(),
  169.                 'optionUrl' => $option->getOptionChiclayoCasasUrl(),
  170.                 'optionText' => $option->getOptionChiclayoCasasText(),
  171.                 'optionSequence' => $option->getOptionChiclayoCasasSequence(),
  172.                 'optionIsCasa' => true,
  173.                 'optionWithOpacity' => $option->getOptionChiclayoCasasWithOpacity()
  174.             ]
  175.         ];
  176.         $options $this->orderOptions($options);
  177.         $page_title $option->getOptionChiclayoPageTitle();
  178.         unset($option);
  179.         $this->locals['options'] = $options;
  180.         $this->locals['page_title'] = $page_title;
  181.         return $this->locals;
  182.     }
  183.     #[Route(path'/ica/opciones/'name'ica_options'methods: ['GET'])]
  184.     #[Template('front/property/ica_options.html.twig')]
  185.     public function icaOptionsAction(Request $requestInfoPropertyManager $ipmgr): array
  186.     {
  187.         $option $ipmgr->find(1);
  188.         $options = [
  189.             [
  190.                 'optionOnlyImage' => $option->getOptionIcaLotesOnlyImage(),
  191.                 'optionImage' => $option->getOptionIcaLotesImage(),
  192.                 'optionTitle' => $option->getOptionIcaLotesTitle(),
  193.                 'optionUrl' => $option->getOptionIcaLotesUrl(),
  194.                 'optionText' => $option->getOptionIcaLotesText(),
  195.                 'optionSequence' => $option->getOptionIcaLotesSequence(),
  196.                 'optionIsCasa' => false,
  197.                 'optionWithOpacity' => $option->getOptionIcaLotesWithOpacity()
  198.             ],
  199.             [
  200.                 'optionOnlyImage' => $option->getOptionIcaCasasOnlyImage(),
  201.                 'optionImage' => $option->getOptionIcaCasasImage(),
  202.                 'optionTitle' => $option->getOptionIcaCasasTitle(),
  203.                 'optionUrl' => $option->getOptionIcaCasasUrl(),
  204.                 'optionText' => $option->getOptionIcaCasasText(),
  205.                 'optionSequence' => $option->getOptionIcaCasasSequence(),
  206.                 'optionIsCasa' => true,
  207.                 'optionWithOpacity' => $option->getOptionIcaCasasWithOpacity()
  208.             ],
  209.             [
  210.                 'optionOnlyImage' => $option->getOptionIcaTechoOnlyImage(),
  211.                 'optionImage' => $option->getOptionIcaTechoImage(),
  212.                 'optionTitle' => $option->getOptionIcaTechoTitle(),
  213.                 'optionUrl' => $option->getOptionIcaTechoUrl(),
  214.                 'optionText' => $option->getOptionIcaTechoText(),
  215.                 'optionSequence' => $option->getOptionIcaTechoSequence(),
  216.                 'optionIsCasa' => true,
  217.                 'optionWithOpacity' => $option->getOptionIcaTechoWithOpacity()
  218.             ]
  219.         ];
  220.         $options $this->orderOptions($options);
  221.         $page_title $option->getOptionIcaPageTitle();
  222.         unset($option);
  223.         $this->locals['options'] = $options;
  224.         $this->locals['page_title'] = $page_title;
  225.         return $this->locals;
  226.     }
  227.     #[Route(path'/lambayeque/opciones/'name'lambayeque_options'methods: ['GET'])]
  228.     #[Template('front/property/lambayeque_options.html.twig')]
  229.     public function lambayequeOptionsAction(Request $requestInfoPropertyManager $ipmgr): array
  230.     {
  231.         $option $ipmgr->find(1);
  232.         $options = [
  233.             [
  234.                 'optionOnlyImage' => $option->getOptionLambayequeLotesOnlyImage(),
  235.                 'optionImage' => $option->getOptionLambayequeLotesImage(),
  236.                 'optionTitle' => $option->getOptionLambayequeLotesTitle(),
  237.                 'optionUrl' => $option->getOptionLambayequeLotesUrl(),
  238.                 'optionText' => $option->getOptionLambayequeLotesText(),
  239.                 'optionSequence' => $option->getOptionLambayequeLotesSequence(),
  240.                 'optionIsCasa' => false,
  241.                 'optionWithOpacity' => $option->getOptionLambayequeLotesWithOpacity()
  242.             ],
  243.             [
  244.                 'optionOnlyImage' => $option->getOptionLambayequeCasasOnlyImage(),
  245.                 'optionImage' => $option->getOptionLambayequeCasasImage(),
  246.                 'optionTitle' => $option->getOptionLambayequeCasasTitle(),
  247.                 'optionUrl' => $option->getOptionLambayequeCasasUrl(),
  248.                 'optionText' => $option->getOptionLambayequeCasasText(),
  249.                 'optionSequence' => $option->getOptionLambayequeCasasSequence(),
  250.                 'optionIsCasa' => true,
  251.                 'optionWithOpacity' => $option->getOptionLambayequeCasasWithOpacity()
  252.             ]
  253.         ];
  254.         $options $this->orderOptions($options);
  255.         $page_title $option->getOptionLambayequePageTitle();
  256.         unset($option);
  257.         $this->locals['options'] = $options;
  258.         $this->locals['page_title'] = $page_title;
  259.         return $this->locals;
  260.     }
  261.     #[Route(path'/piura/opciones/'name'piura_options'methods: ['GET'])]
  262.     #[Template('front/property/piura_options.html.twig')]
  263.     public function piuraOptionsAction(Request $requestInfoPropertyManager $ipmgrPropertyManager $pmgr): array
  264.     {
  265.         $option $ipmgr->find(1);
  266.         $options = [
  267.             [
  268.                 'optionOnlyImage' => $option->getOptionCasasOnlyImage(),
  269.                 'optionImage' => $option->getOptionCasasImage(),
  270.                 'optionTitle' => $option->getOptionCasasTitle(),
  271.                 'optionText' => $option->getOptionCasasText(),
  272.                 'optionUrl' => $option->getOptionCasasUrl(),
  273.                 'optionSequence' => $option->getOptionCasasSequence(),
  274.                 'optionIsCasa' => true,
  275.                 'optionWithOpacity' => $option->getOptionCasasWithOpacity()
  276.             ],
  277.             [
  278.                 'optionOnlyImage' => $option->getOptionLotesOnlyImage(),
  279.                 'optionImage' => $option->getOptionLotesImage(),
  280.                 'optionTitle' => $option->getOptionLotesTitle(),
  281.                 'optionText' => $option->getOptionLotesText(),
  282.                 'optionUrl' => $option->getOptionLotesUrl(),
  283.                 'optionSequence' => $option->getOptionLotesSequence(),
  284.                 'optionIsCasa' => false,
  285.                 'optionWithOpacity' => $option->getOptionLotesWithOpacity()
  286.             ],
  287.             [
  288.                 'optionOnlyImage' => $option->getOptionTechoOnlyImage(),
  289.                 'optionImage' => $option->getOptionTechoImage(),
  290.                 'optionTitle' => $option->getOptionTechoTitle(),
  291.                 'optionText' => $option->getOptionTechoText(),
  292.                 'optionUrl' => $option->getOptionTechoUrl(),
  293.                 'optionSequence' => $option->getOptionTechoSequence(),
  294.                 'optionIsCasa' => true,
  295.                 'optionWithOpacity' => $option->getOptionTechoWithOpacity()
  296.             ]
  297.         ];
  298.         $options $this->orderOptions($options);
  299.         $page_title $option->getOptionPageTitle();
  300.         unset($option);
  301.         $filter_types $pmgr->listTypesFilter();
  302.         $type_lote null;
  303.         foreach ($filter_types as $f) {
  304.             if (str_contains($f['id'], 'lote')) {
  305.                 $type_lote $f['id'];
  306.                 break;
  307.             }
  308.         }
  309.         $this->locals['options'] = $options;
  310.         $this->locals['piura_page_title'] = $page_title;
  311.         $this->locals['location_piura_slug'] = 'piura';
  312.         $this->locals['type_lotes_slug'] = $type_lote;
  313.         return $this->locals;
  314.     }
  315.     #[Route(path'/piura/lotes/'name'piura_lotes'methods: ['GET'])]
  316.     #[Template('front/property/piura_lotes.html.twig')]
  317.     public function piuraLotesAction(Request $requestInfoPropertyManager $ipmgr): array
  318.     {
  319.         $this->locals['home'] = $ipmgr->find(1);
  320.         return $this->locals;
  321.     }
  322.     #[Route(path'/piura/casas-techo-propio/'name'piura_techo'methods: ['GET'])]
  323.     #[Template('front/property/piura_techo.html.twig')]
  324.     public function piuraTechoAction(Request $requestInfoPropertyManager $ipmgr): array
  325.     {
  326.         $this->locals['home'] = $ipmgr->find(1);
  327.         return $this->locals;
  328.     }
  329.     #[Route(path'/ica/lotes/'name'ica_lotes'methods: ['GET'])]
  330.     #[Template('front/property/ica_lotes.html.twig')]
  331.     public function icaLotesAction(Request $requestInfoPropertyManager $ipmgr): array
  332.     {
  333.         $this->locals['home'] = $ipmgr->find(1);
  334.         return $this->locals;
  335.     }
  336.      #[Route(path'/chiclayo/lotes/'name'chiclayo_lotes'methods: ['GET'])]
  337.     #[Template('front/property/chiclayo_lotes.html.twig')]
  338.     public function chiclayoLotesAction(Request $requestInfoPropertyManager $ipmgr): array
  339.     {
  340.         $this->locals['home'] = $ipmgr->find(1);
  341.         return $this->locals;
  342.     }
  343.     #[Route(path'/images-to-mailing/{code}/'name'images-to-mailing'methods: ['GET'])]
  344.     public function imagesToMailing(string $codeRequest $requestPropertyManager $pmgr): JsonResponse
  345.     {
  346.         $proyecto $pmgr->findOneBy(['sap_project' => $code]);
  347.         $img_header '';
  348.         $img_promocion '';
  349.         $data = [
  350.             'img_header' => $img_header,
  351.             'img_promocion' => $img_promocion,
  352.         ];
  353.         if (is_null($proyecto)) {
  354.             return new JsonResponse($data);
  355.         }
  356.         if ($proyecto->getBannerEmbedVideoShow()) {
  357.             $img_header $proyecto->getBannerEmbedImageDesktop();
  358.         }
  359.         if ($img_header == '') {
  360.             $slides $proyecto->getBanners();
  361.             foreach ($slides as $index => $slide) {
  362.                 if ($slide['show'] and $slide['img_desktop']) {
  363.                     $img_header $slide['img_desktop'];
  364.                     break;
  365.                 }
  366.             }
  367.         }
  368.         $img_header is_null($img_header) ? '' $img_header;
  369.         $img_promocion is_null($proyecto->getThankImage()) ? '' $proyecto->getThankImage();
  370.         $base_url $this->getParameter('file_base_url');
  371.         $base_path $this->getParameter('file_base_path');
  372.         $package = new Package(new EmptyVersionStrategy());
  373.         if ($img_header !== '') {
  374.             $img_header $base_url DIRECTORY_SEPARATOR $base_path $package->getUrl($img_header);
  375.         }
  376.         if ($img_promocion !== '') {
  377.             $img_promocion $base_url DIRECTORY_SEPARATOR $base_path $package->getUrl($img_promocion);
  378.         }
  379.         return new JsonResponse([
  380.             'img_header' => $img_header,
  381.             'img_promocion' => $img_promocion,
  382.         ]);
  383.     }
  384.     #[Route(path'/{slug}/'name'property'methods: ['GET'])]
  385.     public function propertyAction(
  386.         $slug,
  387.         PropertyManager $pmgr,
  388.         InfoFormManager $ifmgr,
  389.         InfoPropertyManager $ipmgr
  390.     ): Response {
  391.         $this->locals['IS_PROPERTY_DETAIL'] = true;
  392.         $this->locals['detail'] = $pmgr->loadBySlug($slug);
  393.         if (!$this->locals['detail']) {
  394.             throw $this->createNotFoundException('No encontrado');
  395.         }
  396.         // $replace = $this->getReplaceLanding($this->locals['detail']);
  397.         // if ($replace) {
  398.         //     return $this->redirectToRoute('property', ['slug' => $replace->getSlug()], 302);
  399.         // }
  400.         $this->locals['relateds'] = $pmgr->listActiveRelateds($this->locals['detail']->getId());
  401.         $template 'front/property/property_' $this->locals['detail']->getTemplate() . '.html.twig';
  402.         $this->locals['_token'] = $this->generateToken($this->quote_intention);
  403.         $this->locals['info_form'] = $ifmgr->find(1);
  404.         $this->locals['home'] = $ipmgr->find(1);
  405.         $tmp $this->locals['detail']->getTemplate();
  406.         $this->locals['property_header_menu'] = array_filter(
  407.             $this->locals['home']->getMenuItems(),
  408.             fn($e) => $e['template'] == $tmp
  409.         );
  410.         if (count((array) $this->locals['property_header_menu']) > 0) {
  411.             $this->locals['property_header_menu'] = end($this->locals['property_header_menu']);
  412.         }
  413.         return $this->render($template$this->locals);
  414.     }
  415.     private function getReplaceLanding($sourceLandingScheduleManager $lsmgr): ?Property
  416.     {
  417.         $schedules $lsmgr->getReplaces($source->getId());
  418.         if (!$schedules) {
  419.             return null;
  420.         }
  421.         $current date('w');
  422.         $replace null;
  423.         foreach ($schedules as $sc) {
  424.             if (in_array($current$sc->getScheduleDays())) {
  425.                 $replace $sc->getPtarget();
  426.                 break;
  427.             }
  428.         }
  429.         return $replace;
  430.     }
  431.     private function orderOptions(array $opts): array
  432.     {
  433.         usort($opts, fn($a$b) => $a['optionSequence'] <=> $b['optionSequence']);
  434.         return $opts;
  435.     }
  436.     protected function getCitySession(): ?Location
  437.     {
  438.         $session $this->requestStack->getSession();
  439.         return $session->get(LocationIP::REGION);
  440.     }
  441. }