src/Uniski/CMSBundle/Controller/PageController.php line 177

Open in your IDE?
  1. <?php
  2. namespace Uniski\CMSBundle\Controller;
  3. // IvoryGoogleMapBundle eliminado en migración Sf4 — mapa renderizado con JS directo
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Uniski\CMSBundle\Entity\Offer;
  8. use Uniski\CMSBundle\Entity\Page;
  9. use Uniski\CMSBundle\Form\WebForm\InfoFormType;
  10. use Uniski\CMSBundle\Form\WebForm\InfoSchoolGroupsFormType;
  11. use Uniski\ConfigBundle\Entity\Category;
  12. use Uniski\ConfigBundle\Factory\ConfigurationFactory;
  13. use Uniski\ResourceBundle\Controller\BaseController;
  14. use Uniski\ResourceBundle\Entity\Hotel;
  15. use Uniski\ResourceBundle\Entity\Product;
  16. class PageController extends BaseController
  17. {
  18.   #[Route('/'name'homepage')]
  19.   public function indexAction()
  20.   {
  21.     $offerManager $this->get('app.offer_manager');
  22.     $offers $offerManager->getOffers(['frontpage' => 'all']);
  23.     $topPosts $this->getRepository(\Uniski\CMSBundle\Entity\Post::class)->findByStick(true, ['created' => 'DESC']);
  24.     $posts $this->getRepository(\Uniski\CMSBundle\Entity\Post::class)->findByStick(false, ['created' => 'DESC'], 8);
  25.     $config $this->get('app.config_manager')
  26.                    ->get(ConfigurationFactory::HOMEPAGE)
  27.                    ->getSettings();
  28.     $sections = [
  29.       [
  30.         'offers'  => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SECTION_1),
  31.         'title'   => $config['section_1']['title']
  32.       ],
  33.       [
  34.         'offers'  => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SECTION_2),
  35.         'title'   => $config['section_2']['title']
  36.       ],
  37.       [
  38.         'offers'  => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SECTION_3),
  39.         'title'   => $config['section_3']['title']
  40.       ],
  41.     ];
  42.     $response $this->render("page/home.html.twig", [
  43.         'sliderOffers'    => $offerManager->filterByFrontpage($offersOffer::FRONTPAGE_SLIDER),
  44.         'sections'        => $sections,
  45.         'topPosts'        => $topPosts,
  46.         'posts'           => $posts,
  47.         'menu'            => 'homepage',
  48.         'search'          => $this->get('app.search_manager')->createSearch(),
  49.         'config'          => $config
  50.       ]);
  51.       $response->setSharedMaxAge(86400);
  52.       $response->headers->addCacheControlDirective('must-revalidate'true);
  53.       return $response;
  54.   }
  55.   #[Route('hoteles'name'hotels_page')]
  56.   public function hotelsAction(Request $request)
  57.   {
  58.     return $this->forward('Uniski\CommerceBundle\Controller\SearchController::searchAction', [
  59.         'target' => 'hotels',
  60.         'request' => $request
  61.       ]);
  62.   }
  63.   #[Route('destinos'name'destinations_page')]
  64.   public function destinationsAction(Request $request)
  65.   {
  66.     return $this->forward('Uniski\CommerceBundle\Controller\SearchController::searchAction', [
  67.         'target' => 'destinations',
  68.         'request' => $request
  69.       ]);
  70.   }
  71.   #[Route('hotel/{slug}'name'hotel_show')]
  72.   public function hotelShowAction(Hotel $hotelRequest $request)
  73.   {
  74.     $productPriceService $this->get('app.product_price_service');
  75.     $offerManager        $this->get('app.offer_manager');
  76.     $searchManager       $this->get('app.search_manager');
  77.     $search              $searchManager->createSearch();
  78.     $map                 null;
  79.     $products            = [];
  80.     $search['entity']['value'] = $hotel->getId();
  81.     $allProducts $this->getRepository(\Uniski\ResourceBundle\Entity\Product::class)->findByZone($hotel->getZone());
  82.     foreach ($allProducts as $product) {
  83.       $products[] = [
  84.         'product' => $product,
  85.         'minPrice'    => $offerManager->calculateMinPrice($product)
  86.       ];
  87.     }
  88.     if ($hotel->getAddress() &&
  89.         $hotel->getAddress()->hasCoordinates()) {
  90.       $map = [
  91.         'latitude' => $hotel->getAddress()->getLatitude(),
  92.         'longitude' => $hotel->getAddress()->getLongitude(),
  93.         'zoom' => 15,
  94.       ];
  95.     }
  96.     return $this->render('hotel/show.html.twig',[
  97.         'hotel'    => $hotel,
  98.         'map'      => $map,
  99.         'search'   => $search,
  100.         'products' => $products
  101.       ]);
  102.   }
  103.   #[Route('/ofertas/ski/{slug}')]
  104.   public function destinationsByZoneAction(Category $zoneRequest $request)
  105.   {
  106.     return $this->forward('Uniski\CommerceBundle\Controller\SearchController::searchAction', [
  107.         'target' => $zone,
  108.         'request' => $request
  109.       ]);
  110.   }
  111.   #[Route('/contacto'name'contact_page')]
  112.   public function contactAction(Request $request)
  113.   {
  114.     $form $this->get('app.webform_manager')->submitWebForm($request);
  115.     return $this->render('page/contact.html.twig', [
  116.         'form' => $form->createView(),
  117.         'menu' => 'contact'
  118.       ]);
  119.   }
  120.   #[Route('/aviso-legal'name'legal_notice_page')]
  121.   public function legalNoticeAction()
  122.   {
  123.     return $this->render('page/legal_notice.html.twig', []);
  124.   }
  125.   public function footerMenuAction($region)
  126.   {
  127.     $menus $this->getRepository(\Uniski\CMSBundle\Entity\Menu::class)->findAll();
  128.     $menu $menus[$region];
  129.     return $this->render("page/footer-menu.html.twig", [
  130.         'menu' => $menu
  131.       ]);
  132.   }
  133.   #[Route('/politica-cookies'name'cookies_policy_page')]
  134.   public function cookiesPolicyAction()
  135.   {
  136.     return $this->render('page/cookies_policy.html.twig', []);
  137.   }
  138.   public function backgroundAction()
  139.   {
  140.     $background null;
  141.     $imageRepo  $this->getRepository(\Uniski\ResourceBundle\Entity\Image::class);
  142.     $config     $this->get('app.config_manager')
  143.                        ->get(ConfigurationFactory::HOMEPAGE)
  144.                        ->getSettings();
  145.     if (!empty($config['background'])) {
  146.       $background $imageRepo->find($config['background']);
  147.     }
  148.     return $this->render('default/background.html.twig', [
  149.         'background' => $background
  150.       ]);
  151.   }
  152.   #[Route('/{prefix}/{slug}'name'show_page')]
  153.   #[Route('/{slug}')]
  154.   public function showPageAction(Page $pageRequest $request)
  155.   {
  156.     //Avoid duplicated pages
  157.     if ($request->get('_route') != 'show_page' && $page->getPrefix()) {
  158.       return $this->redirectToRoute("show_page", [
  159.         'prefix' => $page->getPrefix(),
  160.         'slug'   => $page->getSlug()
  161.       ], 301);
  162.     }
  163.     $webformService $this->get('app.webform_manager');
  164.     $form           null;
  165.     $template       null;
  166.     if ($page->getWebForm()) {
  167.       $form $webformService->submitWebForm($request$page->getWebForm(), [
  168.           'page' => $page
  169.         ]);
  170.       $template $this->getTemplateFromForm($page->getWebForm());
  171.     }
  172.     $offerManager $this->get('app.offer_manager');
  173.     $offers $offerManager->getOffers(['page' => $page]);
  174.     $response $this->render('page/show.html.twig', [
  175.       'page' => $page,
  176.       'offers' => $offers,
  177.       'menu' => $page->getSlug(),
  178.       'form' => $form $form->createView() : null,
  179.       'webformTemplate' => $template,
  180.       'search' => $this->get('app.search_manager')->createSearch(),
  181.     ]);
  182.     $response->setSharedMaxAge(86400);
  183.     $response->headers->addCacheControlDirective('must-revalidate'true);
  184.     return $response;
  185.   }
  186.   /**
  187.    *
  188.    *
  189.    *    DO NOT ADD MORE ROUTES AFTER THIS LINES!!!!!
  190.    *
  191.    *
  192.    */
  193.   private function getTemplateFromForm($webform)
  194.   {
  195.     switch ($webform) {
  196.       case InfoFormType::class:
  197.         return 'webform/info.html.twig';
  198.       case InfoSchoolGroupsFormType::class:
  199.         return 'webform/school_groups.html.twig';
  200.     }
  201.   }
  202. }