<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Controller\Dashboard\Admin;
use App\Entity\Category;
use App\Entity\Experience;
use App\Entity\User;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
//use App\Entity\Experience;
/**
* Controller used to manage current user.
*
* @author Romain Monteil <monteil.romain@gmail.com>
*/
#[Route('/admin/experience')]
class ExperiencesListController extends AbstractController {
#[Route('/experiences-list', methods: ['GET','POST'], name: 'experiences_list')]
public function listExperiences(Request $request, ManagerRegistry $doctrine): Response
{
$em = $doctrine->getManager();
$categories = $em->getRepository(Category::class)->findAll();
$coaches = $em->getRepository(User::class)->findAll();
$qb = $em->getRepository(Experience::class)
->createQueryBuilder('e')
->orderBy('e.id', 'DESC');
if ($request->isMethod('POST')) {
if ($type = $request->get('typeCoach')) {
$qb
->andWhere('e.coachingtype = :type')
->setParameter('type', $type);
}
if ($catId = $request->get('category')) {
$qb
->innerJoin('e.subcategories', 'sc')
->innerJoin('sc.category', 'c')
->andWhere('c.id = :catId')
->setParameter('catId', $catId);
}
$experiences = $qb->getQuery()->getResult();
} else {
$experiences = $em->getRepository(Experience::class)->findAll();
}
return $this->render('admin/experience/list/listExperiences.html.twig', [
'experiences' => $experiences,
'categories' => $categories,
'coaches' => $coaches
]);
}
}