aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2018-12-29 19:42:37 +0100
committerKevin Decherf <kevin@kdecherf.com>2018-12-30 01:34:44 +0100
commit6708bf238de46d7ce861e3c0eeb6a9b4623931ed (patch)
tree55aaf6ed40b5c7bdc32bfa37b6758befebea5a81 /src/Wallabag
parentbafb9744c87255ebe28945879da85e587175d241 (diff)
downloadwallabag-6708bf238de46d7ce861e3c0eeb6a9b4623931ed.tar.gz
wallabag-6708bf238de46d7ce861e3c0eeb6a9b4623931ed.tar.zst
wallabag-6708bf238de46d7ce861e3c0eeb6a9b4623931ed.zip
TagRepository: refactor query builder for queries by userId
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php36
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 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\QueryBuilder;
6use Wallabag\CoreBundle\Entity\Tag; 7use Wallabag\CoreBundle\Entity\Tag;
7 8
8class TagRepository extends EntityRepository 9class 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}