src/Action/PropertyDetailAction.php line 14

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\Responder\RedirectResponder;
  7. use App\Responder\TemplateResponder;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Contracts\HttpClient\HttpClientInterface;
  10. class PropertyDetailAction extends AbstractAction
  11. {
  12.     public function __construct(
  13.         TemplateResponder $templateResponder,
  14.         RedirectResponder $redirectResponder,
  15.         ApiService $apiService
  16.     )
  17.     {
  18.         $this->templateResponder $templateResponder;
  19.         $this->redirectResponder $redirectResponder;
  20.         $this->apiService $apiService;
  21.     }
  22.     /**
  23.      * @Route("/bien/detail/{id}", name="property-detail")
  24.      */
  25.     public function __invoke(string $id)
  26.     {
  27.         $property $this->apiService->getPropertyById($id);
  28.         $properties = [];
  29.         $smilarProperties $this->apiService->getAllProperties()['properties'];
  30.         foreach ($smilarProperties as $smilarProperty) {
  31.             if ($property['bedrooms'] !==  && ($property['bedrooms'] === $smilarProperty['bedrooms']) ) {
  32.                 $properties[] = $smilarProperty;
  33.             }
  34.         }
  35.         if (empty($properties)) {
  36.             foreach ($smilarProperties as $smilarProperty) {
  37.                 if ($property['type'] === $smilarProperty['type']) {
  38.                     $properties[] = $smilarProperty;
  39.                 }
  40.             }
  41.         }
  42.         return $this->templateResponder->__invoke('property-detail.html.twig', [
  43.             'property' => $property,
  44.             'otherProperties' => array_slice($properties3)
  45.         ]);
  46.     }
  47. }