X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FTwig%2FWallabagExtension.php;h=c116248ffa6833fb9f1a1141311ee4779280aca4;hb=8315130a75c8f411f76134b6205a017409583d50;hp=1a308070672e057bea8277288c46684ca6e5eb29;hpb=79efca1e6ff28362d4bd2713f68205294cdd07de;p=github%2Fwallabag%2Fwallabag.git 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';