]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/TagRepository.php
Merge pull request #2306 from wallabag/redis-rabbit-check
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / TagRepository.php
index ac3145a1dc8896d5ec8a980f3fee4769d37817ed..41f616079dd53f69032512adf6a1bfb176b98657 100644 (file)
@@ -3,8 +3,6 @@
 namespace Wallabag\CoreBundle\Repository;
 
 use Doctrine\ORM\EntityRepository;
-use Pagerfanta\Adapter\DoctrineORMAdapter;
-use Pagerfanta\Pagerfanta;
 
 class TagRepository extends EntityRepository
 {
@@ -15,30 +13,26 @@ class TagRepository extends EntityRepository
      *
      * @return array
      */
-    public function findTags($userId)
+    public function findAllTags($userId)
     {
-        $qb = $this->createQueryBuilder('t')
-            ->where('t.user =:userId')->setParameter('userId', $userId);
-
-        $pagerAdapter = new DoctrineORMAdapter($qb);
-
-        return new Pagerfanta($pagerAdapter);
+        return $this->createQueryBuilder('t')
+            ->leftJoin('t.entries', 'e')
+            ->where('e.user = :userId')->setParameter('userId', $userId);
     }
 
     /**
-     * Find a tag by its label and its owner.
-     *
-     * @param string $label
-     * @param int    $userId
+     * Used only in test case to get a tag for our entry.
      *
-     * @return Tag|null
+     * @return Tag
      */
-    public function findOneByLabelAndUserId($label, $userId)
+    public function findOneByEntryAndTagLabel($entry, $label)
     {
         return $this->createQueryBuilder('t')
-            ->where('t.label = :label')->setParameter('label', $label)
-            ->andWhere('t.user = :user_id')->setParameter('user_id', $userId)
+            ->leftJoin('t.entries', 'e')
+            ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
+            ->andWhere('t.label = :label')->setParameter('label', $label)
+            ->setMaxResults(1)
             ->getQuery()
-            ->getOneOrNullResult();
+            ->getSingleResult();
     }
 }