<?php
namespace App\Controller;
use App\Entity\Business;
use App\Entity\Discount;
use App\Entity\Movie;
use App\Entity\News;
use App\Entity\Node;
use App\Entity\Page;
use App\Entity\Tag;
use App\Form\Filter\CategoryFilterType;
use App\Helper\NodeFactory;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class IndexController extends CoreController
{
private ?Business $center = null;
private array $pages = [];
private EntityManagerInterface $entityManager;
protected TranslatorInterface $translator;
protected RequestStack $requestStack;
protected Request $request;
/**
* @param RequestStack $requestStack
* @param EntityManagerInterface $entityManager
* @param TranslatorInterface $translator
*/
public function __construct(
RequestStack $requestStack,
EntityManagerInterface $entityManager,
TranslatorInterface $translator
)
{
parent::__construct($translator);
$this->entityManager = $entityManager;
$this->request = $requestStack->getCurrentRequest();
if ($this->request instanceof Request) {
$cityUrl = $this->request->get('city');
$this->center = $this->entityManager->getRepository(Business::class)->findOneBy(['url' => $cityUrl]);
if ($this->center !== null) {
$this->pages = $this->entityManager->getRepository(Page::class)->findBy([
'parent' => $this->center
], ['title' => 'ASC']);
}
}
}
#[Route('/', name: 'app_index')]
public function index(): Response
{
return $this->render('index/index.html.twig');
}
#[Route('/{city}', name: 'app_index_city')]
public function dashboard($city): Response
{
$items = $this->entityManager->getRepository(News::class)->findActiveByCenter($this->center);
return $this->render('index/homepage.html.twig', [
'center' => $this->center,
'city' => $city,
'carousel' => $items
]);
}
#[Route('/{city}/kino', name: 'app_city_cinema')]
#[Route('/{city}/kino/{date}', name: 'app_city_cinema_date')]
public function cinema($city, ?string $date): Response
{
$today = new \DateTime('now');
$selected = $today;
if ($date !== null) {
$selected = DateTime::createFromFormat('Y-m-d', $date);
}
$movies = $this->entityManager->getRepository(Movie::class)->findByCenterAndDate($this->center, $selected);
$cinema = $this->entityManager->getRepository(Business::class)->findOneBy([
'parent' => $this->center,
'isCinema' => true
]);
return $this->render('index/cinema.html.twig', [
'city' => $city,
'today' => $today,
'selected' => $selected,
'center' => $this->center,
'cinema' => $cinema,
'movies' => $movies
]);
}
#[Route('/{city}/prevadzky', name: 'app_city_businesses')]
#[Route('/{city}/prevadzka/{url}', name: 'app_city_business')]
public function business($city, ?string $url): Response
{
$discounts = null;
$filter = $this->createForm(CategoryFilterType::class, null, ['center' => $this->center]);
$selected = $this->entityManager->getRepository(Business::class)->findOneBy(
[
'parent' => $this->center,
'url' => $url
]
);
$filter->handleRequest($this->request);
if ($filter->isSubmitted() && $filter->get('category')->getData() !== null) {
$category = $filter->get('category')->getData();
$list = $this->entityManager->getRepository(Business::class)->searchByCategoryAndCenter($category, $this->center);
} else {
if ($selected instanceof Business) {
$discounts = $this->entityManager->getRepository(Discount::class)->findActiveByBusiness($selected);
$list = $this->entityManager->getRepository(Business::class)->findBy([
'parent' => $this->center,
'floor' => $selected->getFloor(),
'published' => true
], ['title' => 'asc']);
} else {
$list = $this->entityManager->getRepository(Business::class)->findBy([
'parent' => $this->center,
'published' => true
], ['title' => 'asc']);
}
}
return $this->render('index/business.html.twig', [
'city' => $city,
'center' => $this->center,
'selected' => $selected,
'discounts' => $discounts,
'list' => $list,
'form' => $filter->createView()
]);
}
#[Route('/{city}/mapa', name: 'app_city_business_map')]
#[Route('/{city}/mapa/{floor}', name: 'app_city_business_map_floor')]
public function map($city, ?string $floor): Response
{
$nr = NodeFactory::parseFloorToInt($floor);
$category = null;
$filter = $this->createForm(CategoryFilterType::class, null, ['center' => $this->center]);
$filter->handleRequest($this->request);
if ($filter->isSubmitted() && $filter->get('category')->getData() !== null) {
$category = $filter->get('category')->getData();
$list = $this->entityManager->getRepository(Business::class)->searchByCategoryAndCenter($category, $this->center, $nr);
} else {
$list = $this->entityManager->getRepository(Business::class)->findBy([
'parent' => $this->center,
'floor' => $nr
], ['title' => 'asc']);
}
return $this->render('index/map.html.twig', [
'city' => $city,
'center' => $this->center,
'list' => $list,
'floor' => $nr,
'category' => $category,
'form' => $filter->createView()
]);
}
#[Route('/{city}/podujatia', name: 'app_city_news')]
#[Route('/{city}/podujatie/{url}', name: 'app_city_news_detail')]
public function news($city, ?string $url): Response
{
$selected = $this->entityManager->getRepository(News::class)->findOneBy(['url' => $url]);
$list = $this->entityManager->getRepository(News::class)->findActiveByCenter($this->center);
return $this->render('index/news.html.twig', [
'city' => $city,
'center' => $this->center,
'selected' => $selected,
'list' => $list
]);
}
#[Route('/{city}/akcie-a-zlavy', name: 'app_city_discounts')]
#[Route('/{city}/akcie-a-zlavy/{businessUrl}/{url}', name: 'app_city_discount')]
public function discounts($city, ?string $businessUrl, ?string $url): Response
{
$list = $this->entityManager->getRepository(Discount::class)->findActiveByCenter($this->center);
$business = $this->entityManager->getRepository(Business::class)->findOneBy([
'parent' => $this->center,
'url' => $businessUrl
]);
$selected = $this->entityManager->getRepository(Discount::class)->findOneBy([
'parent' => $business,
'url' => $url
]);
return $this->render('index/discounts.html.twig', [
'city' => $city,
'center' => $this->center,
'list' => $list,
'selected' => $selected
]);
}
#[Route('/{city}/o-nas', name: 'app_city_about')]
public function about($city): Response
{
$nodes = $this->entityManager->getRepository(Page::class)->findBy(['parent' => $this->center]);
return $this->render('index/about-us.html.twig', [
'city' => $city,
'center' => $this->center,
'list' => $nodes
]);
}
#[Route('/{city}/o-nas/{url}', name: 'app_city_about_page')]
public function aboutPage($city, ?string $url): Response
{
$page = $this->entityManager->getRepository(Page::class)->findOneBy(['parent' => $this->center, 'url' => $url]);
return $this->render('index/page.html.twig', [
'city' => $city,
'center' => $this->center,
'page' => $page
]);
}
}