]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Repository; | |
4 | ||
5 | use Doctrine\ORM\EntityRepository; | |
6 | use Pagerfanta\Adapter\DoctrineORMAdapter; | |
7 | use Pagerfanta\Pagerfanta; | |
8 | ||
9 | class TagRepository extends EntityRepository | |
10 | { | |
11 | /** | |
12 | * Return only the QueryBuilder to retrieve all tags for a given user. | |
13 | * | |
14 | * @param int $userId | |
15 | * | |
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 | |
31 | */ | |
32 | public function findTags($userId) | |
33 | { | |
34 | $qb = $this->getQbForAllTags($userId); | |
35 | ||
36 | $pagerAdapter = new DoctrineORMAdapter($qb); | |
37 | ||
38 | return new Pagerfanta($pagerAdapter); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Find Tags. | |
43 | * | |
44 | * @param int $userId | |
45 | * | |
46 | * @return array | |
47 | */ | |
48 | public function findAllTags($userId) | |
49 | { | |
50 | return $this->getQbForAllTags($userId) | |
51 | ->getQuery() | |
52 | ->getResult(); | |
53 | } | |
54 | } |