<?php

namespace App\Repository;

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

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

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

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

    public function getIdLibelle()
    {
        $qb = $this->createQueryBuilder('t')
            ->select('t.id, t.libelle_court ')
            ->orderBy('t.libelle_court', 'ASC');
        ;
        return $qb->getQuery()->getArrayResult();
    }
}
