<?php
declare(strict_types = 1);
namespace App\Action;
use App\Domain\Repository\Interfaces\TextRepositoryInterface;
use App\Infra\Services\ApiService;
use App\Infra\Services\FilterApiService;
use App\Responder\RedirectResponder;
use App\Responder\TemplateResponder;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class PropertyAction extends AbstractAction
{
public function __construct(
TemplateResponder $templateResponder,
RedirectResponder $redirectResponder,
FilterApiService $apiService
)
{
$this->templateResponder = $templateResponder;
$this->redirectResponder = $redirectResponder;
$this->apiService = $apiService;
}
/**
* @Route("/biens/{keyword}", defaults={"keyword" = null}, name="properties")
*/
public function __invoke(?string $keyword)
{
if (!$keyword) {
$keyword = 'all';
}
$idCategory = $this->apiService->getInversePropertyCategory(ucfirst($keyword));
$properties = $this->apiService->getPropertiesByCategory($idCategory);
$saleProperties = [];
foreach ($properties as $property) {
//if ($property['category'] == 1 or $property['category'] == 2) {
$saleProperties[] = [$property][0];
//}
}
if ($idCategory === 1) {
$idCategory = 2;
} else {
$idCategory = 1;
}
$otherProperties = $this->apiService->getPropertiesByCategory($idCategory);
$arrayOtherProperties = [];
foreach ($otherProperties as $property) {
//if ($property['category'] == 1 or $property['category'] == 2) {
$arrayOtherProperties[] = [$property][0];
//}
}
return $this->templateResponder->__invoke('property.html.twig', [
'properties' => $properties,
'otherProperties' => array_slice($arrayOtherProperties, 0 , 3)
]);
}
}