X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=a4514d9e791c0ffd04a39df8b4e45d2377e377d2;hb=7e63b892f9682e62f6758bb51c6912499f5bd8d1;hp=04fe6aa345137f78a0ef7934ae90782550c955a9;hpb=0ca374e6a1698926b08635d6a276ff3bf91c76a5;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 04fe6aa3..a4514d9e 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -3,89 +3,79 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\Tools\Pagination\Paginator; +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Pagerfanta; class EntryRepository extends EntityRepository { /** - * Retrieves unread entries for a user + * Retrieves unread entries for a user. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return Pagerfanta */ - public function findUnreadByUser($userId, $firstResult, $maxResults = 12) + public function findUnreadByUser($userId) { $qb = $this->createQueryBuilder('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) ->leftJoin('e.user', 'u') ->where('e.isArchived = false') ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->orderBy('e.createdAt', 'desc') + ->orderBy('e.id', 'desc') ->getQuery(); - $paginator = new Paginator($qb); + $pagerAdapter = new DoctrineORMAdapter($qb); - return $paginator; + return new Pagerfanta($pagerAdapter); } /** - * Retrieves read entries for a user + * Retrieves read entries for a user. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return Pagerfanta */ - public function findArchiveByUser($userId, $firstResult, $maxResults = 12) + public function findArchiveByUser($userId) { $qb = $this->createQueryBuilder('e') ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) ->leftJoin('e.user', 'u') ->where('e.isArchived = true') ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->orderBy('e.createdAt', 'desc') + ->orderBy('e.id', 'desc') ->getQuery(); - $paginator = new Paginator($qb); + $pagerAdapter = new DoctrineORMAdapter($qb); - return $paginator; + return new Pagerfanta($pagerAdapter); } /** - * Retrieves starred entries for a user + * Retrieves starred entries for a user. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return Pagerfanta */ - public function findStarredByUser($userId, $firstResult, $maxResults = 12) + public function findStarredByUser($userId) { + $qb = $this->createQueryBuilder('e') ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) ->leftJoin('e.user', 'u') ->where('e.isStarred = true') ->andWhere('u.id =:userId')->setParameter('userId', $userId) - ->orderBy('e.createdAt', 'desc') + ->orderBy('e.id', 'desc') ->getQuery(); - $paginator = new Paginator($qb); + $pagerAdapter = new DoctrineORMAdapter($qb); - return $paginator; + return new Pagerfanta($pagerAdapter); } /** - * Find Entries + * Find Entries. * * @param int $userId * @param bool $isArchived @@ -109,14 +99,14 @@ class EntryRepository extends EntityRepository } if ('created' === $sort) { - $qb->orderBy('e.createdAt', $order); + $qb->orderBy('e.id', $order); } elseif ('updated' === $sort) { $qb->orderBy('e.updatedAt', $order); } - return $qb - ->getQuery() - ->getResult(); + $pagerAdapter = new DoctrineORMAdapter($qb); + + return new Pagerfanta($pagerAdapter); } /**