<?php
declare(strict_types = 1);
namespace App\Action;
use App\Infra\Services\ApiService;
use App\Responder\RedirectResponder;
use App\Responder\TemplateResponder;
use App\Infra\Services\FilterApiService;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use App\Domain\Repository\Interfaces\TextRepositoryInterface;
use App\Infra\Services\PopupService;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
class HomeAction extends AbstractAction
{
public function __construct(
TemplateResponder $templateResponder,
RedirectResponder $redirectResponder,
PdoSessionHandler $pdoSessionHandler,
ApiService $apiService,
FilterApiService $filterApiService,
RequestStack $requestStack
)
{
parent::__construct($templateResponder, $redirectResponder, $requestStack);
//$this->templateResponder = $templateResponder;
//$this->redirectResponder = $redirectResponder;
$this->apiService = $apiService;
$this->filterApiService = $filterApiService;
}
/**
* @Route("/", name="index")
*/
public function __invoke()
{
$properties = $this->apiService->getAllProperties();
//$references = $this->filterApiService->getReferencesWithoutParking();
$references = $this->filterApiService->getResidenceReferences();
$futurProjects = $this->filterApiService->getFuturProjects();
$buildingProjects = $this->filterApiService->getConstructionProjects();
$projects = $this->filterApiService->getAllProjects();
// Propriétées en vente
$salesProperties = $this->filterApiService->getPropertiesByCategory(1);
$projects = array_reverse($projects);
$arrayOtherProperties = [];
foreach ($properties['properties'] as $property) {
if ($property['category'] == 1 or $property['category'] == 2) {
$arrayOtherProperties[] = [$property][0];
}
}
$popup = new PopupService($this->request);
$response = $this->templateResponder->__invoke('home.html.twig', [
'properties' => $arrayOtherProperties,
'references' => $references,
'futurProjects' => $futurProjects,
'salesProperties' => array_slice($salesProperties, 0 , 4),
'buildingProjects' => $buildingProjects,
'projects' => $projects,
'popup2024' => $popup->showPopup()
]);
if($popup->showPopup()) $response->headers->setCookie($popup->getCookie());
return $response;
}
}