src/Repository/ActualiteOnpcRepository.php line 82

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\ActualiteOnpc as Actualite;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @extends ServiceEntityRepository<Actualite>
  8.  *
  9.  * @method Actualite|null find($id, $lockMode = null, $lockVersion = null)
  10.  * @method Actualite|null findOneBy(array $criteria, array $orderBy = null)
  11.  * @method Actualite[]    findAll()
  12.  * @method Actualite[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class ActualiteOnpcRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryActualite::class);
  19.     }
  20.     public function add(Actualite $entitybool $flush false): void
  21.     {
  22.         $this->getEntityManager()->persist($entity);
  23.         if ($flush) {
  24.             $this->getEntityManager()->flush();
  25.         }
  26.     }
  27.     public function remove(Actualite $entitybool $flush false): void
  28.     {
  29.         $this->getEntityManager()->remove($entity);
  30.         if ($flush) {
  31.             $this->getEntityManager()->flush();
  32.         }
  33.     }
  34. //    /**
  35. //     * @return Actualite[] Returns an array of Actualite objects
  36. //     */
  37. //    public function findByExampleField($value): array
  38. //    {
  39. //        return $this->createQueryBuilder('v')
  40. //            ->andWhere('v.exampleField = :val')
  41. //            ->setParameter('val', $value)
  42. //            ->orderBy('v.id', 'ASC')
  43. //            ->setMaxResults(10)
  44. //            ->getQuery()
  45. //            ->getResult()
  46. //        ;
  47. //    }
  48. //    public function findOneBySomeField($value): ?Actualite
  49. //    {
  50. //        return $this->createQueryBuilder('v')
  51. //            ->andWhere('v.exampleField = :val')
  52. //            ->setParameter('val', $value)
  53. //            ->getQuery()
  54. //            ->getOneOrNullResult()
  55. //        ;
  56. //    }
  57.    /**
  58.     * @return Actualite[] Returns an array of Actualite objects
  59.     */
  60.    public function findByTag($tag$excludeId null): array
  61.    {
  62.        $qb $this->createQueryBuilder('v')
  63.            ->andWhere('v.tag LIKE :val')
  64.            ->setParameter('val''%' $tag '%')
  65.            ->orderBy('v.createdAt''DESC');
  66.        if ($excludeId !== null) {
  67.            $qb->andWhere('v.id != :excludeId')
  68.                ->setParameter('excludeId'$excludeId);
  69.        }
  70.        return $qb->getQuery()->getResult();
  71.    }
  72. }