src/Controller/Cours/FilterController.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Cours;
  3. use App\Repository\CoursRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. class FilterController extends AbstractController
  9. {
  10.     
  11.     public function index(CoursRepository $coursRepository Request $request): Response
  12.     {
  13.         $page $request->query->getInt('page'1);
  14.         $displayMode $request->query->get('display_mode''grid');
  15.         $limit $request->query->getInt('limit'3);
  16.         $searchTerm $request->query->get('search');
  17.         $subcategory $request->query->get('subcategory');
  18.         $offset = ($page 1) * $limit;
  19.         $data $coursRepository->findBySearchTermAndSubCategory($searchTerm$subcategory$limit$offset);
  20.  
  21.         $totalItems $coursRepository->countBySearchTermAndSubCategory($searchTerm$subcategory);
  22.  
  23.         $totalPages ceil($totalItems $limit);
  24.          
  25.  
  26.         return $this->render('home/cours/filter/index.html.twig', [
  27.             'data' => $data,
  28.             'currentPage' => $page,
  29.             'totalPages' => $totalPages,
  30.             'limit' => $limit,
  31.             'searchTerm' => $searchTerm,
  32.             'subcategory' => $subcategory,
  33.             'displayMode'=> $displayMode,
  34.         ]);
  35.     }
  36. }