<?php
namespace App\Controller;
use App\Entity\Bien;
use App\Entity\BienSearch;
use App\Form\BienSearchType;
use App\Form\BienType;
use App\Repository\BienRepository;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/nos-biens")
*/
class BienController extends AbstractController
{
/**
* @Route("/", name="app_biens_index", methods={"GET"})
*/
public function index(
BienRepository $bienRepository,
PaginatorInterface $paginator,
Request $request
): Response {
//Recherche multicriteres
$search = new BienSearch();
$form = $this->createForm(BienSearchType::class, $search);
$form->handleRequest($request);
// $donnees = $bienRepository->findAll();
$donnees = $bienRepository->findAllVisibleQuery($search);
$biens = $paginator->paginate(
$donnees,
$request->query->getInt('page', 1),
9
);
return $this->render('biens/index.html.twig', [
'biens' => $biens,
'biensTotal' => $bienRepository->findAll(),
'biensTriville' => $bienRepository->findBy(['ville' => 'ASC'], []),
'form' => $form->createView(),
'pageTitle' => 'biens',
]);
}
// /**
// * @Route("/new", name="app_biens_new", methods={"GET", "POST"})
// */
// public function new(Request $request, BienRepository $bienRepository): Response
// {
// $bien = new Bien();
// $form = $this->createForm(BienType::class, $bien);
// $form->handleRequest($request);
// if ($form->isSubmitted() && $form->isValid()) {
// $bienRepository->add($bien, true);
// return $this->redirectToRoute('app_bien_index', [], Response::HTTP_SEE_OTHER);
// }
// return $this->renderForm('bien/new.html.twig', [
// 'bien' => $bien,
// 'form' => $form,
// ]);
// }
/**
* @Route("/{id}", name="app_biens_show", methods={"GET"})
*/
public function show(Bien $bien): Response
{
return $this->render('biens/show.html.twig', [
'biens' => $bien,
'pageTitle' => 'biens',
]);
}
// /**
// * @Route("/{id}/edit", name="app_biens_edit", methods={"GET", "POST"})
// */
// public function edit(Request $request, Bien $bien, BienRepository $bienRepository): Response
// {
// $form = $this->createForm(BienType::class, $bien);
// $form->handleRequest($request);
// if ($form->isSubmitted() && $form->isValid()) {
// $bienRepository->add($bien, true);
// return $this->redirectToRoute('app_bien_index', [], Response::HTTP_SEE_OTHER);
// }
// return $this->renderForm('bien/edit.html.twig', [
// 'bien' => $bien,
// 'form' => $form,
// ]);
// }
// /**
// * @Route("/{id}", name="app_biens_delete", methods={"POST"})
// */
// public function delete(Request $request, Bien $bien, BienRepository $bienRepository): Response
// {
// if ($this->isCsrfTokenValid('delete'.$bien->getId(), $request->request->get('_token'))) {
// $bienRepository->remove($bien, true);
// }
// return $this->redirectToRoute('app_bien_index', [], Response::HTTP_SEE_OTHER);
// }
}