src/Controller/Dashboard/Admin/ExperiencesListController.php line 67

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Controller\Dashboard\Admin;
  11. use App\Entity\Category;
  12. use App\Entity\Experience;
  13. use App\Entity\User;
  14. use Doctrine\Persistence\ManagerRegistry;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. //use App\Entity\Experience;
  20. /**
  21.  * Controller used to manage current user.
  22.  *
  23.  * @author Romain Monteil <monteil.romain@gmail.com>
  24.  */
  25. #[Route('/admin/experience')]
  26. class ExperiencesListController extends AbstractController {
  27.     #[Route('/experiences-list'methods: ['GET','POST'], name'experiences_list')]
  28.     public function listExperiences(Request $requestManagerRegistry $doctrine): Response
  29.     {
  30.         $em $doctrine->getManager();
  31.         $categories $em->getRepository(Category::class)->findAll();
  32.         $coaches $em->getRepository(User::class)->findAll();
  33.         $qb $em->getRepository(Experience::class)
  34.             ->createQueryBuilder('e')
  35.             ->orderBy('e.id''DESC');
  36.         if ($request->isMethod('POST')) {
  37.             if ($type $request->get('typeCoach')) {
  38.                 $qb
  39.                     ->andWhere('e.coachingtype = :type')
  40.                     ->setParameter('type'$type);
  41.             }
  42.             if ($catId $request->get('category')) {
  43.                 $qb
  44.                     ->innerJoin('e.subcategories''sc')
  45.                     ->innerJoin('sc.category',    'c')
  46.                     ->andWhere('c.id = :catId')
  47.                     ->setParameter('catId'$catId);
  48.             }
  49.             $experiences $qb->getQuery()->getResult();
  50.         } else {
  51.             $experiences $em->getRepository(Experience::class)->findAll();
  52.         }
  53.         return $this->render('admin/experience/list/listExperiences.html.twig', [
  54.             'experiences' => $experiences,
  55.             'categories'  => $categories,
  56.             'coaches'    => $coaches
  57.         ]);
  58.     }
  59. }