3 namespace Wallabag\CoreBundle\Repository
;
5 use Doctrine\ORM\EntityRepository
;
7 class TagRepository
extends EntityRepository
10 * Count all tags per user.
13 * @param int $cacheLifeTime Duration of the cache for this query
17 public function countAllTags($userId, $cacheLifeTime = null)
19 $query = $this->createQueryBuilder('t')
21 ->leftJoin('t.entries', 'e')
22 ->where('e.user = :userId')->setParameter('userId', $userId)
26 if (null !== $cacheLifeTime) {
27 $query->useQueryCache(true);
28 $query->useResultCache(true);
29 $query->setResultCacheLifetime($cacheLifeTime);
32 return count($query->getArrayResult());
36 * Find all tags per user.
42 public function findAllTags($userId)
44 return $this->createQueryBuilder('t')
45 ->select('t.slug', 't.label', 't.id')
46 ->leftJoin('t.entries', 'e')
47 ->where('e.user = :userId')->setParameter('userId', $userId)
49 ->addGroupBy('t.label')
56 * Used only in test case to get a tag for our entry.
60 public function findOneByEntryAndTagLabel($entry, $label)
62 return $this->createQueryBuilder('t')
63 ->leftJoin('t.entries', 'e')
64 ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
65 ->andWhere('t.label = :label')->setParameter('label', $label)