src/Repository/CongresRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Congres;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @extends ServiceEntityRepository<Congres>
  8.  *
  9.  * @method Congres|null find($id, $lockMode = null, $lockVersion = null)
  10.  * @method Congres|null findOneBy(array $criteria, array $orderBy = null)
  11.  * @method Congres[]    findAll()
  12.  * @method Congres[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class CongresRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registry, Congres::class);
  19.     }
  20.     public function add(Congres $entity, bool $flush = false): void
  21.     {
  22.         $this->getEntityManager()->persist($entity);
  23.         if ($flush) {
  24.             $this->getEntityManager()->flush();
  25.         }
  26.     }
  27.     public function remove(Congres $entity, bool $flush = false): void
  28.     {
  29.         $this->getEntityManager()->remove($entity);
  30.         if ($flush) {
  31.             $this->getEntityManager()->flush();
  32.         }
  33.     }
  34.     public function findByNamePopular(string $search = null)
  35.     {
  36.         $queryBuilder = $this->createQueryBuilder('congres')
  37.             ->where('congres.label LIKE :searchTerm')
  38.             ->orWhere('congres.type_congres LIKE :searchTerm')
  39.             ->setParameter('searchTerm', '%'.$search.'%');
  40.         return $queryBuilder
  41.             ->setMaxResults(10)
  42.             ->getQuery()
  43.             ->getResult();
  44.     }
  45.     public function findCongresAbstract()
  46.     {
  47.         $queryBuilder = $this->createQueryBuilder('e')
  48.             ->Where('e.type_congres LIKE :type')
  49.             ->andWhere('e.date_soumission >= CURRENT_DATE()')
  50.             ->setParameter('type', 'national')
  51.             ->orderBy('e.date_debut', 'DESC');
  52.         return $queryBuilder
  53.             ->setMaxResults(10)
  54.             ->getQuery()
  55.             ->getOneOrNullResult();
  56.     }
  57.     public function findDerniersCongres()
  58.     {
  59.         $queryBuilder = $this->createQueryBuilder('e')
  60.             ->Where('e.type_congres LIKE :type')
  61.             ->andWhere('e.date_debut >= CURRENT_DATE()')
  62.             ->setParameter('type', 'national')
  63.             ->orderBy('e.date_debut', 'DESC');
  64.         return $queryBuilder
  65.             ->setMaxResults(10)
  66.             ->getQuery()
  67.             ->getOneOrNullResult();
  68.     }
  69.     public function findCongresByYear()
  70.     {
  71.         $queryBuilder = $this->createQueryBuilder('e')
  72.             ->select('YEAR(e.date_debut) AS year, e.id, e.label')
  73.             ->where('YEAR(e.date_debut) <= YEAR(CURRENT_DATE())')
  74.             ->orderBy('YEAR(e.date_debut)','DESC');
  75.             return $queryBuilder
  76.             ->setMaxResults(10)
  77.             ->getQuery()
  78.             ->getResult();
  79.     }
  80.     
  81.    
  82. //    /**
  83. //     * @return Congres[] Returns an array of Congres objects
  84. //     */
  85. //    public function findByExampleField($value): array
  86. //    {
  87. //        return $this->createQueryBuilder('c')
  88. //            ->andWhere('c.exampleField = :val')
  89. //            ->setParameter('val', $value)
  90. //            ->orderBy('c.id', 'ASC')
  91. //            ->setMaxResults(10)
  92. //            ->getQuery()
  93. //            ->getResult()
  94. //        ;
  95. //    }
  96. public function findAllDesc()
  97.     {
  98.         $queryBuilder = $this->createQueryBuilder('congres')
  99.         ->orderBy('congres.date_debut','DESC')
  100.             ;
  101.         return $queryBuilder
  102.             ->setMaxResults(1000)
  103.             ->getQuery()
  104.             ->getResult();
  105.     }
  106.    public function findOneByMaxDateDeb()
  107.    {
  108.        return $this->createQueryBuilder('c')
  109.             ->select('MAX(c.date_debut)')
  110.             ->where('c.type_congres LIKE :type')
  111.             ->setParameter('type','national')
  112.            ->getQuery()
  113.            ->getOneOrNullResult()
  114.        ;
  115.    }
  116. }