diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 8a093289..616c37f2 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -4,13 +4,13 @@ namespace Wallabag\CoreBundle\Controller; | |||
4 | 4 | ||
5 | use Pagerfanta\Adapter\ArrayAdapter; | 5 | use Pagerfanta\Adapter\ArrayAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
9 | use Symfony\Component\HttpFoundation\Request; | 10 | use Symfony\Component\HttpFoundation\Request; |
10 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
11 | use Wallabag\CoreBundle\Entity\Tag; | 12 | use Wallabag\CoreBundle\Entity\Tag; |
12 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 13 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
13 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
14 | 14 | ||
15 | class TagController extends Controller | 15 | class TagController extends Controller |
16 | { | 16 | { |
@@ -28,7 +28,7 @@ class TagController extends Controller | |||
28 | $form->handleRequest($request); | 28 | $form->handleRequest($request); |
29 | 29 | ||
30 | if ($form->isSubmitted() && $form->isValid()) { | 30 | if ($form->isSubmitted() && $form->isValid()) { |
31 | $this->get('wallabag_core.content_proxy')->assignTagsToEntry( | 31 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( |
32 | $entry, | 32 | $entry, |
33 | $form->get('label')->getData() | 33 | $form->get('label')->getData() |
34 | ); | 34 | ); |
@@ -65,12 +65,12 @@ class TagController extends Controller | |||
65 | $em->flush(); | 65 | $em->flush(); |
66 | 66 | ||
67 | // remove orphan tag in case no entries are associated to it | 67 | // remove orphan tag in case no entries are associated to it |
68 | if (count($tag->getEntries()) === 0) { | 68 | if (0 === count($tag->getEntries())) { |
69 | $em->remove($tag); | 69 | $em->remove($tag); |
70 | $em->flush(); | 70 | $em->flush(); |
71 | } | 71 | } |
72 | 72 | ||
73 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); | 73 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); |
74 | 74 | ||
75 | return $this->redirect($redirectUrl); | 75 | return $this->redirect($redirectUrl); |
76 | } | 76 | } |
@@ -84,27 +84,11 @@ class TagController extends Controller | |||
84 | */ | 84 | */ |
85 | public function showTagAction() | 85 | public function showTagAction() |
86 | { | 86 | { |
87 | $tags = $this->getDoctrine() | 87 | $tags = $this->get('wallabag_core.tag_repository') |
88 | ->getRepository('WallabagCoreBundle:Tag') | 88 | ->findAllFlatTagsWithNbEntries($this->getUser()->getId()); |
89 | ->findAllTags($this->getUser()->getId()); | ||
90 | |||
91 | $flatTags = []; | ||
92 | |||
93 | foreach ($tags as $tag) { | ||
94 | $nbEntries = $this->getDoctrine() | ||
95 | ->getRepository('WallabagCoreBundle:Entry') | ||
96 | ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId()); | ||
97 | |||
98 | $flatTags[] = [ | ||
99 | 'id' => $tag->getId(), | ||
100 | 'label' => $tag->getLabel(), | ||
101 | 'slug' => $tag->getSlug(), | ||
102 | 'nbEntries' => $nbEntries, | ||
103 | ]; | ||
104 | } | ||
105 | 89 | ||
106 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ | 90 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ |
107 | 'tags' => $flatTags, | 91 | 'tags' => $tags, |
108 | ]); | 92 | ]); |
109 | } | 93 | } |
110 | 94 | ||
@@ -119,14 +103,14 @@ class TagController extends Controller | |||
119 | */ | 103 | */ |
120 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) | 104 | public function showEntriesForTagAction(Tag $tag, $page, Request $request) |
121 | { | 105 | { |
122 | $entriesByTag = $this->getDoctrine() | 106 | $entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId( |
123 | ->getRepository('WallabagCoreBundle:Entry') | 107 | $this->getUser()->getId(), |
124 | ->findAllByTagId($this->getUser()->getId(), $tag->getId()); | 108 | $tag->getId() |
109 | ); | ||
125 | 110 | ||
126 | $pagerAdapter = new ArrayAdapter($entriesByTag); | 111 | $pagerAdapter = new ArrayAdapter($entriesByTag); |
127 | 112 | ||
128 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') | 113 | $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter); |
129 | ->prepare($pagerAdapter, $page); | ||
130 | 114 | ||
131 | try { | 115 | try { |
132 | $entries->setCurrentPage($page); | 116 | $entries->setCurrentPage($page); |
@@ -143,7 +127,7 @@ class TagController extends Controller | |||
143 | 'form' => null, | 127 | 'form' => null, |
144 | 'entries' => $entries, | 128 | 'entries' => $entries, |
145 | 'currentPage' => $page, | 129 | 'currentPage' => $page, |
146 | 'tag' => $tag->getSlug(), | 130 | 'tag' => $tag, |
147 | ]); | 131 | ]); |
148 | } | 132 | } |
149 | } | 133 | } |