X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=5538ae82b40081101d2482271a7b0b290039bfbf;hb=e1779760999f676cb7a74a201bc2a389959702d4;hp=a8c138a97670b1e3f830060d58d28a50bfd2b4e7;hpb=1a93ee423b072ec3bcb0c437cbf9b488bdea245c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index a8c138a9..5538ae82 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -3,91 +3,74 @@ 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 + * Return a query builder to used by other getBuilderFor* method. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return QueryBuilder */ - public function findUnreadByUser($userId, $firstResult, $maxResults = 12) + private function getBuilderByUser($userId) { - $qb = $this->createQueryBuilder('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) + return $this->createQueryBuilder('e') ->leftJoin('e.user', 'u') - ->where('e.isArchived = false') - ->andWhere('u.id =:userId')->setParameter('userId', $userId) + ->andWhere('u.id = :userId')->setParameter('userId', $userId) ->orderBy('e.id', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; + ; } /** - * Retrieves read entries for a user + * Retrieves unread entries for a user. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return QueryBuilder */ - public function findArchiveByUser($userId, $firstResult, $maxResults = 12) + public function getBuilderForUnreadByUser($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.id', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; + return $this + ->getBuilderByUser($userId) + ->andWhere('e.isArchived = false') + ; } /** - * Retrieves starred entries for a user + * Retrieves read entries for a user. * * @param int $userId - * @param int $firstResult - * @param int $maxResults * - * @return Paginator + * @return QueryBuilder */ - public function findStarredByUser($userId, $firstResult, $maxResults = 12) + public function getBuilderForArchiveByUser($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.id', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); + return $this + ->getBuilderByUser($userId) + ->andWhere('e.isArchived = true') + ; + } - return $paginator; + /** + * Retrieves starred entries for a user. + * + * @param int $userId + * + * @return QueryBuilder + */ + public function getBuilderForStarredByUser($userId) + { + return $this + ->getBuilderByUser($userId) + ->andWhere('e.isStarred = true') + ; } /** - * Find Entries + * Find Entries. * * @param int $userId * @param bool $isArchived