src/Repository/Admin/ArticleRepository.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Repository\Admin;
  3. use App\Entity\Admin\Article;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\ORM\Query;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. /**
  8.  * @method Article|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method Article|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method Article[]    findAll()
  11.  * @method Article[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class ArticleRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryArticle::class);
  18.     }
  19.     public function findAllByDateDesc(): Query
  20.     {
  21.         return $this->createQueryBuilder('a')
  22.             ->orderBy('a.dateAjoutAt''DESC')
  23.             ->getQuery()
  24.             ;
  25.     }
  26.     public function findByThemeOrderedByDateDesc($theme): Query
  27.     {
  28.         return $this->createQueryBuilder('a')
  29.             ->andWhere('a.theme = :theme')
  30.             ->setParameter('theme'$theme)
  31.             ->orderBy('a.dateAjoutAt''DESC')
  32.             ->getQuery()
  33.             ;
  34.     }
  35.     public function findArticlesForHome()
  36.     {
  37.         $qb $this->createQueryBuilder('a');
  38.         return $qb
  39.             ->select('a')
  40.             ->andWhere('a.pourAccueil = 1')
  41.             ->getQuery()
  42.             ->getResult()
  43.             ;
  44.     }
  45.     public function findLastArticle()
  46.     {
  47.         return $this->createQueryBuilder('a')
  48.             ->orderBy('a.id''DESC')
  49.             ->setMaxResults(1)
  50.             ->getQuery()
  51.             ->getResult()
  52.             ;
  53.     }
  54.     public function find5LastArticles()
  55.     {
  56.         return $this->createQueryBuilder('a')
  57.             ->orderBy('a.id''DESC')
  58.             ->setMaxResults(5)
  59.             ->getQuery()
  60.             ->getResult()
  61.             ;
  62.     }
  63.     public function countArticles()
  64.     {
  65.         $qb $this->createQueryBuilder('a');
  66.         return $qb
  67.             ->select('count(a.id)' )
  68.             ->getQuery()
  69.             ->getSingleScalarResult();
  70.     }
  71.     // /**
  72.     //  * @return Article[] Returns an array of Article objects
  73.     //  */
  74.     /*
  75.     public function findByExampleField($value)
  76.     {
  77.         return $this->createQueryBuilder('a')
  78.             ->andWhere('a.exampleField = :val')
  79.             ->setParameter('val', $value)
  80.             ->orderBy('a.id', 'ASC')
  81.             ->setMaxResults(10)
  82.             ->getQuery()
  83.             ->getResult()
  84.         ;
  85.     }
  86.     */
  87. }