diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/EntryRepository.php | 61 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 17 |
2 files changed, 61 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index f885ee94..e764e8f7 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php | |||
@@ -9,19 +9,48 @@ use Pagerfanta\Pagerfanta; | |||
9 | class EntryRepository extends EntityRepository | 9 | class 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 all entries for a user. | ||
29 | * | ||
30 | * @param int $userId | ||
31 | * | ||
32 | * @return QueryBuilder | ||
33 | */ | ||
34 | public function getBuilderForAllByUser($userId) | ||
35 | { | ||
36 | return $this | ||
37 | ->getBuilderByUser($userId) | ||
38 | ; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * Retrieves unread entries for a user. | ||
43 | * | ||
44 | * @param int $userId | ||
45 | * | ||
46 | * @return QueryBuilder | ||
47 | */ | ||
48 | public function getBuilderForUnreadByUser($userId) | ||
49 | { | ||
50 | return $this | ||
51 | ->getBuilderByUser($userId) | ||
52 | ->andWhere('e.isArchived = false') | ||
53 | ; | ||
25 | } | 54 | } |
26 | 55 | ||
27 | /** | 56 | /** |
@@ -31,13 +60,12 @@ class EntryRepository extends EntityRepository | |||
31 | * | 60 | * |
32 | * @return QueryBuilder | 61 | * @return QueryBuilder |
33 | */ | 62 | */ |
34 | public function findArchiveByUser($userId) | 63 | public function getBuilderForArchiveByUser($userId) |
35 | { | 64 | { |
36 | return $this->createQueryBuilder('e') | 65 | return $this |
37 | ->leftJoin('e.user', 'u') | 66 | ->getBuilderByUser($userId) |
38 | ->where('e.isArchived = true') | 67 | ->andWhere('e.isArchived = true') |
39 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) | 68 | ; |
40 | ->orderBy('e.id', 'desc'); | ||
41 | } | 69 | } |
42 | 70 | ||
43 | /** | 71 | /** |
@@ -47,13 +75,12 @@ class EntryRepository extends EntityRepository | |||
47 | * | 75 | * |
48 | * @return QueryBuilder | 76 | * @return QueryBuilder |
49 | */ | 77 | */ |
50 | public function findStarredByUser($userId) | 78 | public function getBuilderForStarredByUser($userId) |
51 | { | 79 | { |
52 | return $this->createQueryBuilder('e') | 80 | return $this |
53 | ->leftJoin('e.user', 'u') | 81 | ->getBuilderByUser($userId) |
54 | ->where('e.isStarred = true') | 82 | ->andWhere('e.isStarred = true') |
55 | ->andWhere('u.id =:userId')->setParameter('userId', $userId) | 83 | ; |
56 | ->orderBy('e.id', 'desc'); | ||
57 | } | 84 | } |
58 | 85 | ||
59 | /** | 86 | /** |
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 9c409607..ac3145a1 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -24,4 +24,21 @@ class TagRepository extends EntityRepository | |||
24 | 24 | ||
25 | return new Pagerfanta($pagerAdapter); | 25 | return new Pagerfanta($pagerAdapter); |
26 | } | 26 | } |
27 | |||
28 | /** | ||
29 | * Find a tag by its label and its owner. | ||
30 | * | ||
31 | * @param string $label | ||
32 | * @param int $userId | ||
33 | * | ||
34 | * @return Tag|null | ||
35 | */ | ||
36 | public function findOneByLabelAndUserId($label, $userId) | ||
37 | { | ||
38 | return $this->createQueryBuilder('t') | ||
39 | ->where('t.label = :label')->setParameter('label', $label) | ||
40 | ->andWhere('t.user = :user_id')->setParameter('user_id', $userId) | ||
41 | ->getQuery() | ||
42 | ->getOneOrNullResult(); | ||
43 | } | ||
27 | } | 44 | } |