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: [PATCH] Display entries number for each category --- .../static/themes/material/css/main.css | 4 +++ app/config/services.yml | 3 ++ .../views/themes/material/layout.html.twig | 8 ++--- .../CoreBundle/Twig/WallabagExtension.php | 33 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/Resources/static/themes/material/css/main.css b/app/Resources/static/themes/material/css/main.css index cade37f63..998924016 100755 --- a/app/Resources/static/themes/material/css/main.css +++ b/app/Resources/static/themes/material/css/main.css @@ -303,6 +303,10 @@ nav input { margin: 0 1rem; } +span.numberItems { + float: right; +} + /* ========================================================================== * 3 = Filters slider * ========================================================================== */ diff --git a/app/config/services.yml b/app/config/services.yml index 480408d91..95b8f26f5 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -16,6 +16,9 @@ services: wallabag.twig_extension: class: Wallabag\CoreBundle\Twig\WallabagExtension public: false + arguments: + - "@wallabag_core.entry_repository" + - "@security.token_storage" tags: - { name: twig.extension } 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 50134357f..f64c3da28 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 1a3080706..c116248ff 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';