src\Controller\Site\FormationsController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Site;
  3. use App\Controller\BaseController;
  4. use App\Entity\CategorieFormation;
  5. use App\Entity\ProgrammeFormation;
  6. use App\Repository\ProgrammeFormationRepository;
  7. use Cocur\Slugify\Slugify;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Knp\Component\Pager\PaginatorInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class FormationsController extends BaseController
  13. {
  14.     private $em,$paginator;
  15.     public function __construct(EntityManagerInterface $emPaginatorInterface $paginator)
  16.     {
  17.         $this->em=$em;
  18.         $this->paginator $paginator;
  19.     }
  20.     #[Route(path'/formations/{slug?}'name'site_formation')]
  21.     public function index(Request $request,ProgrammeFormationRepository $repository,CategorieFormation $categorieFormation=null)
  22.     {
  23.         //$this->makeSlug();
  24.         //dd();
  25.         //#2
  26.         $catId=($categorieFormation)? $categorieFormation->getId():null;
  27.         $q=$request->query->get('q');
  28.         $categories=$this->em->getRepository(CategorieFormation::class)->findBy([],['titre'=>'ASC']);
  29.         $all=$this->em->getRepository(ProgrammeFormation::class)->findValid($q,$catId);
  30.         //$all=$repository->findAll();
  31.         $paginedData=$this->paginator->paginate($all,$request->query->getInt('page'1),18);
  32.         return $this->render('site/formations/index.html.twig', [
  33.             'programmes'=>$paginedData,
  34.             'q'=>$q,
  35.             'catId'=>$catId,
  36.             'categories'=>$categories,
  37.         ]);
  38.     }
  39.     #[Route(path'/formation/{id}/'name'site_formation_show')]
  40.     public function show(ProgrammeFormation $programmeFormation,ProgrammeFormationRepository $repository)
  41.     {
  42.         $related=$repository->findRelated($programmeFormation,3);
  43.         return $this->render('site/formations/show.html.twig', [
  44.             'programme'=>$programmeFormation,
  45.             'related'=>$related,
  46.         ]);
  47.     }
  48.      private function makeSlug(){
  49.         $typenewsRepository $this->em->getRepository(CategorieFormation::class);
  50.         $slugify=new Slugify();
  51.         $items=$typenewsRepository->findAll();
  52.         foreach ($items as $item) {
  53.             $item->setSlug($slugify->slugify($item->getTitre()));
  54.         }
  55.         $this->em->flush();
  56.     }
  57. }