Display entries number for each category

This commit is contained in:
Nicolas Lœuillet 2016-04-21 22:30:50 +02:00 committed by Jeremy Benoist
parent 79efca1e6f
commit 8315130a75
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
4 changed files with 44 additions and 4 deletions

View file

@ -303,6 +303,10 @@ nav input {
margin: 0 1rem;
}
span.numberItems {
float: right;
}
/* ==========================================================================
* 3 = Filters slider
* ========================================================================== */

View file

@ -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 }

View file

@ -35,16 +35,16 @@
{% set currentRoute = app.request.attributes.get('_route') %}
<li class="bold {% if currentRoute == 'unread' or currentRoute == 'homepage' %}active{% endif %}">
<a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }}</a>
<a class="waves-effect" href="{{ path('unread') }}">{{ 'menu.left.unread'|trans }} <span class="numberItems grey-text">{{ unreadEntries }}</span></a>
</li>
<li class="bold {% if currentRoute == 'starred' %}active{% endif %}">
<a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }}</a>
<a class="waves-effect" href="{{ path('starred') }}">{{ 'menu.left.starred'|trans }} <span class="numberItems grey-text">{{ starredEntries }}</span></a>
</li>
<li class="bold {% if currentRoute == 'archive' %}active{% endif %}">
<a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }}</a>
<a class="waves-effect" href="{{ path('archive') }}">{{ 'menu.left.archive'|trans }} <span class="numberItems grey-text">{{ archivedEntries }}</span></a>
</li>
<li class="bold border-bottom {% if currentRoute == 'all' %}active{% endif %}">
<a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }}</a>
<a class="waves-effect" href="{{ path('all') }}">{{ 'menu.left.all_articles'|trans }} <span class="numberItems grey-text">{{ allEntries }}</span></a>
</li>
<li class="bold border-bottom {% if currentRoute == 'tags' %}active{% endif %}">
<a class="waves-effect" href="{{ path('tag') }}">{{ 'menu.left.tags'|trans }}</a>

View file

@ -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';