X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FTagRepository.php;h=3ae9d4141161c4443eb98f9bc6533695558e6143;hb=2a1ceb67b4400f46f4d3067e887ff54aa906f0a2;hp=213283e5d6d8b1da418a2eba536823fc152ec83e;hpb=4fc7eba34904a062cddf1e61956c48f27cb2e06c;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 213283e5..3ae9d414 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -30,7 +30,7 @@ class TagRepository extends EntityRepository $query->setResultCacheLifetime($cacheLifeTime); } - return count($query->getArrayResult()); + return \count($query->getArrayResult()); } /** @@ -62,6 +62,27 @@ class TagRepository extends EntityRepository return $tags; } + /** + * Find all tags (flat) per user with nb entries. + * + * @param int $userId + * + * @return array + */ + public function findAllFlatTagsWithNbEntries($userId) + { + return $this->createQueryBuilder('t') + ->select('t.id, t.label, t.slug, count(e.id) as nbEntries') + ->distinct(true) + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId') + ->groupBy('t.id') + ->orderBy('t.slug') + ->setParameter('userId', $userId) + ->getQuery() + ->getArrayResult(); + } + /** * Used only in test case to get a tag for our entry. *