src/Action/VendreAction.php line 18

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\Form\Handler\ContactFormHandler;
  6. use App\Form\Type\ContactFormType;
  7. use App\Responder\RedirectResponder;
  8. use App\Responder\TemplateResponder;
  9. use App\Infra\Services\FilterApiService;
  10. use Symfony\Component\Form\FormFactoryInterface;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Contracts\HttpClient\HttpClientInterface;
  14. class VendreAction extends AbstractAction
  15. {
  16.     public function __construct(
  17.         TemplateResponder $templateResponder,
  18.         RedirectResponder $redirectResponder,
  19.         FormFactoryInterface $formFactory,
  20.         ContactFormHandler $contactFormHandler,
  21.         FilterApiService $apiService
  22.     )
  23.     {
  24.         $this->templateResponder $templateResponder;
  25.         $this->redirectResponder $redirectResponder;
  26.         $this->formFactory $formFactory;
  27.         $this->contactFormHandler $contactFormHandler;
  28.         $this->apiService $apiService;
  29.     }
  30.     /**
  31.      * @Route("/vendre", name="vendre")
  32.      */
  33.     public function __invoke(Request $request)
  34.     {
  35.         $contactType $this->formFactory
  36.             ->create(ContactFormType::class)
  37.             ->handleRequest($request);
  38.         if ($this->contactFormHandler->handle($contactType)) {
  39.             return $this->redirectResponder->__invoke('contact');
  40.         }
  41.         $toSales $this->apiService->getPropertiesByCategory(1);
  42.         $salesProperties = [];
  43.         foreach ($toSales as $property) {
  44.             //if ($property['category'] == 1 or $property['category'] == 2) {
  45.             $salesProperties[] = [$property][0];
  46.             //}
  47.         }
  48.         $toRents $this->apiService->getPropertiesByCategory(2);
  49.         $rentsProperties = [];
  50.         foreach ($toRents as $property) {
  51.             //if ($property['category'] == 1 or $property['category'] == 2) {
  52.             $rentsProperties[] = [$property][0];
  53.             //}
  54.         }
  55.         return $this->templateResponder->__invoke(
  56.             'vendre.html.twig', [
  57.                 'form' => $contactType->createView(),
  58.                 'salesProperties' => array_slice($salesProperties3),
  59.                 'rentsProperties' => array_slice($rentsProperties3)
  60.             ]
  61.         );
  62.     }
  63. }