src/Controller/FormationsController.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\CategorieRepository;
  4. use App\Repository\FormationRepository;
  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. /**
  10.  * Controleur des formations
  11.  *
  12.  * @author emds
  13.  */
  14. class FormationsController extends AbstractController
  15. {
  16.     /**
  17.      *
  18.      * @var FormationRepository
  19.      */
  20.     private $formationRepository;
  21.     
  22.     /**
  23.      *
  24.      * @var CategorieRepository
  25.      */
  26.     private $categorieRepository;
  27.     const PAGEFORMATION "pages/formations.html.twig";
  28.     const PAGE_FORMATION_ADMIN "admin_formation/index.html.twig";
  29.     public function __construct(FormationRepository $formationRepositoryCategorieRepository $categorieRepository)
  30.     {
  31.         $this->formationRepository $formationRepository;
  32.         $this->categorieRepository$categorieRepository;
  33.     }
  34.     
  35.     /**
  36.      * @Route("/formations", name="formations")
  37.      * @return Response
  38.      */
  39.     public function index(): Response
  40.     {
  41.         $formations $this->formationRepository->findAll();
  42.         $categories $this->categorieRepository->findAll();
  43.         return $this->render($this::PAGEFORMATION, [
  44.             'formations' => $formations,
  45.             'categories' => $categories
  46.         ]);
  47.     }
  48.     /**
  49.      * @Route("/formations/tri/{champ}/{ordre}/{table}", name="formations.sort")
  50.      * @Route("/admin/formations/tri/{champ}/{ordre}/{table}", name="admin.formations.sort")
  51.      * @param type $champ
  52.      * @param type $ordre
  53.      * @param type $table
  54.      * @return Response
  55.      */
  56.     public function sort(Request $request$champ$ordre$table=""): Response
  57.     {
  58.         if ($table==="") {
  59.             $formations $this->formationRepository->findAllOrderBy($champ$ordre);
  60.         } else {
  61.             $formations $this->formationRepository->findAllOrderByInTable($champ$ordre$table);
  62.         }
  63.         $categories $this->categorieRepository->findAll();
  64.         if ($request->get('_route') === "admin.formations.sort") {
  65.             return $this->render($this::PAGE_FORMATION_ADMIN, [
  66.                 'formations' => $formations,
  67.                 'categories' => $categories,
  68.             ]);
  69.         }
  70.         return $this->render($this::PAGEFORMATION, [
  71.             'formations' => $formations,
  72.             'categories' => $categories
  73.         ]);
  74.     }
  75.     
  76.     /**
  77.      * @Route("/formations/recherche/{champ}/{table}", name="formations.findallcontain")
  78.      * @Route("/admin/formations/recherche/{champ}/{table}", name="admin.formations.findallcontain")
  79.      * @param type $champ
  80.      * @param Request $request
  81.      * @param type $table
  82.      * @return Response
  83.      */
  84.     public function findAllContain($champRequest $request$table=""): Response
  85.     {
  86.         $valeur $request->get("recherche");
  87.         if ($valeur=="") {
  88.             $formations $this->formationRepository->findAll();
  89.         } elseif ($table=="") {
  90.             $formations $this->formationRepository->findByContainValue($champ$valeur);
  91.         } else {
  92.             $formations $this->formationRepository->findByContainValueInTable($champ$valeur$table);
  93.         }
  94.         $categories $this->categorieRepository->findAll();
  95.         if ($request->get('_route') === "admin.formations.findallcontain") {
  96.             return $this->render($this::PAGE_FORMATION_ADMIN, [
  97.                 'formations' => $formations,
  98.                 'categories' => $categories,
  99.                 'valeur' => $valeur,
  100.                 'table' => $table
  101.             ]);
  102.         }
  103.         return $this->render($this::PAGEFORMATION, [
  104.             'formations' => $formations,
  105.             'categories' => $categories,
  106.             'valeur' => $valeur,
  107.             'table' => $table
  108.         ]);
  109.     }
  110.     /**
  111.      * @Route("/formations/formation/{id}", name="formations.showone")
  112.      * @param type $id
  113.      * @return Response
  114.      */
  115.     public function showOne($id): Response
  116.     {
  117.         $formation $this->formationRepository->find($id);
  118.         return $this->render("pages/formation.html.twig", [
  119.             'formation' => $formation
  120.         ]);
  121.     }
  122.     
  123. }