src/Service/Content/VideoService.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Service\Content;
  3. use App\Entity\Category;
  4. use App\Entity\ContentVideo;
  5. use App\Entity\Member;
  6. use App\Repository\AbstractRepository;
  7. use App\Repository\ContentVideoRepository;
  8. use App\Response\EntityUpdated;
  9. use Doctrine\ORM\Tools\Pagination\Paginator;
  10. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  11. class VideoService extends AbstractContentService
  12. {
  13.     /**
  14.      * @var ContentVideoRepository
  15.      */
  16.     protected $repo;
  17.     /**
  18.      * VideoService constructor.
  19.      */
  20.     public function __construct(ContentVideoRepository $repoEventDispatcherInterface $dispatcher)
  21.     {
  22.         parent::__construct($repo$dispatcher);
  23.     }
  24.     /**
  25.      * @return ContentVideoRepository
  26.      */
  27.     public function getRepository(): AbstractRepository
  28.     {
  29.         return parent::getRepository();
  30.     }
  31.     public function getVideosByMember(Member $memberint $page, array $statusesint $limit): Paginator
  32.     {
  33.         return $this->repo->getVideosByMember($member$page$statuses$limit);
  34.     }
  35.     /**
  36.      * @throws \Doctrine\ORM\ORMException
  37.      * @throws \Doctrine\ORM\OptimisticLockException
  38.      */
  39.     public function storeContentVideo(ContentVideo $video): EntityUpdated
  40.     {
  41.         $this->storeEntity($video);
  42.         return new EntityUpdated(true$video->getId());
  43.     }
  44.     /**
  45.      * @throws \Doctrine\ORM\NonUniqueResultException
  46.      */
  47.     public function findBySlug(string $slugbool $ignoreContentStatus false): ?ContentVideo
  48.     {
  49.         if ($ignoreContentStatus) {
  50.             return $this->getRepository()->findOneBy(['slug' => $slug]);
  51.         }
  52.         $qb $this->getRepository()->getBaseVideoQueryBuilder([]);
  53.         $qb->andWhere('v.slug = :slug');
  54.         $qb->setParameter(':slug'$slug);
  55.         return $qb->getQuery()->getOneOrNullResult();
  56.     }
  57.     public function getActiveVideosByCategory(Category $categoryint $pageint $limit): Paginator
  58.     {
  59.         $repo $this->getRepository();
  60.         $qb $repo->getActiveVideosByCategoryQueryBuilder($category);
  61.         $qb->setMaxResults($limit);
  62.         $qb->setFirstResult($page $limit $limit);
  63.         return new Paginator($qb->getQuery());
  64.     }
  65.     /**
  66.      * @return Paginator
  67.      */
  68.     public function getFreshVideos(int $page$perPage)
  69.     {
  70.         return $this->getRepository()->getFreshVideos($page$perPage);
  71.     }
  72.     /**
  73.      * @return ContentVideo[]
  74.      */
  75.     public function getFreshVideosArray(int $page$perPage): array
  76.     {
  77.         return $this->getRepository()->getFreshVideosArray($page$perPage);
  78.     }
  79. }