X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=82eb947462ea1db1e7653d9ffc725313c04ab127;hb=3bcc4d4cb29abeedb48b1f297f1a65a02998ff69;hp=ca71970bcbaf9b83936da34a93bde1694c16824a;hpb=6be9750155fa731d75898b4973a126a090345c2d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index ca71970b..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) @@ -223,4 +225,45 @@ class EntryRepository extends EntityRepository ->getQuery() ->getResult(); } + + /** + * Find an entry by its url and its owner. + * If it exists, return the entry otherwise return false. + * + * @param $url + * @param $userId + * + * @return array|bool + */ + public function findByUrlAndUserId($url, $userId) + { + $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(); + } }