diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 40 |
1 files changed, 40 insertions, 0 deletions
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 | } |