<?php
namespace App\Repository;
use App\Entity\Video;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\Tools\Pagination\Paginator;
/**
* @method Video|null find($id, $lockMode = null, $lockVersion = null)
* @method Video|null findOneBy(array $criteria, array $orderBy = null)
* @method Video[] findAll()
* @method Video[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class VideoRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Video::class);
}
// /**
// * @return Video[] Returns an array of Video objects
// */
public function findByTitle($q)
{
//$order = in_array($order,['ASC','DESC'])? $order : 'ASC';
return $this->createQueryBuilder('v')
->andWhere('v.libelle LIKE :q')
->setParameter('q', '%' . $q . '%')
//->setMaxResults(2)
->getQuery()
->getResult();
}
public function findByVA($status)
{
return $this->createQueryBuilder('v')
->andWhere('v.status = :val ')
->andWhere('v.une = true ')
->setParameter('val', $status)
//->setParameter('val1', $premium)
->orderBy('v.id', 'DESC')
->setMaxResults(2)
->getQuery()
->getResult()
;
}
public function findBylist($status, $q)
{
return $this->createQueryBuilder('v')
->andWhere('v.status = :val AND v.libelle LIKE :valq OR v.description LIKE :vald')
->setParameter('val', $status)
->setParameter('valq', '%'. $q .'%')
->setParameter('vald', '%'. $q .'%')
//->setParameter('val1', $premium)
->orderBy('v.id', 'DESC')
//->setMaxResults(5)
->getQuery()
->getResult()
;
}
// requete pour la pagination
public function findWithPage($status, $q, $page = 1, $limit = 30)
{
return new Paginator( $this->createQueryBuilder('v')
->andWhere('v.status = :val AND v.libelle like :valq OR v.description like :vald')
->setParameter('val', $status)
->setParameter('valq', '%'.$q.'%')
->setParameter('vald', '%'.$q.'%')
->orderBy('v.id', 'DESC')
->getQuery()
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit))
;
}
/*$req->innerJoin('e.categorie','c')
->andWhere('c.id = :type')
->setParameter('type',$type);*/
public function findBycateg($status,$cat)
{
return $this->createQueryBuilder('v')
->andWhere('v.status = :val AND v.categorie = :val1')
->setParameter('val', $status)
->setParameter('val1', $cat)
->orderBy('v.id', 'DESC')
//->setMaxResults(1)
->getQuery()
->getResult()
;
}
public function findBycategA($status,$categorie)
{
return $this->createQueryBuilder('v')
->andWhere('v.status = :val AND v.categorie = :val1')
->andWhere(' v.categorie = :val1')
->setParameter('val', $status)
->setParameter('val1', $categorie)
->orderBy('v.id', 'DESC')
->setMaxResults(1)
->getQuery()
->getResult()
;
}
public function findBycategshow($status,$id,$categorie)
{
return $this->createQueryBuilder('v')
->andWhere('v.status = :val ')
->andWhere('v.id = :val1 ')
->andWhere(' v.categorie = :vl2')
->setParameter('val', $status)
->setParameter('val1', $id)
->setParameter('val2', $categorie)
//->orderBy('v.id', 'DESC')
// ->setMaxResults(1)
->getQuery()
->getResult()
;
}
public function findByRecente($status)
{
return $this->createQueryBuilder('v')
->andWhere('v.status = :val ')
->setParameter('val', $status)
//->setParameter('val1', $premium)
->orderBy('v.id', 'DESC')
->setMaxResults(1)
->getQuery()
->getResult()
;
}
/*
public function findOneBySomeField($value): ?Video
{
return $this->createQueryBuilder('v')
->andWhere('v.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}