]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Repository/TagRepository.php
Merge pull request #2266 from wallabag/add-tags-counter
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / TagRepository.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Repository;
4
5 use Doctrine\ORM\EntityRepository;
6
7 class TagRepository extends EntityRepository
8 {
9 /**
10 * Find Tags.
11 *
12 * @param int $userId
13 *
14 * @return array
15 */
16 public function findAllTags($userId)
17 {
18 return $this->createQueryBuilder('t')
19 ->leftJoin('t.entries', 'e')
20 ->where('e.user = :userId')->setParameter('userId', $userId);
21 }
22
23 /**
24 * Used only in test case to get a tag for our entry.
25 *
26 * @return Tag
27 */
28 public function findOneByEntryAndTagLabel($entry, $label)
29 {
30 return $this->createQueryBuilder('t')
31 ->leftJoin('t.entries', 'e')
32 ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
33 ->andWhere('t.label = :label')->setParameter('label', $label)
34 ->setMaxResults(1)
35 ->getQuery()
36 ->getSingleResult();
37 }
38 }