src/Repository/ExclusionsVideoRepository.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Company;
  4. use App\Entity\ExclusionsVideo;
  5. use App\Entity\Video;
  6. use App\Repository\Model\IExclusionRepository;
  7. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  8. use Doctrine\ORM\NonUniqueResultException;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. /**
  11.  * @method ExclusionsVideo|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method ExclusionsVideo|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method ExclusionsVideo[]    findAll()
  14.  * @method ExclusionsVideo[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class ExclusionsVideoRepository extends ServiceEntityRepository implements IExclusionRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registryExclusionsVideo::class);
  21.     }
  22.     /**
  23.      * Checks if an exclusion for said company exists
  24.      * @param Company $company
  25.      * @param Video $video
  26.      * @return bool
  27.      */
  28.     public function isExclusion(Company $companyVideo $video): bool
  29.     {
  30.         try {
  31.             $result $this->createQueryBuilder('e')
  32.                 ->andWhere('e.company = :company')
  33.                 ->andWhere('e.video = :video')
  34.                 ->setParameter('company'$company)
  35.                 ->setParameter('video'$video)
  36.                 ->getQuery()
  37.                 ->getOneOrNullResult();
  38.         } catch (NonUniqueResultException $e) {
  39.             $result null;
  40.         }
  41.         return ($result instanceof ExclusionsVideo);
  42.     }
  43.     /**
  44.      * @param Company $company
  45.      * @return int|mixed|string|null
  46.      */
  47.     public function getExcludedIds(Company $company): array
  48.     {
  49.         $result $this->createQueryBuilder('e')
  50.             ->select('e')
  51.             ->andWhere('e.company = :company')
  52.             ->setParameter('company'$company)
  53.             ->getQuery()
  54.             ->getResult();
  55.         foreach ($result as $key=>$item){
  56.             $result[$key] = $item->getVideo()->getId();
  57.         }
  58.         return $result;
  59.     }
  60. }