From 8315130a75c8f411f76134b6205a017409583d50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 21 Apr 2016 22:30:50 +0200 Subject: Display entries number for each category --- .../views/themes/material/layout.html.twig | 8 +++--- src/Wallabag/CoreBundle/Twig/WallabagExtension.php | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig index 50134357..f64c3da2 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig @@ -35,16 +35,16 @@ {% set currentRoute = app.request.attributes.get('_route') %}
  • - {{ 'menu.left.unread'|trans }} + {{ 'menu.left.unread'|trans }} {{ unreadEntries }}
  • - {{ 'menu.left.starred'|trans }} + {{ 'menu.left.starred'|trans }} {{ starredEntries }}
  • - {{ 'menu.left.archive'|trans }} + {{ 'menu.left.archive'|trans }} {{ archivedEntries }}
  • - {{ 'menu.left.all_articles'|trans }} + {{ 'menu.left.all_articles'|trans }} {{ allEntries }}
  • {{ 'menu.left.tags'|trans }} diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php index 1a308070..c116248f 100644 --- a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php +++ b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php @@ -2,8 +2,20 @@ namespace Wallabag\CoreBundle\Twig; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Wallabag\CoreBundle\Repository\EntryRepository; + class WallabagExtension extends \Twig_Extension { + private $tokenStorage; + private $repository; + + public function __construct(EntryRepository $repository = null, TokenStorageInterface $tokenStorage = null) + { + $this->repository = $repository; + $this->tokenStorage = $tokenStorage; + } + public function getFilters() { return [ @@ -16,6 +28,27 @@ class WallabagExtension extends \Twig_Extension return preg_replace('/^www\./i', '', $url); } + public function getGlobals() + { + $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null; + + if (null === $user || !is_object($user)) { + return array(); + } + + $unreadEntries = $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()->getResult(); + $starredEntries = $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()->getResult(); + $archivedEntries = $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()->getResult(); + $allEntries = $this->repository->getBuilderForAllByUser($user->getId())->getQuery()->getResult(); + + return array( + 'unreadEntries' => count($unreadEntries), + 'starredEntries' => count($starredEntries), + 'archivedEntries' => count($archivedEntries), + 'allEntries' => count($allEntries), + ); + } + public function getName() { return 'wallabag_extension'; -- cgit v1.2.3