src/Repository/PhotoGaleryRepository.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\data\SearchAlbumPhoto;
  4. use App\Entity\PhotoGalery;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Knp\Component\Pager\Pagination\PaginationInterface;
  8. use Knp\Component\Pager\PaginatorInterface;
  9. /**
  10.  * @extends ServiceEntityRepository<PhotoGalery>
  11.  *
  12.  * @method PhotoGalery|null find($id, $lockMode = null, $lockVersion = null)
  13.  * @method PhotoGalery|null findOneBy(array $criteria, array $orderBy = null)
  14.  * @method PhotoGalery[]    findAll()
  15.  * @method PhotoGalery[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  16.  */
  17. class PhotoGaleryRepository extends ServiceEntityRepository
  18. {
  19.     /**
  20.      * @var PaginatorInterface
  21.      */
  22.     private $paginator;
  23.     public function __construct(ManagerRegistry $registryPaginatorInterface $paginator)
  24.     {
  25.         parent::__construct($registryPhotoGalery::class);
  26.         $this->paginator $paginator;
  27.     }
  28.     /**
  29.      * récupère les produits en lien avec une recherche
  30.      * @return PaginationInterface
  31.      */
  32.     public function findSearch(SearchAlbumPhoto $search) : PaginationInterface
  33.     {
  34.         $query $this
  35.             ->createQueryBuilder('pg')
  36.             ->select('a''pg')
  37.             ->join('pg.album','a')
  38.         ;
  39.         if (!empty($search->albumPhoto)){
  40.             $query $query
  41.                 ->andWhere('a.id IN (:albumPhoto)')
  42.                 ->setParameter('albumPhoto'$search->albumPhoto);
  43.         }
  44.         $query $query->getQuery()->getResult() ;
  45.         return $this->paginator->paginate(
  46.             $query,
  47.             $search->page,
  48.             9
  49.         );
  50.     }
  51. //    /**
  52. //     * @return PhotoGalery[] Returns an array of PhotoGalery objects
  53. //     */
  54. //    public function findByExampleField($value): array
  55. //    {
  56. //        return $this->createQueryBuilder('p')
  57. //            ->andWhere('p.exampleField = :val')
  58. //            ->setParameter('val', $value)
  59. //            ->orderBy('p.id', 'ASC')
  60. //            ->setMaxResults(10)
  61. //            ->getQuery()
  62. //            ->getResult()
  63. //        ;
  64. //    }
  65. //    public function findOneBySomeField($value): ?PhotoGalery
  66. //    {
  67. //        return $this->createQueryBuilder('p')
  68. //            ->andWhere('p.exampleField = :val')
  69. //            ->setParameter('val', $value)
  70. //            ->getQuery()
  71. //            ->getOneOrNullResult()
  72. //        ;
  73. //    }
  74. }