src/Controller/AvocatsController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Avocats;
  4. use App\Form\AvocatsType;
  5. use App\Repository\AvocatsRepository;
  6. use App\Repository\JoursSemaineRepository;
  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. /**
  12.  * @Route("/avocats")
  13.  */
  14. class AvocatsController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/", name="app_avocats_index", methods={"GET"})
  18.      */
  19.     public function index(AvocatsRepository $avocatsRepository): Response
  20.     {
  21.         $user $this->getUser();
  22.         if (in_array('ROLE_ADMIN'$this->getUser()->getRoles(), true)) 
  23.         {
  24.             $avc $avocatsRepository->findBy(array('Deleted'=>0));
  25.             $role 'admin';
  26.         }
  27.         else
  28.         {
  29.             $avc $avocatsRepository->findBy(array('id'=>$user->getAvocats()));
  30.             $role 'user';
  31.         }
  32.         return $this->render('avocats/index.html.twig', [
  33.             'avocats' => $avc,
  34.             'role'=>$role
  35.         ]);
  36.     }
  37.     /**
  38.      * @Route("/new", name="app_avocats_new", methods={"GET", "POST"})
  39.      */
  40.     public function new(Request $requestAvocatsRepository $avocatsRepository): Response
  41.     {
  42.         $avocat = new Avocats();
  43.         $form $this->createForm(AvocatsType::class, $avocat);
  44.         $form->handleRequest($request);
  45.         if ($form->isSubmitted() && $form->isValid()) {
  46.             $file $form->get('Photos')->getData();
  47.             if($file != 'ok') {
  48.                 $path '/';
  49.                 $fileName uniqid().'-'.$file->getClientOriginalName();
  50.                 $file->move(
  51.                     $this->getParameter('photos_directory').$path,
  52.                     $fileName
  53.                 );
  54.                 
  55.                 $avocat->setPhotos($fileName);
  56.             }
  57.             $avocat->setDeleted(0);
  58.             
  59.             $avocatsRepository->add($avocattrue);
  60.             return $this->redirectToRoute('app_avocats_index', [], Response::HTTP_SEE_OTHER);
  61.         }
  62.         return $this->renderForm('avocats/new.html.twig', [
  63.             'avocat' => $avocat,
  64.             'form' => $form,
  65.         ]);
  66.     }
  67.     /**
  68.      * @Route("/{id}", name="app_avocats_show", methods={"GET"})
  69.      */
  70.     public function show(Avocats $avocat): Response
  71.     {
  72.         return $this->render('avocats/show.html.twig', [
  73.             'avocat' => $avocat,
  74.         ]);
  75.     }
  76.     /**
  77.      * @Route("/{id}/edit", name="app_avocats_edit", methods={"GET", "POST"})
  78.      */
  79.     public function edit(Request $requestAvocats $avocatAvocatsRepository $avocatsRepositoryJoursSemaineRepository $joursSemaineRepo): Response
  80.     {
  81.         $js $joursSemaineRepo->findBy(array('Avocats'=>$avocat));
  82.         $form $this->createForm(AvocatsType::class, $avocat);
  83.         $form->handleRequest($request);
  84.         if ($form->isSubmitted() && $form->isValid()) {
  85.             $avocatsRepository->add($avocattrue);
  86.             return $this->redirectToRoute('app_avocats_index', [], Response::HTTP_SEE_OTHER);
  87.         }
  88.         return $this->renderForm('avocats/edit.html.twig', [
  89.             'avocat' => $avocat,
  90.             'form' => $form,
  91.             'js'=>$js
  92.         ]);
  93.     }
  94.     /**
  95.      * @Route("/{id}", name="app_avocats_delete", methods={"POST"})
  96.      */
  97.     public function delete(Request $requestAvocats $avocatAvocatsRepository $avocatsRepository): Response
  98.     {
  99.         if ($this->isCsrfTokenValid('delete'.$avocat->getId(), $request->request->get('_token'))) {
  100.            $avocat->setDeleted(1);
  101.             $avocatsRepository->add($avocattrue);
  102.         }
  103.         return $this->redirectToRoute('app_avocats_index', [], Response::HTTP_SEE_OTHER);
  104.     }
  105.     
  106. }