]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/WallabagBundle/Repository/EntriesRepository.php
toggle archive / fav actions
[github/wallabag/wallabag.git] / src / WallabagBundle / Repository / EntriesRepository.php
index 4c13c9c2fd65f07fa6b104207a3f990714e556a8..c4428a1d20046e6cf70d1d45c33a020716429cf7 100644 (file)
@@ -4,28 +4,46 @@ namespace WallabagBundle\Repository;
 
 use Doctrine\ORM\Query;
 use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\Tools\Pagination\Paginator;
 
-/**
- * EntriesRepository
- *
- * This class was generated by the Doctrine ORM. Add your own custom
- * repository methods below.
- */
 class EntriesRepository extends EntityRepository
 {
-  /*  public function findUnreadByUser($userId)
+    public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
     {
-        return $this->createQueryBuilder('e')
-            ->where('e.is_read = 0')
-            ->andWhere('e.user_id = :userId')
-            ->setParameter('userId', $userId)
+        $qb = $this->createQueryBuilder('e')
+            ->select('e')
+            ->setFirstResult($firstResult)
+            ->setMaxResults($maxResults)
+            ->where('e.isRead = 0')
+            ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
             ->getQuery();
-    }*/
-    public function findUnreadByUser($userId)
+
+        $pag = new Paginator($qb);
+
+        return $pag;
+    }
+
+    public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
     {
         $qb = $this->createQueryBuilder('e')
             ->select('e')
-            ->where('e.isRead = 0')
+            ->setFirstResult($firstResult)
+            ->setMaxResults($maxResults)
+            ->where('e.isRead = 1')
+            ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
+            ->getQuery()
+            ->getResult(Query::HYDRATE_ARRAY);
+
+        return $qb;
+    }
+
+    public function findStarredByUser($userId, $firstResult, $maxResults = 12)
+    {
+        $qb = $this->createQueryBuilder('e')
+            ->select('e')
+            ->setFirstResult($firstResult)
+            ->setMaxResults($maxResults)
+            ->where('e.isFav = 1')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
             ->getQuery()
             ->getResult(Query::HYDRATE_ARRAY);