diff options
7 files changed, 88 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ccdf9406..93db0d6c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\Controller; | |||
4 | 4 | ||
5 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 5 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Pagerfanta\Pagerfanta; | ||
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
@@ -257,9 +256,10 @@ class EntryController extends Controller | |||
257 | } | 256 | } |
258 | 257 | ||
259 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); | 258 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); |
260 | $entries = new Pagerfanta($pagerAdapter); | ||
261 | 259 | ||
262 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); | 260 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') |
261 | ->prepare($pagerAdapter, $page); | ||
262 | |||
263 | try { | 263 | try { |
264 | $entries->setCurrentPage($page); | 264 | $entries->setCurrentPage($page); |
265 | } catch (OutOfRangeCurrentPageException $e) { | 265 | } catch (OutOfRangeCurrentPageException $e) { |
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index 944c755d..959b308d 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php | |||
@@ -46,7 +46,7 @@ class ExportController extends Controller | |||
46 | * | 46 | * |
47 | * @Route("/export/{category}.{format}", name="export_entries", requirements={ | 47 | * @Route("/export/{category}.{format}", name="export_entries", requirements={ |
48 | * "format": "epub|mobi|pdf|json|xml|txt|csv", | 48 | * "format": "epub|mobi|pdf|json|xml|txt|csv", |
49 | * "category": "all|unread|starred|archive" | 49 | * "category": "all|unread|starred|archive|tag_entries" |
50 | * }) | 50 | * }) |
51 | * | 51 | * |
52 | * @return \Symfony\Component\HttpFoundation\Response | 52 | * @return \Symfony\Component\HttpFoundation\Response |
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 8645fb44..b6514ea6 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -2,12 +2,15 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Pagerfanta\Adapter\ArrayAdapter; | ||
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\CoreBundle\Entity\Entry; | 10 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Entity\Tag; | 11 | use Wallabag\CoreBundle\Entity\Tag; |
10 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 12 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
13 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
11 | 14 | ||
12 | class TagController extends Controller | 15 | class TagController extends Controller |
13 | { | 16 | { |
@@ -90,4 +93,41 @@ class TagController extends Controller | |||
90 | ] | 93 | ] |
91 | ); | 94 | ); |
92 | } | 95 | } |
96 | |||
97 | /** | ||
98 | * @param Tag $tag | ||
99 | * @param int $page | ||
100 | * | ||
101 | * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) | ||
102 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
103 | * | ||
104 | * @return \Symfony\Component\HttpFoundation\Response | ||
105 | */ | ||
106 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) | ||
107 | { | ||
108 | $pagerAdapter = new ArrayAdapter($tag->getEntries()->toArray()); | ||
109 | |||
110 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') | ||
111 | ->prepare($pagerAdapter, $page); | ||
112 | |||
113 | try { | ||
114 | $entries->setCurrentPage($page); | ||
115 | } catch (OutOfRangeCurrentPageException $e) { | ||
116 | if ($page > 1) { | ||
117 | return $this->redirect($this->generateUrl($request->get('_route'), [ | ||
118 | 'slug' => $tag->getSlug(), | ||
119 | 'page' => $entries->getNbPages(), | ||
120 | ]), 302); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | return $this->render( | ||
125 | 'WallabagCoreBundle:Entry:entries.html.twig', | ||
126 | [ | ||
127 | 'form' => null, | ||
128 | 'entries' => $entries, | ||
129 | 'currentPage' => $page, | ||
130 | ] | ||
131 | ); | ||
132 | } | ||
93 | } | 133 | } |
diff --git a/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php new file mode 100644 index 00000000..f9066bee --- /dev/null +++ b/src/Wallabag/CoreBundle/Helper/PreparePagerForEntries.php | |||
@@ -0,0 +1,34 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Pagerfanta\Adapter\AdapterInterface; | ||
6 | use Pagerfanta\Pagerfanta; | ||
7 | use Symfony\Component\Routing\Router; | ||
8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | ||
9 | |||
10 | class PreparePagerForEntries | ||
11 | { | ||
12 | private $user; | ||
13 | private $router; | ||
14 | |||
15 | public function __construct(TokenStorage $token, Router $router) | ||
16 | { | ||
17 | $this->user = $token->getToken()->getUser(); | ||
18 | $this->router = $router; | ||
19 | } | ||
20 | |||
21 | /** | ||
22 | * @param AdapterInterface $adapter | ||
23 | * @param int $page | ||
24 | * | ||
25 | * @return null|Pagerfanta | ||
26 | */ | ||
27 | public function prepare(AdapterInterface $adapter, $page = 1) | ||
28 | { | ||
29 | $entries = new Pagerfanta($adapter); | ||
30 | $entries->setMaxPerPage($this->user->getConfig()->getItemsPerPage()); | ||
31 | |||
32 | return $entries; | ||
33 | } | ||
34 | } | ||
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index f8835198..e95ef452 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -119,3 +119,9 @@ services: | |||
119 | class: Wallabag\CoreBundle\Helper\Redirect | 119 | class: Wallabag\CoreBundle\Helper\Redirect |
120 | arguments: | 120 | arguments: |
121 | - "@router" | 121 | - "@router" |
122 | |||
123 | wallabag_core.helper.prepare_pager_for_entries: | ||
124 | class: Wallabag\CoreBundle\Helper\PreparePagerForEntries | ||
125 | arguments: | ||
126 | - "@security.token_storage" | ||
127 | - "@router" | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig index eca8924e..a0a0b02f 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Entry/entries.html.twig | |||
@@ -122,6 +122,7 @@ | |||
122 | </div> | 122 | </div> |
123 | 123 | ||
124 | <!-- Filters --> | 124 | <!-- Filters --> |
125 | {% if form is not null %} | ||
125 | <div id="filters" class="side-nav fixed right-aligned"> | 126 | <div id="filters" class="side-nav fixed right-aligned"> |
126 | <form action="{{ path('all') }}"> | 127 | <form action="{{ path('all') }}"> |
127 | 128 | ||
@@ -205,5 +206,6 @@ | |||
205 | 206 | ||
206 | </form> | 207 | </form> |
207 | </div> | 208 | </div> |
208 | {% include "WallabagCoreBundle:Entry:pager.html.twig" with {'entries': entries} %} | 209 | {% endif %} |
210 | |||
209 | {% endblock %} | 211 | {% endblock %} |
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig index d958c4b8..9495f543 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Tag/tags.html.twig | |||
@@ -9,7 +9,7 @@ | |||
9 | <br /> | 9 | <br /> |
10 | <ul class="row data"> | 10 | <ul class="row data"> |
11 | {% for tag in tags %} | 11 | {% for tag in tags %} |
12 | <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12">{{tag.label}} ({{ tag.getEntriesByUserId(app.user.id) | length }})</li> | 12 | <li id="tag-{{ tag.id|e }}" class="col l4 m6 s12"><a href="{{ path('tag_entries', {'slug': tag.slug}) }}">{{tag.label}} ({{ tag.entries.getValues | length }})</a></li> |
13 | {% endfor %} | 13 | {% endfor %} |
14 | </ul> | 14 | </ul> |
15 | {% endblock %} | 15 | {% endblock %} |