CommentaireRepository.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Commentaire;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Common\Persistence\ManagerRegistry;
  6. /**
  7. * @method Commentaire|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method Commentaire|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method Commentaire[] findAll()
  10. * @method Commentaire[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class CommentaireRepository extends ServiceEntityRepository
  13. {
  14. public function __construct(ManagerRegistry $registry)
  15. {
  16. parent::__construct($registry, Commentaire::class);
  17. }
  18. public function findLast ($limit = 5)
  19. {
  20. return $qb = $this->createQueryBuilder('c')
  21. ->innerJoin('c.film', 'flm')->addSelect('flm')
  22. ->innerJoin('c.user', 'usr')->addSelect('usr')
  23. ->setMaxResults($limit)
  24. ->orderBy('c.id', 'DESC')
  25. ->getQuery()
  26. ->getResult();
  27. }
  28. }