]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/WallabagBundle/Repository/EntriesRepository.php
some parameters, new entry form, etc.
[github/wallabag/wallabag.git] / src / WallabagBundle / Repository / EntriesRepository.php
index c355a012c61dd51a68ccc0a1e914f4d9468e3a42..3eb1733d1ebff98cb3ea92c19fa6093155b7f184 100644 (file)
@@ -4,48 +4,76 @@ 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)
+    /**
+     * Retrieves unread entries for a user
+     *
+     * @param $userId
+     * @param $firstResult
+     * @param int $maxResults
+     * @return Paginator
+     */
+    public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
     {
         $qb = $this->createQueryBuilder('e')
             ->select('e')
+            ->setFirstResult($firstResult)
+            ->setMaxResults($maxResults)
             ->where('e.isRead = 0')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
-            ->getQuery()
-            ->getResult(Query::HYDRATE_ARRAY);
+            ->getQuery();
 
-        return $qb;
+        $paginator = new Paginator($qb);
+
+        return $paginator;
     }
 
-    public function findArchiveByUser($userId)
+    /**
+     * Retrieves read entries for a user
+     *
+     * @param $userId
+     * @param $firstResult
+     * @param int $maxResults
+     * @return Paginator
+     */
+    public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
     {
         $qb = $this->createQueryBuilder('e')
             ->select('e')
+            ->setFirstResult($firstResult)
+            ->setMaxResults($maxResults)
             ->where('e.isRead = 1')
             ->andWhere('e.userId =:userId')->setParameter('userId', $userId)
-            ->getQuery()
-            ->getResult(Query::HYDRATE_ARRAY);
+            ->getQuery();
+
+        $paginator = new Paginator($qb);
 
-        return $qb;
+        return $paginator;
     }
 
-    public function findStarredByUser($userId)
+    /**
+     * Retrieves starred entries for a user
+     *
+     * @param $userId
+     * @param $firstResult
+     * @param int $maxResults
+     * @return Paginator
+     */
+    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);
+            ->getQuery();
+
+        $paginator = new Paginator($qb);
 
-        return $qb;
+        return $paginator;
     }
 }