<?php
namespace App\Repository;
use App\data\SearchAlbumPhoto;
use App\Entity\PhotoGalery;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Knp\Component\Pager\Pagination\PaginationInterface;
use Knp\Component\Pager\PaginatorInterface;
/**
* @extends ServiceEntityRepository<PhotoGalery>
*
* @method PhotoGalery|null find($id, $lockMode = null, $lockVersion = null)
* @method PhotoGalery|null findOneBy(array $criteria, array $orderBy = null)
* @method PhotoGalery[] findAll()
* @method PhotoGalery[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PhotoGaleryRepository extends ServiceEntityRepository
{
/**
* @var PaginatorInterface
*/
private $paginator;
public function __construct(ManagerRegistry $registry, PaginatorInterface $paginator)
{
parent::__construct($registry, PhotoGalery::class);
$this->paginator = $paginator;
}
/**
* récupère les produits en lien avec une recherche
* @return PaginationInterface
*/
public function findSearch(SearchAlbumPhoto $search) : PaginationInterface
{
$query = $this
->createQueryBuilder('pg')
->select('a', 'pg')
->join('pg.album','a')
;
if (!empty($search->albumPhoto)){
$query = $query
->andWhere('a.id IN (:albumPhoto)')
->setParameter('albumPhoto', $search->albumPhoto);
}
$query = $query->getQuery()->getResult() ;
return $this->paginator->paginate(
$query,
$search->page,
9
);
}
// /**
// * @return PhotoGalery[] Returns an array of PhotoGalery objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('p.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?PhotoGalery
// {
// return $this->createQueryBuilder('p')
// ->andWhere('p.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}