]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/TagRepository.php
Provide a way to delete tagging rules
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / TagRepository.php
index 903a99cda3804bddfa61751cdf611a3c6a209e75..ac3145a1dc8896d5ec8a980f3fee4769d37817ed 100644 (file)
@@ -3,8 +3,42 @@
 namespace Wallabag\CoreBundle\Repository;
 
 use Doctrine\ORM\EntityRepository;
+use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Pagerfanta;
 
 class TagRepository extends EntityRepository
 {
+    /**
+     * Find Tags.
+     *
+     * @param int $userId
+     *
+     * @return array
+     */
+    public function findTags($userId)
+    {
+        $qb = $this->createQueryBuilder('t')
+            ->where('t.user =:userId')->setParameter('userId', $userId);
 
+        $pagerAdapter = new DoctrineORMAdapter($qb);
+
+        return new Pagerfanta($pagerAdapter);
+    }
+
+    /**
+     * Find a tag by its label and its owner.
+     *
+     * @param string $label
+     * @param int    $userId
+     *
+     * @return Tag|null
+     */
+    public function findOneByLabelAndUserId($label, $userId)
+    {
+        return $this->createQueryBuilder('t')
+            ->where('t.label = :label')->setParameter('label', $label)
+            ->andWhere('t.user = :user_id')->setParameter('user_id', $userId)
+            ->getQuery()
+            ->getOneOrNullResult();
+    }
 }