src/Controller/ProspectsController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Prospects;
  4. use App\Form\ProspectsType;
  5. use App\Repository\ProspectsRepository;
  6. use App\Repository\ReferentsRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Datetime;
  12. /**
  13.  * @Route("/prospects")
  14.  */
  15. class ProspectsController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="app_prospects_index", methods={"GET"})
  19.      */
  20.     public function index(ProspectsRepository $prospectsRepository): Response
  21.     {
  22.         return $this->render('prospects/index.html.twig', [
  23.             'prospects' => $prospectsRepository->findAll(),
  24.         ]);
  25.     }
  26.     /**
  27.      * @Route("/new/{code}", name="app_prospects_new", methods={"GET", "POST"})
  28.      */
  29.     public function new(Request $requestProspectsRepository $prospectsRepository,$codeReferentsRepository $referentsRepo): Response
  30.     {
  31.      
  32.         $referent $referentsRepo->findOneBy(array('Code'=>$code));
  33.         if(empty($referent))
  34.         {
  35.             dd("Erreur de code contacter l'administrateur");
  36.         }
  37.         $prospect = new Prospects();
  38.         $form $this->createForm(ProspectsType::class, $prospect);
  39.         $form->handleRequest($request);
  40.         if ($form->isSubmitted() && $form->isValid()) {
  41.             $prospExist $prospectsRepository->findOneBy(array('Email'=>$prospect->getEmail()));
  42.             if(empty($prospExist))
  43.             {
  44.                 $prospect->setDateNaissance(new Datetime($_POST['date']));
  45.                 $prospect->setReferents($referent);
  46.                 $prospectsRepository->add($prospecttrue);
  47.             }
  48.             return $this->redirectToRoute('app_prospects_new', ['code'=>$code,'message'=>'success'], Response::HTTP_SEE_OTHER);
  49.         }
  50.         return $this->renderForm('prospects/new.html.twig', [
  51.             'prospect' => $prospect,
  52.             'form' => $form,
  53.             'code' => $code
  54.         ]);
  55.     }
  56.     /**
  57.      * @Route("/{id}", name="app_prospects_show", methods={"GET"})
  58.      */
  59.     public function show(Prospects $prospect): Response
  60.     {
  61.         return $this->render('prospects/show.html.twig', [
  62.             'prospect' => $prospect,
  63.         ]);
  64.     }
  65.     /**
  66.      * @Route("/{id}/edit", name="app_prospects_edit", methods={"GET", "POST"})
  67.      */
  68.     public function edit(Request $requestProspects $prospectProspectsRepository $prospectsRepository): Response
  69.     {
  70.         $form $this->createForm(ProspectsType::class, $prospect);
  71.         $form->handleRequest($request);
  72.         if ($form->isSubmitted() && $form->isValid()) {
  73.             $prospectsRepository->add($prospecttrue);
  74.             return $this->redirectToRoute('app_prospects_index', [], Response::HTTP_SEE_OTHER);
  75.         }
  76.         return $this->renderForm('prospects/edit.html.twig', [
  77.             'prospect' => $prospect,
  78.             'form' => $form,
  79.         ]);
  80.     }
  81.     /**
  82.      * @Route("/{id}", name="app_prospects_delete", methods={"POST"})
  83.      */
  84.     public function delete(Request $requestProspects $prospectProspectsRepository $prospectsRepository): Response
  85.     {
  86.         if ($this->isCsrfTokenValid('delete'.$prospect->getId(), $request->request->get('_token'))) {
  87.             $prospectsRepository->remove($prospecttrue);
  88.         }
  89.         return $this->redirectToRoute('app_prospects_index', [], Response::HTTP_SEE_OTHER);
  90.     }
  91. }