vendor/kobizo/core-bundle/src/Repository/OptionRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace Kobizo\Bundle\CoreBundle\Repository;
  3. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  4. use Doctrine\Persistence\ManagerRegistry;
  5. use Doctrine\ORM\QueryBuilder;
  6. use Kobizo\Bundle\ECommerceBundle\Entity\Store;
  7. use Kobizo\Component\Entity\Option;
  8. /**
  9.  * @method Option|null find($id, $lockMode = null, $lockVersion = null)
  10.  * @method Option|null findOneBy(array $criteria, array $orderBy = null)
  11.  * @method Option[]    findAll()
  12.  * @method Option[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class OptionRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryOption::class);
  19.     }
  20.     public function getSearchQueryBuilder(array $filters = []): QueryBuilder
  21.     {
  22.         $qb $this->createQueryBuilder('option');
  23.         if (isset($filters['term'])) {
  24.             $qb->andWhere('option.key LIKE :term OR option.label LIKE :term')
  25.                 ->setParameter('term''%'.$filters['term'].'%');
  26.         }
  27.         return $qb;
  28.     }
  29.     public function getOptionByKeyAndStoreCode(string $key, ?Store $store null): ?Option
  30.     {
  31.         $qb $this->createQueryBuilder('option')
  32.             ->where('option.key = :key')
  33.             ->setParameter('key'$key);
  34.         if ($store) {
  35.             $qb->join('option.store''store')
  36.                 ->andWhere('store = :store')
  37.                 ->setParameter('store'$store);
  38.         } else {
  39.             $qb->andWhere('option.store IS NULL');
  40.         }
  41.         return $qb
  42.             ->getQuery()
  43.             ->getOneOrNullResult();
  44.     }
  45. }