<?php
namespace App\Repository;
use App\Entity\Congres;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Congres>
*
* @method Congres|null find($id, $lockMode = null, $lockVersion = null)
* @method Congres|null findOneBy(array $criteria, array $orderBy = null)
* @method Congres[] findAll()
* @method Congres[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CongresRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Congres::class);
}
public function add(Congres $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Congres $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function findByNamePopular(string $search = null)
{
$queryBuilder = $this->createQueryBuilder('congres')
->where('congres.label LIKE :searchTerm')
->orWhere('congres.type_congres LIKE :searchTerm')
->setParameter('searchTerm', '%'.$search.'%');
return $queryBuilder
->setMaxResults(10)
->getQuery()
->getResult();
}
public function findCongresAbstract()
{
$queryBuilder = $this->createQueryBuilder('e')
->Where('e.type_congres LIKE :type')
->andWhere('e.date_soumission >= CURRENT_DATE()')
->setParameter('type', 'national')
->orderBy('e.date_debut', 'DESC');
return $queryBuilder
->setMaxResults(10)
->getQuery()
->getOneOrNullResult();
}
public function findDerniersCongres()
{
$queryBuilder = $this->createQueryBuilder('e')
->Where('e.type_congres LIKE :type')
->andWhere('e.date_debut >= CURRENT_DATE()')
->setParameter('type', 'national')
->orderBy('e.date_debut', 'DESC');
return $queryBuilder
->setMaxResults(10)
->getQuery()
->getOneOrNullResult();
}
public function findCongresByYear()
{
$queryBuilder = $this->createQueryBuilder('e')
->select('YEAR(e.date_debut) AS year, e.id, e.label')
->where('YEAR(e.date_debut) <= YEAR(CURRENT_DATE())')
->orderBy('YEAR(e.date_debut)','DESC');
return $queryBuilder
->setMaxResults(10)
->getQuery()
->getResult();
}
// /**
// * @return Congres[] Returns an array of Congres objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('c')
// ->andWhere('c.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('c.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
public function findAllDesc()
{
$queryBuilder = $this->createQueryBuilder('congres')
->orderBy('congres.date_debut','DESC')
;
return $queryBuilder
->setMaxResults(1000)
->getQuery()
->getResult();
}
public function findOneByMaxDateDeb()
{
return $this->createQueryBuilder('c')
->select('MAX(c.date_debut)')
->where('c.type_congres LIKE :type')
->setParameter('type','national')
->getQuery()
->getOneOrNullResult()
;
}
}