src/Repository/SessionsFormationsRepository.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\SessionsFormations;
  4. use App\Entity\Formations;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. /**
  8.  * @extends ServiceEntityRepository<SessionsFormations>
  9.  *
  10.  * @method SessionsFormations|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method SessionsFormations|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method SessionsFormations[]    findAll()
  13.  * @method SessionsFormations[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class SessionsFormationsRepository extends ServiceEntityRepository
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registrySessionsFormations::class);
  20.     }
  21.     public function add(SessionsFormations $entitybool $flush false): void
  22.     {
  23.         $this->getEntityManager()->persist($entity);
  24.         if ($flush) {
  25.             $this->getEntityManager()->flush();
  26.         }
  27.     }
  28.      public function findByCriteria($criteria)
  29.     {
  30.     
  31.         $qb $this->createQueryBuilder('j');
  32.         if (!empty($criteria['SujetsFormations'])) {
  33.             $qb->leftJoin('j.Formations''f'
  34.                ->andWhere('f.SujetsFormations = :sujetsFormations')
  35.                ->setParameter('sujetsFormations'$criteria['SujetsFormations']);
  36.         }
  37.     
  38.         if (!empty($criteria['TypesFormations'])) {
  39.             $qb->andWhere('j.TypesFormations = :typesFormations')
  40.                ->setParameter('typesFormations'$criteria['TypesFormations']);
  41.         }
  42.     
  43.         if (!empty($criteria['TitreFr'])) {
  44.             $qb->leftJoin('j.Formations''f'
  45.                ->andWhere('f.TitreFr = :titreFr')
  46.                ->setParameter('titreFr'$criteria['TitreFr']);
  47.         }
  48.         if (!empty($criteria['Lieu'])) {
  49.             $qb->andWhere('j.Lieu = :lieu')
  50.                ->setParameter('lieu'$criteria['Lieu']);
  51.         }
  52.     
  53.         return $qb->getQuery()->getResult();
  54.     }
  55.     public function remove(SessionsFormations $entitybool $flush false): void
  56.     {
  57.         $this->getEntityManager()->remove($entity);
  58.         if ($flush) {
  59.             $this->getEntityManager()->flush();
  60.         }
  61.     }
  62. //    /**
  63. //     * @return SessionsFormations[] Returns an array of SessionsFormations objects
  64. //     */
  65. //    public function findByExampleField($value): array
  66. //    {
  67. //        return $this->createQueryBuilder('s')
  68. //            ->andWhere('s.exampleField = :val')
  69. //            ->setParameter('val', $value)
  70. //            ->orderBy('s.id', 'ASC')
  71. //            ->setMaxResults(10)
  72. //            ->getQuery()
  73. //            ->getResult()
  74. //        ;
  75. //    }
  76. //    public function findOneBySomeField($value): ?SessionsFormations
  77. //    {
  78. //        return $this->createQueryBuilder('s')
  79. //            ->andWhere('s.exampleField = :val')
  80. //            ->setParameter('val', $value)
  81. //            ->getQuery()
  82. //            ->getOneOrNullResult()
  83. //        ;
  84. //    }
  85. public function findSearch($sujet,$type,$lieu,$ref)
  86.     {
  87.       
  88.         $qb $this->getEntityManager()
  89.             ->createQueryBuilder()
  90.             ->select('DISTINCT s, f')
  91.             ->from('App\Entity\SessionsFormations''s')
  92.             ->leftJoin('s.Formations''f')
  93.             ->addSelect('f');
  94.            
  95.             if(!empty($sujet)){
  96.                 $qb->andWhere('f.TitreFr = :sujet')
  97.                 ->setParameter('sujet'$sujet);
  98.             }
  99.             if(!empty($type)){
  100.                 $qb->andWhere('s.Type = :type')
  101.                 ->setParameter('type'$type);
  102.             }
  103.             if(!empty($lieu)){
  104.                 $qb->andWhere('s.Lieu = :lieu')
  105.                 ->setParameter('lieu'$lieu);
  106.             }
  107.             if(!empty($ref)){
  108.                 $qb->andWhere('f.Reference = :ref')
  109.                 ->setParameter('ref'$ref);
  110.             }
  111.            
  112.              $query $qb->getQuery();
  113. $results $query->getResult();
  114.             
  115.         
  116.         return($results);
  117.     }
  118. }