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