aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-04-21 22:30:50 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-08-23 07:47:55 +0200
commit8315130a75c8f411f76134b6205a017409583d50 (patch)
treed6ef8c9725809df2885dfd1351a7ec188fd51c44 /src
parent79efca1e6ff28362d4bd2713f68205294cdd07de (diff)
downloadwallabag-8315130a75c8f411f76134b6205a017409583d50.tar.gz
wallabag-8315130a75c8f411f76134b6205a017409583d50.tar.zst
wallabag-8315130a75c8f411f76134b6205a017409583d50.zip
Display entries number for each category
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig8
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php33
2 files changed, 37 insertions, 4 deletions
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 @@
35 {% set currentRoute = app.request.attributes.get('_route') %} 35 {% set currentRoute = app.request.attributes.get('_route') %}
36 36
37 <li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}"> 37 <li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}">
38 <a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }}</a> 38 <a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }} <span class="numberItems grey-text">{{ unreadEntries }}</span></a>
39 </li> 39 </li>
40 <li class="bold {% if currentRoute == 'starred' %}active{% endif %}"> 40 <li class="bold {% if currentRoute == 'starred' %}active{% endif %}">
41 <a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }}</a> 41 <a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }} <span class="numberItems grey-text">{{ starredEntries }}</span></a>
42 </li> 42 </li>
43 <li class="bold {% if currentRoute == 'archive' %}active{% endif %}"> 43 <li class="bold {% if currentRoute == 'archive' %}active{% endif %}">
44 <a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }}</a> 44 <a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }} <span class="numberItems grey-text">{{ archivedEntries }}</span></a>
45 </li> 45 </li>
46 <li class="bold border-bottom {% if currentRoute == 'all' %}active{% endif %}"> 46 <li class="bold border-bottom {% if currentRoute == 'all' %}active{% endif %}">
47 <a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }}</a> 47 <a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }} <span class="numberItems grey-text">{{ allEntries }}</span></a>
48 </li> 48 </li>
49 <li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}"> 49 <li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}">
50 <a class="waves-effect" href="{{ path('tag') }}">{{ 'menu.left.tags'|trans }}</a> 50 <a class="waves-effect" href="{{ path('tag') }}">{{ 'menu.left.tags'|trans }}</a>
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 @@
2 2
3namespace Wallabag\CoreBundle\Twig; 3namespace Wallabag\CoreBundle\Twig;
4 4
5use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
6use Wallabag\CoreBundle\Repository\EntryRepository;
7
5class WallabagExtension extends \Twig_Extension 8class WallabagExtension extends \Twig_Extension
6{ 9{
10 private $tokenStorage;
11 private $repository;
12
13 public function __construct(EntryRepository $repository = null, TokenStorageInterface $tokenStorage = null)
14 {
15 $this->repository = $repository;
16 $this->tokenStorage = $tokenStorage;
17 }
18
7 public function getFilters() 19 public function getFilters()
8 { 20 {
9 return [ 21 return [
@@ -16,6 +28,27 @@ class WallabagExtension extends \Twig_Extension
16 return preg_replace('/^www\./i', '', $url); 28 return preg_replace('/^www\./i', '', $url);
17 } 29 }
18 30
31 public function getGlobals()
32 {
33 $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
34
35 if (null === $user || !is_object($user)) {
36 return array();
37 }
38
39 $unreadEntries = $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()->getResult();
40 $starredEntries = $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()->getResult();
41 $archivedEntries = $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()->getResult();
42 $allEntries = $this->repository->getBuilderForAllByUser($user->getId())->getQuery()->getResult();
43
44 return array(
45 'unreadEntries' => count($unreadEntries),
46 'starredEntries' => count($starredEntries),
47 'archivedEntries' => count($archivedEntries),
48 'allEntries' => count($allEntries),
49 );
50 }
51
19 public function getName() 52 public function getName()
20 { 53 {
21 return 'wallabag_extension'; 54 return 'wallabag_extension';