aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/EntryRepository.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 1335e808..a4514d9e 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -3,7 +3,6 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\Tools\Pagination\Paginator;
7use Pagerfanta\Adapter\DoctrineORMAdapter; 6use Pagerfanta\Adapter\DoctrineORMAdapter;
8use Pagerfanta\Pagerfanta; 7use Pagerfanta\Pagerfanta;
9 8
@@ -13,77 +12,66 @@ class EntryRepository extends EntityRepository
13 * Retrieves unread entries for a user. 12 * Retrieves unread entries for a user.
14 * 13 *
15 * @param int $userId 14 * @param int $userId
16 * @param int $firstResult
17 * @param int $maxResults
18 * 15 *
19 * @return Paginator 16 * @return Pagerfanta
20 */ 17 */
21 public function findUnreadByUser($userId, $firstResult, $maxResults = 12) 18 public function findUnreadByUser($userId)
22 { 19 {
23 $qb = $this->createQueryBuilder('e') 20 $qb = $this->createQueryBuilder('e')
24 ->setFirstResult($firstResult)
25 ->setMaxResults($maxResults)
26 ->leftJoin('e.user', 'u') 21 ->leftJoin('e.user', 'u')
27 ->where('e.isArchived = false') 22 ->where('e.isArchived = false')
28 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 23 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
29 ->orderBy('e.id', 'desc') 24 ->orderBy('e.id', 'desc')
30 ->getQuery(); 25 ->getQuery();
31 26
32 $paginator = new Paginator($qb); 27 $pagerAdapter = new DoctrineORMAdapter($qb);
33 28
34 return $paginator; 29 return new Pagerfanta($pagerAdapter);
35 } 30 }
36 31
37 /** 32 /**
38 * Retrieves read entries for a user. 33 * Retrieves read entries for a user.
39 * 34 *
40 * @param int $userId 35 * @param int $userId
41 * @param int $firstResult
42 * @param int $maxResults
43 * 36 *
44 * @return Paginator 37 * @return Pagerfanta
45 */ 38 */
46 public function findArchiveByUser($userId, $firstResult, $maxResults = 12) 39 public function findArchiveByUser($userId)
47 { 40 {
48 $qb = $this->createQueryBuilder('e') 41 $qb = $this->createQueryBuilder('e')
49 ->select('e') 42 ->select('e')
50 ->setFirstResult($firstResult)
51 ->setMaxResults($maxResults)
52 ->leftJoin('e.user', 'u') 43 ->leftJoin('e.user', 'u')
53 ->where('e.isArchived = true') 44 ->where('e.isArchived = true')
54 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 45 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
55 ->orderBy('e.id', 'desc') 46 ->orderBy('e.id', 'desc')
56 ->getQuery(); 47 ->getQuery();
57 48
58 $paginator = new Paginator($qb); 49 $pagerAdapter = new DoctrineORMAdapter($qb);
59 50
60 return $paginator; 51 return new Pagerfanta($pagerAdapter);
61 } 52 }
62 53
63 /** 54 /**
64 * Retrieves starred entries for a user. 55 * Retrieves starred entries for a user.
65 * 56 *
66 * @param int $userId 57 * @param int $userId
67 * @param int $firstResult
68 * @param int $maxResults
69 * 58 *
70 * @return Paginator 59 * @return Pagerfanta
71 */ 60 */
72 public function findStarredByUser($userId, $firstResult, $maxResults = 12) 61 public function findStarredByUser($userId)
73 { 62 {
63
74 $qb = $this->createQueryBuilder('e') 64 $qb = $this->createQueryBuilder('e')
75 ->select('e') 65 ->select('e')
76 ->setFirstResult($firstResult)
77 ->setMaxResults($maxResults)
78 ->leftJoin('e.user', 'u') 66 ->leftJoin('e.user', 'u')
79 ->where('e.isStarred = true') 67 ->where('e.isStarred = true')
80 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 68 ->andWhere('u.id =:userId')->setParameter('userId', $userId)
81 ->orderBy('e.id', 'desc') 69 ->orderBy('e.id', 'desc')
82 ->getQuery(); 70 ->getQuery();
83 71
84 $paginator = new Paginator($qb); 72 $pagerAdapter = new DoctrineORMAdapter($qb);
85 73
86 return $paginator; 74 return new Pagerfanta($pagerAdapter);
87 } 75 }
88 76
89 /** 77 /**