src/Controller/IndexController.php line 145

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Business;
  4. use App\Entity\Discount;
  5. use App\Entity\Movie;
  6. use App\Entity\News;
  7. use App\Entity\Node;
  8. use App\Entity\Page;
  9. use App\Entity\Tag;
  10. use App\Form\Filter\CategoryFilterType;
  11. use App\Helper\NodeFactory;
  12. use DateTime;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\RequestStack;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. class IndexController extends CoreController
  21. {
  22.     private ?Business $center null;
  23.     private array $pages = [];
  24.     private EntityManagerInterface $entityManager;
  25.     protected TranslatorInterface $translator;
  26.     protected RequestStack $requestStack;
  27.     protected Request $request;
  28.     /**
  29.      * @param RequestStack $requestStack
  30.      * @param EntityManagerInterface $entityManager
  31.      * @param TranslatorInterface $translator
  32.      */
  33.     public function __construct(
  34.         RequestStack           $requestStack,
  35.         EntityManagerInterface $entityManager,
  36.         TranslatorInterface    $translator
  37.     )
  38.     {
  39.         parent::__construct($translator);
  40.         $this->entityManager $entityManager;
  41.         $this->request $requestStack->getCurrentRequest();
  42.         if ($this->request instanceof Request) {
  43.             $cityUrl $this->request->get('city');
  44.             $this->center $this->entityManager->getRepository(Business::class)->findOneBy(['url' => $cityUrl]);
  45.             if ($this->center !== null) {
  46.                 $this->pages $this->entityManager->getRepository(Page::class)->findBy([
  47.                     'parent' => $this->center
  48.                 ], ['title' => 'ASC']);
  49.             }
  50.         }
  51.     }
  52.     #[Route('/'name'app_index')]
  53.     public function index(): Response
  54.     {
  55.         return $this->render('index/index.html.twig');
  56.     }
  57.     #[Route('/{city}'name'app_index_city')]
  58.     public function dashboard($city): Response
  59.     {
  60.         $items $this->entityManager->getRepository(News::class)->findActiveByCenter($this->center);
  61.         return $this->render('index/homepage.html.twig', [
  62.             'center' => $this->center,
  63.             'city' => $city,
  64.             'carousel' => $items
  65.         ]);
  66.     }
  67.     #[Route('/{city}/kino'name'app_city_cinema')]
  68.     #[Route('/{city}/kino/{date}'name'app_city_cinema_date')]
  69.     public function cinema($city, ?string $date): Response
  70.     {
  71.         $today = new \DateTime('now');
  72.         $selected $today;
  73.         if ($date !== null) {
  74.             $selected DateTime::createFromFormat('Y-m-d'$date);
  75.         }
  76.         $movies $this->entityManager->getRepository(Movie::class)->findByCenterAndDate($this->center$selected);
  77.         $cinema $this->entityManager->getRepository(Business::class)->findOneBy([
  78.             'parent' => $this->center,
  79.             'isCinema' => true
  80.         ]);
  81.         return $this->render('index/cinema.html.twig', [
  82.             'city' => $city,
  83.             'today' => $today,
  84.             'selected' => $selected,
  85.             'center' => $this->center,
  86.             'cinema' => $cinema,
  87.             'movies' => $movies
  88.         ]);
  89.     }
  90.     #[Route('/{city}/prevadzky'name'app_city_businesses')]
  91.     #[Route('/{city}/prevadzka/{url}'name'app_city_business')]
  92.     public function business($city, ?string $url): Response
  93.     {
  94.         $discounts null;
  95.         $filter $this->createForm(CategoryFilterType::class, null, ['center' => $this->center]);
  96.         $selected $this->entityManager->getRepository(Business::class)->findOneBy(
  97.             [
  98.                 'parent' => $this->center,
  99.                 'url' => $url
  100.             ]
  101.         );
  102.         $filter->handleRequest($this->request);
  103.         if ($filter->isSubmitted() && $filter->get('category')->getData() !== null) {
  104.             $category $filter->get('category')->getData();
  105.             $list $this->entityManager->getRepository(Business::class)->searchByCategoryAndCenter($category$this->center);
  106.         } else {
  107.             if ($selected instanceof Business) {
  108.                 $discounts $this->entityManager->getRepository(Discount::class)->findActiveByBusiness($selected);
  109.                 $list $this->entityManager->getRepository(Business::class)->findBy([
  110.                     'parent' => $this->center,
  111.                     'floor' => $selected->getFloor(),
  112.                     'published' => true
  113.                 ], ['title' => 'asc']);
  114.             } else {
  115.                 $list $this->entityManager->getRepository(Business::class)->findBy([
  116.                     'parent' => $this->center,
  117.                     'published' => true
  118.                 ], ['title' => 'asc']);
  119.             }
  120.         }
  121.         return $this->render('index/business.html.twig', [
  122.             'city' => $city,
  123.             'center' => $this->center,
  124.             'selected' => $selected,
  125.             'discounts' => $discounts,
  126.             'list' => $list,
  127.             'form' => $filter->createView()
  128.         ]);
  129.     }
  130.     #[Route('/{city}/mapa'name'app_city_business_map')]
  131.     #[Route('/{city}/mapa/{floor}'name'app_city_business_map_floor')]
  132.     public function map($city, ?string $floor): Response
  133.     {
  134.         $nr NodeFactory::parseFloorToInt($floor);
  135.         $category null;
  136.         $filter $this->createForm(CategoryFilterType::class, null, ['center' => $this->center]);
  137.         $filter->handleRequest($this->request);
  138.         if ($filter->isSubmitted() && $filter->get('category')->getData() !== null) {
  139.             $category $filter->get('category')->getData();
  140.             $list $this->entityManager->getRepository(Business::class)->searchByCategoryAndCenter($category$this->center$nr);
  141.         } else {
  142.             $list $this->entityManager->getRepository(Business::class)->findBy([
  143.                 'parent' => $this->center,
  144.                 'floor' => $nr
  145.             ], ['title' => 'asc']);
  146.         }
  147.         return $this->render('index/map.html.twig', [
  148.             'city' => $city,
  149.             'center' => $this->center,
  150.             'list' => $list,
  151.             'floor' => $nr,
  152.             'category' => $category,
  153.             'form' => $filter->createView()
  154.         ]);
  155.     }
  156.     #[Route('/{city}/podujatia'name'app_city_news')]
  157.     #[Route('/{city}/podujatie/{url}'name'app_city_news_detail')]
  158.     public function news($city, ?string $url): Response
  159.     {
  160.         $selected $this->entityManager->getRepository(News::class)->findOneBy(['url' => $url]);
  161.         $list $this->entityManager->getRepository(News::class)->findActiveByCenter($this->center);
  162.         return $this->render('index/news.html.twig', [
  163.             'city' => $city,
  164.             'center' => $this->center,
  165.             'selected' => $selected,
  166.             'list' => $list
  167.         ]);
  168.     }
  169.     #[Route('/{city}/akcie-a-zlavy'name'app_city_discounts')]
  170.     #[Route('/{city}/akcie-a-zlavy/{businessUrl}/{url}'name'app_city_discount')]
  171.     public function discounts($city, ?string $businessUrl, ?string $url): Response
  172.     {
  173.         $list $this->entityManager->getRepository(Discount::class)->findActiveByCenter($this->center);
  174.         $business $this->entityManager->getRepository(Business::class)->findOneBy([
  175.             'parent' => $this->center,
  176.             'url' => $businessUrl
  177.         ]);
  178.         $selected $this->entityManager->getRepository(Discount::class)->findOneBy([
  179.             'parent' => $business,
  180.             'url' => $url
  181.         ]);
  182.         return $this->render('index/discounts.html.twig', [
  183.             'city' => $city,
  184.             'center' => $this->center,
  185.             'list' => $list,
  186.             'selected' => $selected
  187.         ]);
  188.     }
  189.     #[Route('/{city}/o-nas'name'app_city_about')]
  190.     public function about($city): Response
  191.     {
  192.         $nodes $this->entityManager->getRepository(Page::class)->findBy(['parent' => $this->center]);
  193.         return $this->render('index/about-us.html.twig', [
  194.             'city' => $city,
  195.             'center' => $this->center,
  196.             'list' => $nodes
  197.         ]);
  198.     }
  199.     #[Route('/{city}/o-nas/{url}'name'app_city_about_page')]
  200.     public function aboutPage($city, ?string $url): Response
  201.     {
  202.         $page $this->entityManager->getRepository(Page::class)->findOneBy(['parent' => $this->center'url' => $url]);
  203.         return $this->render('index/page.html.twig', [
  204.             'city' => $city,
  205.             'center' => $this->center,
  206.             'page' => $page
  207.         ]);
  208.     }
  209. }