<?php
declare(strict_types = 1);
namespace App\Action\Ajax;
use App\Domain\Repository\Interfaces\JobRepositoryInterface;
use App\Infra\Services\FilterApiService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Twig\Environment;
class SearchFormAction
{
public function __construct(
FilterApiService $filterApiService,
Environment $environment
)
{
$this->filterApiService = $filterApiService;
$this->environnement = $environment;
}
/**
* @Route("/form/search", name="form-search", methods={"GET"})
*/
public function __invoke(Request $request)
{
$regions = [];
$properties = $this->filterApiService->getPropertiesForCities();
foreach ($properties as $property) {
// $regions[] = $property['region']['name'];
$regions[$property['city']['name']] = $property['city']['name'];
if ( $property['district'] !== null) {
$regions[$property['district']['name']] = $property['district']['name'];
}
}
$regions = ['' => 'Tous'] + $regions;
ksort($regions);
$regions = array_unique($regions);
return new JsonResponse($regions, 200);
}
}