aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/TagController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php54
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
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Pagerfanta\Adapter\ArrayAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
8use Wallabag\CoreBundle\Entity\Entry; 10use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag; 11use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\CoreBundle\Form\Type\NewTagType; 12use Wallabag\CoreBundle\Form\Type\NewTagType;
13use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
11 14
12class TagController extends Controller 15class 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}