src/Controller/PublicController.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Service\Business\ImmoRepository;
  4. use Doctrine\DBAL\Connection;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class PublicController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/", name="public_home")
  13.      */
  14.     public function home(ImmoRepository $repository): Response
  15.     {
  16.         return $this->render('public/home.html.twig', [
  17.             'projects' => array_slice($repository->listProjects(null, true), 0, 3),
  18.         ]);
  19.     }
  20.     /**
  21.      * @Route("/entreprise", name="public_about")
  22.      */
  23.     public function about(Connection $connection): Response
  24.     {
  25.         return $this->render('public/about.html.twig', [
  26.             'enterprise' => $connection->fetchAssociative('SELECT * FROM enterprise ORDER BY id ASC LIMIT 1'),
  27.         ]);
  28.     }
  29.     /**
  30.      * @Route("/projets", name="public_projects")
  31.      */
  32.     public function projects(Request $request, ImmoRepository $repository): Response
  33.     {
  34.         return $this->render('public/projects.html.twig', [
  35.             'projects' => $repository->listProjects($request->query->get('q'), true),
  36.             'q' => $request->query->get('q'),
  37.         ]);
  38.     }
  39.     /**
  40.      * @Route("/projets/{id}", name="public_project_show", requirements={"id"="\d+"})
  41.      */
  42.     public function projectShow(int $id, Connection $connection): Response
  43.     {
  44.         $project = $connection->fetchAssociative('SELECT * FROM real_estate_project WHERE id = ? AND is_published = 1', [$id]);
  45.         if (!$project) {
  46.             throw $this->createNotFoundException('Projet introuvable.');
  47.         }
  48.         return $this->render('public/project_show.html.twig', [
  49.             'project' => $project,
  50.             'properties' => $connection->fetchAllAssociative('SELECT * FROM property WHERE project_id = ? ORDER BY status ASC, price ASC LIMIT 40', [$id]),
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/contact", name="public_contact")
  55.      */
  56.     public function contact(Request $request): Response
  57.     {
  58.         if ($request->isMethod('POST') && $this->isCsrfTokenValid('public-contact', (string) $request->request->get('_token'))) {
  59.             $this->addFlash('success', 'Votre message a été enregistré pour la démonstration.');
  60.         }
  61.         return $this->render('public/contact.html.twig');
  62.     }
  63. }