]>
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 NL |
11 | /** |
12 | * Find Tags. | |
13 | * | |
8ce32af6 | 14 | * @param int $userId |
3f3fbef1 NL |
15 | * |
16 | * @return array | |
17 | */ | |
18 | public function findTags($userId) | |
19 | { | |
20 | $qb = $this->createQueryBuilder('t') | |
21 | ->where('t.user =:userId')->setParameter('userId', $userId); | |
22 | ||
23 | $pagerAdapter = new DoctrineORMAdapter($qb); | |
24 | ||
25 | return new Pagerfanta($pagerAdapter); | |
26 | } | |
7244d6cb NL |
27 | |
28 | /** | |
29 | * Find a tag by its label and its owner. | |
30 | * | |
31 | * @param string $label | |
32 | * @param int $userId | |
33 | * | |
34 | * @return Tag|null | |
35 | */ | |
36 | public function findOneByLabelAndUserId($label, $userId) | |
37 | { | |
38 | return $this->createQueryBuilder('t') | |
39 | ->where('t.label = :label')->setParameter('label', $label) | |
40 | ->andWhere('t.user = :user_id')->setParameter('user_id', $userId) | |
41 | ->getQuery() | |
42 | ->getOneOrNullResult(); | |
43 | } | |
b3dc0749 | 44 | } |