src/Action/PropertyAction.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. namespace App\Action;
  4. use App\Domain\Repository\Interfaces\TextRepositoryInterface;
  5. use App\Infra\Services\ApiService;
  6. use App\Infra\Services\FilterApiService;
  7. use App\Responder\RedirectResponder;
  8. use App\Responder\TemplateResponder;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Contracts\HttpClient\HttpClientInterface;
  11. class PropertyAction extends AbstractAction
  12. {
  13.     public function __construct(
  14.         TemplateResponder $templateResponder,
  15.         RedirectResponder $redirectResponder,
  16.         FilterApiService $apiService
  17.     )
  18.     {
  19.         $this->templateResponder $templateResponder;
  20.         $this->redirectResponder $redirectResponder;
  21.         $this->apiService $apiService;
  22.     }
  23.     /**
  24.      * @Route("/biens/{keyword}", defaults={"keyword" = null}, name="properties")
  25.      */
  26.     public function __invoke(?string $keyword)
  27.     {
  28.         if (!$keyword) {
  29.             $keyword 'all';
  30.         }
  31.         $idCategory $this->apiService->getInversePropertyCategory(ucfirst($keyword));
  32.         $properties $this->apiService->getPropertiesByCategory($idCategory);
  33.         $saleProperties = [];
  34.         foreach ($properties as $property) {
  35.             //if ($property['category'] == 1 or $property['category'] == 2) {
  36.                 $saleProperties[] = [$property][0];
  37.             //}
  38.         }
  39.         if ($idCategory === 1) {
  40.             $idCategory 2;
  41.         } else {
  42.             $idCategory 1;
  43.         }
  44.         $otherProperties $this->apiService->getPropertiesByCategory($idCategory);
  45.         $arrayOtherProperties = [];
  46.         foreach ($otherProperties as $property) {
  47.             //if ($property['category'] == 1 or $property['category'] == 2) {
  48.             $arrayOtherProperties[] = [$property][0];
  49.             //}
  50.         }
  51.         return $this->templateResponder->__invoke('property.html.twig', [
  52.             'properties' => $properties,
  53.             'otherProperties' => array_slice($arrayOtherProperties3)
  54.         ]);
  55.     }
  56. }