diff options
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 3ae9d414..bd2d9f97 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Wallabag\CoreBundle\Repository; | 3 | namespace Wallabag\CoreBundle\Repository; |
4 | 4 | ||
5 | use Doctrine\ORM\EntityRepository; | 5 | use Doctrine\ORM\EntityRepository; |
6 | use Doctrine\ORM\QueryBuilder; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | 8 | ||
8 | class TagRepository extends EntityRepository | 9 | class TagRepository extends EntityRepository |
@@ -45,12 +46,8 @@ class TagRepository extends EntityRepository | |||
45 | */ | 46 | */ |
46 | public function findAllTags($userId) | 47 | public function findAllTags($userId) |
47 | { | 48 | { |
48 | $ids = $this->createQueryBuilder('t') | 49 | $ids = $this->getQueryBuilderByUser($userId) |
49 | ->select('t.id') | 50 | ->select('t.id') |
50 | ->leftJoin('t.entries', 'e') | ||
51 | ->where('e.user = :userId')->setParameter('userId', $userId) | ||
52 | ->groupBy('t.id') | ||
53 | ->orderBy('t.slug') | ||
54 | ->getQuery() | 51 | ->getQuery() |
55 | ->getArrayResult(); | 52 | ->getArrayResult(); |
56 | 53 | ||
@@ -71,14 +68,9 @@ class TagRepository extends EntityRepository | |||
71 | */ | 68 | */ |
72 | public function findAllFlatTagsWithNbEntries($userId) | 69 | public function findAllFlatTagsWithNbEntries($userId) |
73 | { | 70 | { |
74 | return $this->createQueryBuilder('t') | 71 | return $this->getQueryBuilderByUser($userId) |
75 | ->select('t.id, t.label, t.slug, count(e.id) as nbEntries') | 72 | ->select('t.id, t.label, t.slug, count(e.id) as nbEntries') |
76 | ->distinct(true) | 73 | ->distinct(true) |
77 | ->leftJoin('t.entries', 'e') | ||
78 | ->where('e.user = :userId') | ||
79 | ->groupBy('t.id') | ||
80 | ->orderBy('t.slug') | ||
81 | ->setParameter('userId', $userId) | ||
82 | ->getQuery() | 74 | ->getQuery() |
83 | ->getArrayResult(); | 75 | ->getArrayResult(); |
84 | } | 76 | } |
@@ -101,13 +93,9 @@ class TagRepository extends EntityRepository | |||
101 | 93 | ||
102 | public function findForArchivedArticlesByUser($userId) | 94 | public function findForArchivedArticlesByUser($userId) |
103 | { | 95 | { |
104 | $ids = $this->createQueryBuilder('t') | 96 | $ids = $this->getQueryBuilderByUser($userId) |
105 | ->select('t.id') | 97 | ->select('t.id') |
106 | ->leftJoin('t.entries', 'e') | ||
107 | ->where('e.user = :userId')->setParameter('userId', $userId) | ||
108 | ->andWhere('e.isArchived = true') | 98 | ->andWhere('e.isArchived = true') |
109 | ->groupBy('t.id') | ||
110 | ->orderBy('t.slug') | ||
111 | ->getQuery() | 99 | ->getQuery() |
112 | ->getArrayResult(); | 100 | ->getArrayResult(); |
113 | 101 | ||
@@ -118,4 +106,20 @@ class TagRepository extends EntityRepository | |||
118 | 106 | ||
119 | return $tags; | 107 | return $tags; |
120 | } | 108 | } |
109 | |||
110 | /** | ||
111 | * Retrieve a sorted list of tags used by a user. | ||
112 | * | ||
113 | * @param int $userId | ||
114 | * | ||
115 | * @return QueryBuilder | ||
116 | */ | ||
117 | private function getQueryBuilderByUser($userId) | ||
118 | { | ||
119 | return $this->createQueryBuilder('t') | ||
120 | ->leftJoin('t.entries', 'e') | ||
121 | ->where('e.user = :userId')->setParameter('userId', $userId) | ||
122 | ->groupBy('t.id') | ||
123 | ->orderBy('t.slug'); | ||
124 | } | ||
121 | } | 125 | } |