diff --git a/src/Repository/AnnotationRepository.php b/src/Repository/AnnotationRepository.php index 6a762484d..524f8ebe6 100644 --- a/src/Repository/AnnotationRepository.php +++ b/src/Repository/AnnotationRepository.php @@ -148,6 +148,12 @@ class AnnotationRepository extends ServiceEntityRepository ->getResult(); } + public function getCountBuilderByUser($userId = null) + { + return $this->createQueryBuilder('e') + ->andWhere('e.user = :userId')->setParameter('userId', $userId); + } + /** * Return a query builder to used by other getBuilderFor* method. * diff --git a/src/Repository/EntryRepository.php b/src/Repository/EntryRepository.php index d2c7b06a6..83b3c77a4 100644 --- a/src/Repository/EntryRepository.php +++ b/src/Repository/EntryRepository.php @@ -228,21 +228,6 @@ class EntryRepository extends ServiceEntityRepository ; } - /** - * Retrieve entries with annotations count for a user. - * - * @param int $userId - * - * @return QueryBuilder - */ - public function getCountBuilderForAnnotationsByUser($userId) - { - return $this - ->getQueryBuilderByUser($userId) - ->innerJoin('e.annotations', 'a') - ; - } - /** * Retrieve untagged entries for a user. * diff --git a/src/Twig/WallabagExtension.php b/src/Twig/WallabagExtension.php index 9c80586e0..f21187414 100644 --- a/src/Twig/WallabagExtension.php +++ b/src/Twig/WallabagExtension.php @@ -9,6 +9,7 @@ use Twig\Extension\GlobalsInterface; use Twig\TwigFilter; use Twig\TwigFunction; use Wallabag\Entity\User; +use Wallabag\Repository\AnnotationRepository; use Wallabag\Repository\EntryRepository; use Wallabag\Repository\TagRepository; @@ -16,14 +17,16 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface { private $tokenStorage; private $entryRepository; + private $annotationRepository; private $tagRepository; private $lifeTime; private $translator; private $projectDir; - public function __construct(EntryRepository $entryRepository, TagRepository $tagRepository, TokenStorageInterface $tokenStorage, $lifeTime, TranslatorInterface $translator, string $projectDir) + public function __construct(EntryRepository $entryRepository, AnnotationRepository $annotationRepository, TagRepository $tagRepository, TokenStorageInterface $tokenStorage, $lifeTime, TranslatorInterface $translator, string $projectDir) { $this->entryRepository = $entryRepository; + $this->annotationRepository = $annotationRepository; $this->tagRepository = $tagRepository; $this->tokenStorage = $tokenStorage; $this->lifeTime = $lifeTime; @@ -96,28 +99,25 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface switch ($type) { case 'starred': - $qb = $this->entryRepository->getCountBuilderForStarredByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForStarredByUser($user->getId())->select('COUNT(e.id)'); break; case 'archive': - $qb = $this->entryRepository->getCountBuilderForArchiveByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForArchiveByUser($user->getId())->select('COUNT(e.id)'); break; case 'unread': - $qb = $this->entryRepository->getCountBuilderForUnreadByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForUnreadByUser($user->getId())->select('COUNT(e.id)'); break; case 'annotated': - $qb = $this->entryRepository->getCountBuilderForAnnotationsByUser($user->getId()); + $qb = $this->annotationRepository->getCountBuilderByUser($user->getId())->select('COUNT(DISTINCT e.entry)'); break; case 'all': - $qb = $this->entryRepository->getCountBuilderForAllByUser($user->getId()); + $qb = $this->entryRepository->getCountBuilderForAllByUser($user->getId())->select('COUNT(e.id)'); break; default: throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type)); } - $query = $qb - ->select('COUNT(e.id)') - ->getQuery(); - + $query = $qb->getQuery(); $query->useQueryCache(true); $query->enableResultCache($this->lifeTime); diff --git a/templates/Entry/_card_actions.html.twig b/templates/Entry/_card_actions.html.twig index f3f18ba95..d14572012 100644 --- a/templates/Entry/_card_actions.html.twig +++ b/templates/Entry/_card_actions.html.twig @@ -7,7 +7,7 @@ - {% set current_path = path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) %} + {% set current_path = app.request.requesturi %}