src/Repository/VideoRepository.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Video;
  4. use DateTime;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\ORM\QueryBuilder;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. /**
  9.  * @method Video|null find($id, $lockMode = null, $lockVersion = null)
  10.  * @method Video|null findOneBy(array $criteria, array $orderBy = null)
  11.  * @method Video[]    findAll()
  12.  * @method Video[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13.  */
  14. class VideoRepository extends ServiceEntityRepository
  15. {
  16.     public function __construct(ManagerRegistry $registry)
  17.     {
  18.         parent::__construct($registryVideo::class);
  19.     }
  20.     public function getEntityManager()
  21.     {
  22.         return parent::getEntityManager();
  23.     }
  24.     public function save(Video $video)
  25.     {
  26.         $this->_em->persist($video);
  27.         $this->_em->flush();
  28.     }
  29.     public function delete(Video $video)
  30.     {
  31.         $this->_em->remove($video);
  32.         $this->_em->flush();
  33.     }
  34.     public function getVideos(?string $filter): QueryBuilder
  35.     {
  36.         $qb $this->createQueryBuilder('v');
  37.         $qb->andWhere($qb->expr()->like('v.url'':filter'));
  38.         $qb->setParameter('filter''%'.$filter.'%');
  39.         return $qb;
  40.     }
  41.     public function getNumberOfVideosPerDay($day$month$year)
  42.     {
  43.         $day str_pad($day2'0'STR_PAD_LEFT);
  44.         $month str_pad($month2'0'STR_PAD_LEFT);
  45.         $str '%' $year.'-'.$month.'-'.$day '%';
  46.         $qb $this->createQueryBuilder('v')
  47.             ->select('COUNT(DISTINCT v.id) AS count')
  48.             ->where('v.createdAt LIKE :str');
  49.         $qb->setParameter('str'$str);
  50.         return $qb->getQuery()->getResult();
  51.     }
  52.     public function getNumberOfVideosPerMonth(int $yearint $month)
  53.     {
  54.         $str '\'' $year.'-'.$month.'-01' '\' and \'' $year.'-'.$month.'-31' '\'';
  55.         $qb $this->createQueryBuilder('v')
  56.             ->select('COUNT(DISTINCT v.id) AS count')
  57.             ->where('v.createdAt between ' $str);
  58.         return $qb->getQuery()->getResult();
  59.     }
  60.     public function getYearsOfVideos(): array
  61.     {
  62.         $qb $this->createQueryBuilder('v')
  63.             ->select('DISTINCT(YEAR(v.createdAt)) AS y');
  64.         return $qb->getQuery()->getArrayResult();
  65.     }
  66.     public function getStorageOfVideosPerMonth(string $yearint $month)
  67.     {
  68.         $str '\'' $year.'-'.$month.'-01' '\' and \'' $year.'-'.$month.'-31' '\'';
  69.         $qb $this->createQueryBuilder('v')
  70.             ->select('SUM(v.size) as total')
  71.             ->where('v.createdAt between ' $str);
  72.         return $qb->getQuery()->getResult();
  73.     }
  74.     /**
  75.      * @param int $int
  76.      * @return Video[]
  77.      */
  78.     public function findNotProcessedForPastDays(int $int): array
  79.     {
  80.         $query $this->_em->createQuery("SELECT v FROM App\Entity\Video v WHERE v.createdAt > DATE_SUB(CURRENT_DATE(), ".$int.", 'DAY') and v.filename LIKE 'stream-%' and v.postprocessed = 0 and v.size > 4500000");
  81.         return $query->getResult();
  82.     }
  83.     /**
  84.      * @param int $int
  85.      * @return Video[]
  86.      */
  87.     public function findNotProcessedOnlyForPastDays(int $int): array
  88.     {
  89.         $query $this->_em->createQuery("SELECT v FROM App\Entity\Video v WHERE v.createdAt > DATE_SUB(CURRENT_DATE(), ".$int.", 'DAY') and v.filename LIKE 'stream-%' and v.chromeBugReady = 0");
  90.         return $query->getResult();
  91.     }
  92.     public function getAllUploadVideos(): array
  93.     {
  94.         $qb $this->createQueryBuilder('v')
  95.             ->where('v.filename LIKE :param')
  96.             ->andWhere('v.createdAt > :date')
  97.             ->setParameter('param''upload_%')
  98.             ->setParameter('date', new DateTime('2021-03-16 06:00:00'))
  99.             ->orderBy('v.createdAt''desc');
  100.         return $qb->getQuery()->getResult();
  101.     }
  102.     public function getDeviceTypeData()
  103.     {
  104.         $qb $this->createQueryBuilder('v')
  105.             ->select("SUM(case when v.deviceType = 'mobile' then 1 else 0 end) as mobile,
  106.             SUM(case when v.deviceType = 'desktop' then 1 else 0 end) as desktop");
  107.         return $qb->getQuery()->getResult();
  108.     }
  109.     public function getOsData()
  110.     {
  111.         $qb $this->createQueryBuilder('v')
  112.             ->select('v.os, count(v) as count')
  113.             ->groupBy('v.os')
  114.             ->having('count(v) > 0');
  115.         return $qb->getQuery()->getResult();
  116.     }
  117.     public function getBrowserData()
  118.     {
  119.         $qb $this->createQueryBuilder('v')
  120.             ->select('v.browser, count(v) as count')
  121.             ->groupBy('v.browser')
  122.             ->having('count(v) > 0');
  123.         return $qb->getQuery()->getResult();
  124.     }
  125. }