-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticleRepository.php
37 lines (31 loc) · 1.06 KB
/
ArticleRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace App\Repository;
use App\Entity\Article;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\Tools\Pagination\Paginator;
/**
* @extends ServiceEntityRepository<Articles>
*
* @method Articles|null find($id, $lockMode = null, $lockVersion = null)
* @method Articles|null findOneBy(array $criteria, array $orderBy = null)
* @method Articles[] findAll()
* @method Articles[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ArticleRepository extends ServiceEntityRepository
{
public const PAGINATOR_PER_PAGE = 5;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Article::class);
}
public function getArticlePaginator(int $offset): Paginator
{
$query = $this->createQueryBuilder('a')
->setMaxResults(self::PAGINATOR_PER_PAGE)
->setFirstResult($offset)
->getQuery()
;
return new Paginator($query);
}
}