aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/EntryRepository.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-08-20 20:10:06 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-08-20 20:39:22 +0200
commit0ab7404f93670ed161b67528c1a61c5bfa92d42b (patch)
tree591b52d4c035b75ea59ee597101e998ba0f3e802 /src/Wallabag/CoreBundle/Repository/EntryRepository.php
parent4fcb7eaf139a4d2cbd0f54574e6c51a0fe852ef1 (diff)
downloadwallabag-0ab7404f93670ed161b67528c1a61c5bfa92d42b.tar.gz
wallabag-0ab7404f93670ed161b67528c1a61c5bfa92d42b.tar.zst
wallabag-0ab7404f93670ed161b67528c1a61c5bfa92d42b.zip
Refactorize the way to retrieve entries
One place to retrieve entries in Entry & Rss controller. More simple and easy to maintain.
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index f885ee94..5538ae82 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -9,19 +9,34 @@ use Pagerfanta\Pagerfanta;
9class EntryRepository extends EntityRepository 9class EntryRepository extends EntityRepository
10{ 10{
11 /** 11 /**
12 * Retrieves unread entries for a user. 12 * Return a query builder to used by other getBuilderFor* method.
13 * 13 *
14 * @param int $userId 14 * @param int $userId
15 * 15 *
16 * @return QueryBuilder 16 * @return QueryBuilder
17 */ 17 */
18 public function findUnreadByUser($userId) 18 private function getBuilderByUser($userId)
19 { 19 {
20 return $this->createQueryBuilder('e') 20 return $this->createQueryBuilder('e')
21 ->leftJoin('e.user', 'u') 21 ->leftJoin('e.user', 'u')
22 ->where('e.isArchived = false') 22 ->andWhere('u.id = :userId')->setParameter('userId', $userId)
23 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 23 ->orderBy('e.id', 'desc')
24 ->orderBy('e.id', 'desc'); 24 ;
25 }
26
27 /**
28 * Retrieves unread entries for a user.
29 *
30 * @param int $userId
31 *
32 * @return QueryBuilder
33 */
34 public function getBuilderForUnreadByUser($userId)
35 {
36 return $this
37 ->getBuilderByUser($userId)
38 ->andWhere('e.isArchived = false')
39 ;
25 } 40 }
26 41
27 /** 42 /**
@@ -31,13 +46,12 @@ class EntryRepository extends EntityRepository
31 * 46 *
32 * @return QueryBuilder 47 * @return QueryBuilder
33 */ 48 */
34 public function findArchiveByUser($userId) 49 public function getBuilderForArchiveByUser($userId)
35 { 50 {
36 return $this->createQueryBuilder('e') 51 return $this
37 ->leftJoin('e.user', 'u') 52 ->getBuilderByUser($userId)
38 ->where('e.isArchived = true') 53 ->andWhere('e.isArchived = true')
39 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 54 ;
40 ->orderBy('e.id', 'desc');
41 } 55 }
42 56
43 /** 57 /**
@@ -47,13 +61,12 @@ class EntryRepository extends EntityRepository
47 * 61 *
48 * @return QueryBuilder 62 * @return QueryBuilder
49 */ 63 */
50 public function findStarredByUser($userId) 64 public function getBuilderForStarredByUser($userId)
51 { 65 {
52 return $this->createQueryBuilder('e') 66 return $this
53 ->leftJoin('e.user', 'u') 67 ->getBuilderByUser($userId)
54 ->where('e.isStarred = true') 68 ->andWhere('e.isStarred = true')
55 ->andWhere('u.id =:userId')->setParameter('userId', $userId) 69 ;
56 ->orderBy('e.id', 'desc');
57 } 70 }
58 71
59 /** 72 /**