<?php

namespace App\Repository;

use App\Entity\MomentPassage;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<MomentPassage>
 *
 * @method MomentPassage|null find($id, $lockMode = null, $lockVersion = null)
 * @method MomentPassage|null findOneBy(array $criteria, array $orderBy = null)
 * @method MomentPassage[]    findAll()
 * @method MomentPassage[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class MomentPassageRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, MomentPassage::class);
    }

    /**
     * @throws ORMException
     * @throws OptimisticLockException
     */
    public function add(MomentPassage $entity, bool $flush = true): void
    {
        $this->_em->persist($entity);
        if ($flush) {
            $this->_em->flush();
        }
    }

    /**
     * @throws ORMException
     * @throws OptimisticLockException
     */
    public function remove(MomentPassage $entity, bool $flush = true): void
    {
        $this->_em->remove($entity);
        if ($flush) {
            $this->_em->flush();
        }
    }

    public function getAllIdNom()
    {
        $qb = $this->createQueryBuilder('s')->select('s.libelle as value,s.libelle as text')->orderBy('s.libelle', 'ASC');
        return $qb->getQuery()->getArrayResult();
    }

    // /**
    //  * @return MomentPassage[] Returns an array of MomentPassage objects
    //  */
    /*
    public function findByExampleField($value)
    {
        return $this->createQueryBuilder('m')
            ->andWhere('m.exampleField = :val')
            ->setParameter('val', $value)
            ->orderBy('m.id', 'ASC')
            ->setMaxResults(10)
            ->getQuery()
            ->getResult()
        ;
    }
    */

    /*
    public function findOneBySomeField($value): ?MomentPassage
    {
        return $this->createQueryBuilder('m')
            ->andWhere('m.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
    */
}
