X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=82eb947462ea1db1e7653d9ffc725313c04ab127;hb=78833672469f7beb0c4a195aa0a76f7ca4133057;hp=502e9da05c0ee459dbe475630ff36bbdafeea7d1;hpb=303768dfe9b85f87d043eb225c5c8c3a88d8c051;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 502e9da0..82eb9474 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -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) @@ -226,18 +228,42 @@ class EntryRepository extends EntityRepository /** * Find an entry by its url and its owner. + * If it exists, return the entry otherwise return false. * * @param $url * @param $userId * - * @return array + * @return array|bool */ - public function findOneByUrlAndUserId($url, $userId) + public function findByUrlAndUserId($url, $userId) { - return $this->createQueryBuilder('e') + $res = $this->createQueryBuilder('e') ->where('e.url = :url')->setParameter('url', $url) ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) ->getQuery() ->getResult(); + + 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(); } }