]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Repository/TagRepository.php
Fix tags listing
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / TagRepository.php
CommitLineData
b3dc0749
NL
1<?php
2
3namespace Wallabag\CoreBundle\Repository;
4
5use Doctrine\ORM\EntityRepository;
b3dc0749 6
6d37a7e6 7class TagRepository extends EntityRepository
b3dc0749 8{
3f3fbef1 9 /**
fc732227 10 * Return only the QueryBuilder to retrieve all tags for a given user.
3f3fbef1 11 *
8ce32af6 12 * @param int $userId
3f3fbef1 13 *
fc732227
JB
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
7244d6cb 23 /**
fc732227 24 * Find Tags.
7244d6cb 25 *
fc732227 26 * @param int $userId
7244d6cb 27 *
fc732227 28 * @return array
7244d6cb 29 */
fc732227 30 public function findAllTags($userId)
7244d6cb 31 {
fc732227 32 return $this->getQbForAllTags($userId)
7244d6cb 33 ->getQuery()
fc732227 34 ->getResult();
7244d6cb 35 }
567421af
TC
36
37 /**
38 * Used only in test case to get a tag for our entry.
39 *
40 * @return Tag
41 */
e686a76d 42 public function findOneByEntryAndTagLabel($entry, $label)
567421af
TC
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 }
b3dc0749 52}