]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Repository/TagRepository.php
Fix tags listing
[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 * Return only the QueryBuilder to retrieve all tags for a given user.
11 *
12 * @param int $userId
13 *
14 * @return QueryBuilder
15 */
16 private function getQbForAllTags($userId)
17 {
18 return $this->createQueryBuilder('t')
19 ->leftJoin('t.entries', 'e')
20 ->where('e.user = :userId')->setParameter('userId', $userId);
21 }
22
23 /**
24 * Find Tags.
25 *
26 * @param int $userId
27 *
28 * @return array
29 */
30 public function findAllTags($userId)
31 {
32 return $this->getQbForAllTags($userId)
33 ->getQuery()
34 ->getResult();
35 }
36
37 /**
38 * Used only in test case to get a tag for our entry.
39 *
40 * @return Tag
41 */
42 public function findOneByEntryAndTagLabel($entry, $label)
43 {
44 return $this->createQueryBuilder('t')
45 ->leftJoin('t.entries', 'e')
46 ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
47 ->andWhere('t.label = :label')->setParameter('label', $label)
48 ->setMaxResults(1)
49 ->getQuery()
50 ->getSingleResult();
51 }
52 }