]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Merge pull request #1524 from wallabag/sf2.8
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index b8e22eb833a4bea43150eb2c660cac900a4207ff..a16be9e01924d4cefb89b6a37db999fb341ef704 100644 (file)
@@ -122,6 +122,8 @@ class EntryRepository extends EntityRepository
     /**
      * Fetch an entry with a tag. Only used for tests.
      *
+     * @param int $userId
+     *
      * @return Entry
      */
     public function findOneWithTags($userId)
@@ -242,10 +244,27 @@ class EntryRepository extends EntityRepository
             ->getQuery()
             ->getResult();
 
-        if (count($res) > 1) {
-            return next($res);
+        if (count($res)) {
+            return current($res);
         }
 
         return false;
     }
+
+    /**
+     * Count all entries for a user.
+     *
+     * @param int $userId
+     *
+     * @return integer
+     */
+    public function countAllEntriesByUsername($userId)
+    {
+        $qb = $this->createQueryBuilder('e')
+            ->select('count(e)')
+            ->where('e.user=:userId')->setParameter('userId', $userId)
+        ;
+
+        return $qb->getQuery()->getSingleScalarResult();
+    }
 }