diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-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..f5c4ea6a 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 | * Find all tags per user. |
11 | * | 11 | * |
12 | * @param int $userId | 12 | * @param int $userId |
13 | * @param int $cacheLifeTime Duration of the cache for this query | ||
13 | * | 14 | * |
14 | * @return array | 15 | * @return array |
15 | */ | 16 | */ |
16 | public function findAllTags($userId) | 17 | public function findAllTags($userId, $cacheLifeTime = null) |
18 | { | ||
19 | $query = $this->createQueryBuilder('t') | ||
20 | ->select('t') | ||
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 $query->getArrayResult(); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Find all tags with associated entries per user. | ||
37 | * | ||
38 | * @param int $userId | ||
39 | * | ||
40 | * @return array | ||
41 | */ | ||
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 | /** |