<?php
namespace App\Controller\Frontend;
use App\Business\Cart\Session\CartSessionHandlerInterface;
use App\Business\Frontend\Index\IndexDataProviderInterface;
use App\Entity\Customer;
use App\Service\Utils\CustomerServiceInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class IndexController extends AbstractController
{
protected ?Customer $customer;
protected CartSessionHandlerInterface $cartSessionHandler;
/**
* @param CustomerServiceInterface $customerService
* @param CartSessionHandlerInterface $cartSessionHandler
*/
public function __construct(
CustomerServiceInterface $customerService,
CartSessionHandlerInterface $cartSessionHandler
) {
$this->customer = $customerService->getCustomerByHost();
$this->cartSessionHandler = $cartSessionHandler;
}
/**
* @param IndexDataProviderInterface $dataProvider
*
* @return Response
*/
#[Route('/', name: 'app_frontend_index')]
public function index(IndexDataProviderInterface $dataProvider): Response
{
if ($this->customer === null) {
return $this->redirectToRoute('app_frontend_customer_not_found');
}
return $this->render('frontend/index/index.html.twig', [
'sortedAreasArray' => $dataProvider->getCustomerPackagePlacesAndAreas(),
'latestSponsors' => $dataProvider->getLatestSponsors(4),
]);
}
/**
* @return Response
*/
#[Route('/not-found', name: 'app_frontend_customer_not_found')]
public function customerNotFound(): Response
{
return $this->render('frontend/index/customer_not_found.html.twig', [
'controller_name' => 'MainController',
]);
}
/**
* @return Response
*/
#[Route('/customer_styles.css', name: 'app_frontend_customer_css')]
public function customerCSS(): Response
{
$response = new Response();
$response->headers->set('Content-Type', 'text/css');
return $this->render('frontend/css/customer_styles.css.twig', [
'customer' => $this->customer
], $response);
}
}