]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/AnnotationBundle/Repository/AnnotationRepository.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / AnnotationBundle / Repository / AnnotationRepository.php
index 8cccffba1366bb51c46f68de2bcec354c2b3a616..014c29b65f97b39758880c894106652dbcf830d3 100644 (file)
@@ -9,22 +9,6 @@ use Doctrine\ORM\EntityRepository;
  */
 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.
      *
@@ -108,4 +92,51 @@ class AnnotationRepository extends EntityRepository
             ->getQuery()
             ->getSingleResult();
     }
+
+    /**
+     * Remove all annotations for a user id.
+     * Used when a user want to reset all informations.
+     *
+     * @param int $userId
+     */
+    public function removeAllByUserId($userId)
+    {
+        $this->getEntityManager()
+            ->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = :userId')
+            ->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')
+        ;
+    }
 }