<?php
namespace App\Repository;
use App\Entity\SessionsFormations;
use App\Entity\Formations;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<SessionsFormations>
*
* @method SessionsFormations|null find($id, $lockMode = null, $lockVersion = null)
* @method SessionsFormations|null findOneBy(array $criteria, array $orderBy = null)
* @method SessionsFormations[] findAll()
* @method SessionsFormations[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SessionsFormationsRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SessionsFormations::class);
}
public function add(SessionsFormations $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function findByCriteria($criteria)
{
$qb = $this->createQueryBuilder('j');
if (!empty($criteria['SujetsFormations'])) {
$qb->leftJoin('j.Formations', 'f')
->andWhere('f.SujetsFormations = :sujetsFormations')
->setParameter('sujetsFormations', $criteria['SujetsFormations']);
}
if (!empty($criteria['TypesFormations'])) {
$qb->andWhere('j.TypesFormations = :typesFormations')
->setParameter('typesFormations', $criteria['TypesFormations']);
}
if (!empty($criteria['TitreFr'])) {
$qb->leftJoin('j.Formations', 'f')
->andWhere('f.TitreFr = :titreFr')
->setParameter('titreFr', $criteria['TitreFr']);
}
if (!empty($criteria['Lieu'])) {
$qb->andWhere('j.Lieu = :lieu')
->setParameter('lieu', $criteria['Lieu']);
}
return $qb->getQuery()->getResult();
}
public function remove(SessionsFormations $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return SessionsFormations[] Returns an array of SessionsFormations objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?SessionsFormations
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
public function findSearch($sujet,$type,$lieu,$ref)
{
$qb = $this->getEntityManager()
->createQueryBuilder()
->select('DISTINCT s, f')
->from('App\Entity\SessionsFormations', 's')
->leftJoin('s.Formations', 'f')
->addSelect('f');
if(!empty($sujet)){
$qb->andWhere('f.TitreFr = :sujet')
->setParameter('sujet', $sujet);
}
if(!empty($type)){
$qb->andWhere('s.Type = :type')
->setParameter('type', $type);
}
if(!empty($lieu)){
$qb->andWhere('s.Lieu = :lieu')
->setParameter('lieu', $lieu);
}
if(!empty($ref)){
$qb->andWhere('f.Reference = :ref')
->setParameter('ref', $ref);
}
$query = $qb->getQuery();
$results = $query->getResult();
return($results);
}
}