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 with associated entries per user.
42 public function findAllTagsWithEntries($userId)
44 return $this->createQueryBuilder('t')
45 ->leftJoin('t.entries', 'e')
46 ->where('e.user = :userId')->setParameter('userId', $userId)
52 * Used only in test case to get a tag for our entry.
56 public function findOneByEntryAndTagLabel($entry, $label)
58 return $this->createQueryBuilder('t')
59 ->leftJoin('t.entries', 'e')
60 ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
61 ->andWhere('t.label = :label')->setParameter('label', $label)