diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository/TagRepository.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Repository/TagRepository.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 41f61607..9d127da7 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php | |||
@@ -7,17 +7,45 @@ use Doctrine\ORM\EntityRepository; | |||
7 | class TagRepository extends EntityRepository | 7 | class 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 with associated entries per user. | ||
11 | * | 37 | * |
12 | * @param int $userId | 38 | * @param int $userId |
13 | * | 39 | * |
14 | * @return array | 40 | * @return array |
15 | */ | 41 | */ |
16 | public function findAllTags($userId) | 42 | public function findAllTagsWithEntries($userId) |
17 | { | 43 | { |
18 | return $this->createQueryBuilder('t') | 44 | return $this->createQueryBuilder('t') |
19 | ->leftJoin('t.entries', 'e') | 45 | ->leftJoin('t.entries', 'e') |
20 | ->where('e.user = :userId')->setParameter('userId', $userId); | 46 | ->where('e.user = :userId')->setParameter('userId', $userId) |
47 | ->getQuery() | ||
48 | ->getResult(); | ||
21 | } | 49 | } |
22 | 50 | ||
23 | /** | 51 | /** |