]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/TagRepository.php
Merge remote-tracking branch 'origin/master' into 2.1
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / TagRepository.php
index 903a99cda3804bddfa61751cdf611a3c6a209e75..41f616079dd53f69032512adf6a1bfb176b98657 100644 (file)
@@ -6,5 +6,33 @@ use Doctrine\ORM\EntityRepository;
 
 class TagRepository extends EntityRepository
 {
+    /**
+     * Find Tags.
+     *
+     * @param int $userId
+     *
+     * @return array
+     */
+    public function findAllTags($userId)
+    {
+        return $this->createQueryBuilder('t')
+            ->leftJoin('t.entries', 'e')
+            ->where('e.user = :userId')->setParameter('userId', $userId);
+    }
 
+    /**
+     * Used only in test case to get a tag for our entry.
+     *
+     * @return Tag
+     */
+    public function findOneByEntryAndTagLabel($entry, $label)
+    {
+        return $this->createQueryBuilder('t')
+            ->leftJoin('t.entries', 'e')
+            ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
+            ->andWhere('t.label = :label')->setParameter('label', $label)
+            ->setMaxResults(1)
+            ->getQuery()
+            ->getSingleResult();
+    }
 }