]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
Merge remote-tracking branch 'origin/master' into 2.3
[github/wallabag/wallabag.git] / src / Wallabag / AnnotationBundle / Repository / AnnotationRepository.php
index 8d3f07eef350f2eb8ebf12a05b80deb5f6d026fb..b44f7e647acc4d35a5d0af70a63fd0bc48785680 100644 (file)
@@ -3,28 +3,14 @@
 namespace Wallabag\AnnotationBundle\Repository;
 
 use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\QueryBuilder;
+use Wallabag\AnnotationBundle\Entity\Annotation;
 
 /**
  * AnnotationRepository.
  */
 class AnnotationRepository extends EntityRepository
 {
-    /**
-     * Return a query builder to used by other getBuilderFor* method.
-     *
-     * @param int $userId
-     *
-     * @return QueryBuilder
-     */
-    private function getBuilderByUser($userId)
-    {
-        return $this->createQueryBuilder('a')
-            ->leftJoin('a.user', 'u')
-            ->andWhere('u.id = :userId')->setParameter('userId', $userId)
-            ->orderBy('a.id', 'desc')
-        ;
-    }
-
     /**
      * Retrieves all annotations for a user.
      *
@@ -122,4 +108,37 @@ class AnnotationRepository extends EntityRepository
             ->setParameter('userId', $userId)
             ->execute();
     }
+
+    /**
+     * Find all annotations related to archived entries.
+     *
+     * @param $userId
+     *
+     * @return mixed
+     */
+    public function findAllArchivedEntriesByUser($userId)
+    {
+        return $this->createQueryBuilder('a')
+            ->leftJoin('a.entry', 'e')
+            ->where('a.user = :userid')->setParameter(':userid', $userId)
+            ->andWhere('e.isArchived = true')
+            ->getQuery()
+            ->getResult();
+    }
+
+    /**
+     * Return a query builder to used by other getBuilderFor* method.
+     *
+     * @param int $userId
+     *
+     * @return QueryBuilder
+     */
+    private function getBuilderByUser($userId)
+    {
+        return $this->createQueryBuilder('a')
+            ->leftJoin('a.user', 'u')
+            ->andWhere('u.id = :userId')->setParameter('userId', $userId)
+            ->orderBy('a.id', 'desc')
+        ;
+    }
 }