]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add simple stats in footer 2323/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 1 Oct 2016 13:58:26 +0000 (15:58 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 1 Oct 2016 14:03:50 +0000 (16:03 +0200)
15 files changed:
app/config/services.yml
src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
src/Wallabag/CoreBundle/Twig/WallabagExtension.php
tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php

index 76bbce27c741b49aeae4898e87ca469305630d35..a57ef0f3d42e43f0d24c96dcb56183769d7b1b03 100644 (file)
@@ -21,6 +21,7 @@ services:
             - "@wallabag_core.tag_repository"
             - "@security.token_storage"
             - "%wallabag_core.cache_lifetime%"
+            - "@translator"
         tags:
             - { name: twig.extension }
 
index 7ad5c1002184c3e4d18ba713b766a49f6a74c880..f8526cfeb3f590df8bac3ba90a589136b6675927 100644 (file)
@@ -45,6 +45,7 @@ footer:
         # social: 'Social'
         # powered_by: 'powered by'
         about: 'Om'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Opsætning'
index 650e4761f37653b5268a62574b9a365208ec98f3..b0abe0cd343d9241f502cf7ea92585bcaabc3993 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Soziales'
         powered_by: 'angetrieben von'
         about: 'Über'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Einstellungen'
index d5842cc5249981cbce15ee5909287c37aff299f9..02fbd50795c0918d890a915253c75da8a6dd2597 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Social'
         powered_by: 'powered by'
         about: 'About'
+    stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Config'
index bd691c1c4e111e6ade3e1150aced688c688420c5..b7f6ab244ffca10f4b6cb9d928854e2be69fde64 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Social'
         powered_by: 'funciona por'
         about: 'Acerca de'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Configuración'
index a9989a8396cd00357ee76d93bf8f3b2f2ef385a1..e195a8c524873868ceb26d9cc0a7777ad518a4e2 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'شبکه‌های اجتماعی'
         powered_by: 'توانمند با'
         about: 'درباره'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'پیکربندی'
index b70ca64dfbe18ef345dd42c7c45a51e42f2986c4..9fe1855d78ac780e7ce2085771cb9209598f02c8 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Social'
         powered_by: 'propulsé par'
         about: 'À propos'
+    stats: Depuis le %user_creation% vous avez lu %nb_archives% articles. Ce qui fait %per_day% par jour !
 
 config:
     page_title: 'Configuration'
index 118098fe5f1de955f5e871fe7f382d572c686466..3425481374c1a48e4124e8af263ac8e2e8ca84ed 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Social'
         powered_by: 'powered by'
         about: 'About'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Configurazione'
index 93467dac33be6ee8decadbe9d3d8fc0eb6324504..f6cea17f6fbb840a3f1bbf040e24e854808fe5cb 100644 (file)
@@ -45,9 +45,10 @@ footer:
         social: 'Social'
         powered_by: 'propulsat per'
         about: 'A prepaus'
-    page_title: 'Configuracion'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
+    page_title: 'Configuracion'
     tab_menu:
         settings: 'Paramètres'
         rss: 'RSS'
index 27507a8111f01b360ec985343fd7abfdd68d3650..5fd12b101f41b85d914881a326d0891c1a67614e 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Społeczność'
         powered_by: 'Kontrolowany przez'
         about: 'O nas'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Konfiguracja'
index 7c77ffb729665212e3543fb7c195c6d89b99f2d2..9002b724464722cfc9bd7a73b6c38255a5b930c4 100644 (file)
@@ -45,6 +45,7 @@ footer:
         # social: 'Social'
         # powered_by: 'powered by'
         about: 'Despre'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Configurație'
index 8bc0c4b9519e8b0e47eb34a05cb01b69c1dcbf76..1121a2ef0729c47180adb93437ba47208c7cb4ae 100644 (file)
@@ -45,6 +45,7 @@ footer:
         social: 'Sosyal'
         powered_by: 'powered by'
         about: 'Hakkımızda'
+    # stats: Since %user_creation% you read %nb_archives% articles. That is about %per_day% a day!
 
 config:
     page_title: 'Yapılandırma'
index df05e2a4890bd5dfd5d4aa751ec5dfbf46436540..b2d77c2e2d81cf1f73c6cc1ebd583b9908292015 100644 (file)
     <footer class="page-footer cyan darken-2">
         <div class="footer-copyright">
             <div class="container">
-                <p>{{ 'footer.wallabag.powered_by'|trans }} <a target="_blank" href="https://wallabag.org" class="grey-text text-lighten-4">wallabag</a></p>
-                <a class="grey-text text-lighten-4 right" href="{{ path('about') }}">{{ 'footer.wallabag.about'|trans }}</a>
+                <div class="row">
+                    <div class="col s8">
+                        <p>
+                            {{ display_stats() }}
+                        </p>
+                    </div>
+                    <div class="col s4">
+                        <p>
+                            {{ 'footer.wallabag.powered_by'|trans }} <a target="_blank" href="https://wallabag.org" class="grey-text text-lighten-4">wallabag</a> –
+                            <a class="grey-text text-lighten-4" href="{{ path('about') }}">{{ 'footer.wallabag.about'|trans|lower }}</a>
+                        </p>
+                    </div>
+                </div>
             </div>
         </div>
     </footer>
index fb4c7412395f4affcb3b4b73f844ea06d498d4cc..783cde3e70897aedb877f45f8ad0562a5b68cc9b 100644 (file)
@@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Twig;
 use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
 use Wallabag\CoreBundle\Repository\EntryRepository;
 use Wallabag\CoreBundle\Repository\TagRepository;
+use Symfony\Component\Translation\TranslatorInterface;
 
 class WallabagExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
 {
@@ -12,13 +13,15 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
     private $entryRepository;
     private $tagRepository;
     private $lifeTime;
+    private $translator;
 
-    public function __construct(EntryRepository $entryRepository = null, TagRepository $tagRepository = null, TokenStorageInterface $tokenStorage = null, $lifeTime = 0)
+    public function __construct(EntryRepository $entryRepository, TagRepository $tagRepository, TokenStorageInterface $tokenStorage, $lifeTime, TranslatorInterface $translator)
     {
         $this->entryRepository = $entryRepository;
         $this->tagRepository = $tagRepository;
         $this->tokenStorage = $tokenStorage;
         $this->lifeTime = $lifeTime;
+        $this->translator = $translator;
     }
 
     public function getFilters()
@@ -33,6 +36,7 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
         return array(
             new \Twig_SimpleFunction('count_entries', [$this, 'countEntries']),
             new \Twig_SimpleFunction('count_tags', [$this, 'countTags']),
+            new \Twig_SimpleFunction('display_stats', [$this, 'displayStats']),
         );
     }
 
@@ -107,6 +111,40 @@ class WallabagExtension extends \Twig_Extension implements \Twig_Extension_Globa
         return $this->tagRepository->countAllTags($user->getId());
     }
 
+    /**
+     * Display a single line about reading stats.
+     *
+     * @return string
+     */
+    public function displayStats()
+    {
+        $user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
+
+        if (null === $user || !is_object($user)) {
+            return 0;
+        }
+
+        $query = $this->entryRepository->getBuilderForArchiveByUser($user->getId())
+            ->select('e.id')
+            ->groupBy('e.id')
+            ->getQuery();
+
+        $query->useQueryCache(true);
+        $query->useResultCache(true);
+        $query->setResultCacheLifetime($this->lifeTime);
+
+        $nbArchives = count($query->getArrayResult());
+
+        $interval = $user->getCreatedAt()->diff(new \DateTime('now'));
+        $nbDays = (int) $interval->format('%a') ?: 1;
+
+        return $this->translator->trans('footer.stats', [
+            '%user_creation%' => $user->getCreatedAt()->format('F jS, Y'),
+            '%nb_archives%' => $nbArchives,
+            '%per_day%' => round($nbArchives / $nbDays, 2),
+        ]);
+    }
+
     public function getName()
     {
         return 'wallabag_extension';
index 8ec2a75a228b1c202117525e7353f152dd1b1a50..b1c8c946315f4995918fdfbeca37798b39a572a3 100644 (file)
@@ -8,7 +8,23 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase
 {
     public function testRemoveWww()
     {
-        $extension = new WallabagExtension();
+        $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')
+            ->disableOriginalConstructor()
+            ->getMock();
+
+        $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator);
 
         $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr'));
         $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr'));