aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/TagRepository.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/TagRepository.php')
-rw-r--r--src/Wallabag/CoreBundle/Repository/TagRepository.php34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php
index abf915fe..e76878d4 100644
--- a/src/Wallabag/CoreBundle/Repository/TagRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php
@@ -7,7 +7,33 @@ use Doctrine\ORM\EntityRepository;
7class TagRepository extends EntityRepository 7class TagRepository extends EntityRepository
8{ 8{
9 /** 9 /**
10 * Find Tags. 10 * Count all tags per user.
11 *
12 * @param int $userId
13 * @param int $cacheLifeTime Duration of the cache for this query
14 *
15 * @return int
16 */
17 public function countAllTags($userId, $cacheLifeTime = null)
18 {
19 $query = $this->createQueryBuilder('t')
20 ->select('t.slug')
21 ->leftJoin('t.entries', 'e')
22 ->where('e.user = :userId')->setParameter('userId', $userId)
23 ->groupBy('t.slug')
24 ->getQuery();
25
26 if (null !== $cacheLifeTime) {
27 $query->useQueryCache(true);
28 $query->useResultCache(true);
29 $query->setResultCacheLifetime($cacheLifeTime);
30 }
31
32 return count($query->getArrayResult());
33 }
34
35 /**
36 * Find all tags per user.
11 * 37 *
12 * @param int $userId 38 * @param int $userId
13 * 39 *
@@ -16,10 +42,14 @@ class TagRepository extends EntityRepository
16 public function findAllTags($userId) 42 public function findAllTags($userId)
17 { 43 {
18 return $this->createQueryBuilder('t') 44 return $this->createQueryBuilder('t')
45 ->select('t.slug', 't.label', 't.id')
19 ->leftJoin('t.entries', 'e') 46 ->leftJoin('t.entries', 'e')
20 ->where('e.user = :userId')->setParameter('userId', $userId) 47 ->where('e.user = :userId')->setParameter('userId', $userId)
48 ->groupBy('t.slug')
49 ->addGroupBy('t.label')
50 ->addGroupBy('t.id')
21 ->getQuery() 51 ->getQuery()
22 ->getResult(); 52 ->getArrayResult();
23 } 53 }
24 54
25 /** 55 /**