<?php
namespace AutomarketBundle\Controller;
use AutomarketBundle\Services\CatalogService;
use AutomarketBundle\Services\MainService;
use CoreBundle\Component\CoreFormFactory;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use PortalBundle\Model\SeoMetaTag;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
class MainController extends BaseController
{
private CatalogService $catalogService;
private MainService $mainService;
public function __construct(CoreFormFactory $coreFormFactory, RequestStack $requestStack, EntityManagerInterface $em,
SeoMetaTag $seoMetaTag, CatalogService $catalogService, MainService $mainService)
{
parent::__construct($coreFormFactory, $requestStack, $em, $seoMetaTag);
$this->catalogService = $catalogService;
$this->mainService = $mainService;
}
public function redirectAutomarket(): RedirectResponse
{
return $this->redirectToRoute('automarket_homepage');
}
public function index(Request $request): Response
{
$lang = $request->getLocale();
$this->mainService->setLang($lang);
return $this->baseAutomarketRender('@Automarket/Main/index.html.twig', [
'onShowParam' => $this->catalogService->getOnShowFilter(),
'bodyTypes' => $this->mainService->getBodyTypes($this->getDealer()),
'newArrivals' => $this->mainService->getNewArrivals($this->getDealer(), $this->getUser(), true, $lang),
'ourSelections' => $this->mainService->getOurSelections(),
'brands' => $this->mainService->getBrands($this->getDealer())
]);
}
public function robots(): Response
{
$Dealer = $this->getDealer();
$response = new Response();
$response->headers->set('Content-Type', 'text/plain');
return $this->baseAutomarketRender('@Automarket//robots.txt.twig', [
'Dealer' => $Dealer
], $response);
}
public function pageError(Request $request): Response
{
return $this->baseAutomarketRender('@Automarket/404.html.twig', ['_locale' => $request->getLocale()]);
}
public function personalData(): Response
{
return $this->baseAutomarketRender('@Automarket/personal-data.html.twig', ['dealer' => $this->getDealer()]);
}
}