diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 8645fb44..bc95a4d3 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 | { |
@@ -81,7 +84,9 @@ class TagController extends Controller | |||
81 | { | 84 | { |
82 | $tags = $this->getDoctrine() | 85 | $tags = $this->getDoctrine() |
83 | ->getRepository('WallabagCoreBundle:Tag') | 86 | ->getRepository('WallabagCoreBundle:Tag') |
84 | ->findAllTags($this->getUser()->getId()); | 87 | ->findAllTags($this->getUser()->getId()) |
88 | ->getQuery() | ||
89 | ->getResult(); | ||
85 | 90 | ||
86 | return $this->render( | 91 | return $this->render( |
87 | 'WallabagCoreBundle:Tag:tags.html.twig', | 92 | 'WallabagCoreBundle:Tag:tags.html.twig', |
@@ -90,4 +95,45 @@ class TagController extends Controller | |||
90 | ] | 95 | ] |
91 | ); | 96 | ); |
92 | } | 97 | } |
98 | |||
99 | /** | ||
100 | * @param Tag $tag | ||
101 | * @param int $page | ||
102 | * | ||
103 | * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) | ||
104 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
105 | * | ||
106 | * @return \Symfony\Component\HttpFoundation\Response | ||
107 | */ | ||
108 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) | ||
109 | { | ||
110 | $entriesByTag = $this->getDoctrine() | ||
111 | ->getRepository('WallabagCoreBundle:Entry') | ||
112 | ->findAllByTagId($this->getUser()->getId(), $tag->getId()); | ||
113 | |||
114 | $pagerAdapter = new ArrayAdapter($entriesByTag); | ||
115 | |||
116 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') | ||
117 | ->prepare($pagerAdapter, $page); | ||
118 | |||
119 | try { | ||
120 | $entries->setCurrentPage($page); | ||
121 | } catch (OutOfRangeCurrentPageException $e) { | ||
122 | if ($page > 1) { | ||
123 | return $this->redirect($this->generateUrl($request->get('_route'), [ | ||
124 | 'slug' => $tag->getSlug(), | ||
125 | 'page' => $entries->getNbPages(), | ||
126 | ]), 302); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return $this->render( | ||
131 | 'WallabagCoreBundle:Entry:entries.html.twig', | ||
132 | [ | ||
133 | 'form' => null, | ||
134 | 'entries' => $entries, | ||
135 | 'currentPage' => $page, | ||
136 | ] | ||
137 | ); | ||
138 | } | ||
93 | } | 139 | } |