]>
Commit | Line | Data |
---|---|---|
b3dc0749 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Repository; | |
4 | ||
5 | use Doctrine\ORM\EntityRepository; | |
3f3fbef1 NL |
6 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
7 | use Pagerfanta\Pagerfanta; | |
b3dc0749 | 8 | |
6d37a7e6 | 9 | class TagRepository extends EntityRepository |
b3dc0749 | 10 | { |
3f3fbef1 | 11 | /** |
fc732227 | 12 | * Return only the QueryBuilder to retrieve all tags for a given user. |
3f3fbef1 | 13 | * |
8ce32af6 | 14 | * @param int $userId |
3f3fbef1 | 15 | * |
fc732227 JB |
16 | * @return QueryBuilder |
17 | */ | |
18 | private function getQbForAllTags($userId) | |
19 | { | |
20 | return $this->createQueryBuilder('t') | |
21 | ->leftJoin('t.entries', 'e') | |
22 | ->where('e.user = :userId')->setParameter('userId', $userId); | |
23 | } | |
24 | ||
25 | /** | |
26 | * Find Tags and return a Pager. | |
27 | * | |
28 | * @param int $userId | |
29 | * | |
30 | * @return Pagerfanta | |
3f3fbef1 NL |
31 | */ |
32 | public function findTags($userId) | |
33 | { | |
fc732227 | 34 | $qb = $this->getQbForAllTags($userId); |
3f3fbef1 NL |
35 | |
36 | $pagerAdapter = new DoctrineORMAdapter($qb); | |
37 | ||
38 | return new Pagerfanta($pagerAdapter); | |
39 | } | |
7244d6cb NL |
40 | |
41 | /** | |
fc732227 | 42 | * Find Tags. |
7244d6cb | 43 | * |
fc732227 | 44 | * @param int $userId |
7244d6cb | 45 | * |
fc732227 | 46 | * @return array |
7244d6cb | 47 | */ |
fc732227 | 48 | public function findAllTags($userId) |
7244d6cb | 49 | { |
fc732227 | 50 | return $this->getQbForAllTags($userId) |
7244d6cb | 51 | ->getQuery() |
fc732227 | 52 | ->getResult(); |
7244d6cb | 53 | } |
567421af TC |
54 | |
55 | /** | |
56 | * Used only in test case to get a tag for our entry. | |
57 | * | |
58 | * @return Tag | |
59 | */ | |
e686a76d | 60 | public function findOneByEntryAndTagLabel($entry, $label) |
567421af TC |
61 | { |
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) | |
66 | ->setMaxResults(1) | |
67 | ->getQuery() | |
68 | ->getSingleResult(); | |
69 | } | |
b3dc0749 | 70 | } |