aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Twig
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-09-03 16:13:08 +0200
committerGitHub <noreply@github.com>2016-09-03 16:13:08 +0200
commit8f8654913ce82be12219a37a24630066bbe950c2 (patch)
tree303a416dc4fd95bc124abaaf183f2ca9f39494d8 /src/Wallabag/CoreBundle/Twig
parent9972ab467af3a9d6d1c7f3588dbb940b38298aaa (diff)
parentb3f4a11a81b520b8dcc2bcebeeafea2cc0338a70 (diff)
downloadwallabag-8f8654913ce82be12219a37a24630066bbe950c2.tar.gz
wallabag-8f8654913ce82be12219a37a24630066bbe950c2.tar.zst
wallabag-8f8654913ce82be12219a37a24630066bbe950c2.zip
Merge pull request #2002 from wallabag/feature-display-itemsNumber
Feature display items number
Diffstat (limited to 'src/Wallabag/CoreBundle/Twig')
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Twig/WallabagExtension.php b/src/Wallabag/CoreBundle/Twig/WallabagExtension.php
index 1a308070..5c475d61 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
5class WallabagExtension extends \Twig_Extension 5use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
6use Wallabag\CoreBundle\Repository\EntryRepository;
7
8class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
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,38 @@ 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->enableCache(
40 $this->repository->getBuilderForUnreadByUser($user->getId())->getQuery()
41 );
42
43 $starredEntries = $this->repository->enableCache(
44 $this->repository->getBuilderForStarredByUser($user->getId())->getQuery()
45 );
46
47 $archivedEntries = $this->repository->enableCache(
48 $this->repository->getBuilderForArchiveByUser($user->getId())->getQuery()
49 );
50
51 $allEntries = $this->repository->enableCache(
52 $this->repository->getBuilderForAllByUser($user->getId())->getQuery()
53 );
54
55 return array(
56 'unreadEntries' => count($unreadEntries->getResult()),
57 'starredEntries' => count($starredEntries->getResult()),
58 'archivedEntries' => count($archivedEntries->getResult()),
59 'allEntries' => count($allEntries->getResult()),
60 );
61 }
62
19 public function getName() 63 public function getName()
20 { 64 {
21 return 'wallabag_extension'; 65 return 'wallabag_extension';