aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/Configuration.php3
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php1
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php24
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig8
-rw-r--r--src/Wallabag/CoreBundle/Twig/WallabagExtension.php46
6 files changed, 79 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
index d1bb9820..d8141eea 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
@@ -36,6 +36,9 @@ class Configuration implements ConfigurationInterface
36 ->end() 36 ->end()
37 ->scalarNode('paypal_url') 37 ->scalarNode('paypal_url')
38 ->end() 38 ->end()
39 ->integerNode('cache_lifetime')
40 ->defaultValue(10)
41 ->end()
39 ->end() 42 ->end()
40 ; 43 ;
41 44
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
index 7d08b73b..0cbde908 100644
--- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
+++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
@@ -22,6 +22,7 @@ class WallabagCoreExtension extends Extension
22 $container->setParameter('wallabag_core.reading_speed', $config['reading_speed']); 22 $container->setParameter('wallabag_core.reading_speed', $config['reading_speed']);
23 $container->setParameter('wallabag_core.version', $config['version']); 23 $container->setParameter('wallabag_core.version', $config['version']);
24 $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); 24 $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']);
25 $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']);
25 26
26 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 27 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
27 $loader->load('services.yml'); 28 $loader->load('services.yml');
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index e5c21679..24d1a57a 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -3,12 +3,15 @@
3namespace Wallabag\CoreBundle\Repository; 3namespace Wallabag\CoreBundle\Repository;
4 4
5use Doctrine\ORM\EntityRepository; 5use Doctrine\ORM\EntityRepository;
6use Doctrine\ORM\Query;
6use Pagerfanta\Adapter\DoctrineORMAdapter; 7use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Pagerfanta; 8use Pagerfanta\Pagerfanta;
8use Wallabag\CoreBundle\Entity\Tag; 9use Wallabag\CoreBundle\Entity\Tag;
9 10
10class EntryRepository extends EntityRepository 11class EntryRepository extends EntityRepository
11{ 12{
13 private $lifeTime;
14
12 /** 15 /**
13 * Return a query builder to used by other getBuilderFor* method. 16 * Return a query builder to used by other getBuilderFor* method.
14 * 17 *
@@ -308,4 +311,25 @@ class EntryRepository extends EntityRepository
308 311
309 return $qb->getQuery()->getSingleScalarResult(); 312 return $qb->getQuery()->getSingleScalarResult();
310 } 313 }
314
315 public function setLifeTime($lifeTime)
316 {
317 $this->lifeTime = $lifeTime;
318 }
319
320 /**
321 * Enable cache for a query.
322 *
323 * @param Query $query
324 *
325 * @return Query
326 */
327 public function enableCache(Query $query)
328 {
329 $query->useQueryCache(true);
330 $query->useResultCache(true);
331 $query->setResultCacheLifetime($this->lifeTime);
332
333 return $query;
334 }
311} 335}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index e95ef452..1c1457e7 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -81,6 +81,8 @@ services:
81 factory: [ "@doctrine.orm.default_entity_manager", getRepository ] 81 factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
82 arguments: 82 arguments:
83 - WallabagCoreBundle:Entry 83 - WallabagCoreBundle:Entry
84 calls:
85 - [ setLifeTime, [ "%wallabag_core.cache_lifetime%" ] ]
84 86
85 wallabag_core.tag_repository: 87 wallabag_core.tag_repository:
86 class: Wallabag\CoreBundle\Repository\TagRepository 88 class: Wallabag\CoreBundle\Repository\TagRepository
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..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';