aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/TagController.php
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-10-23 11:09:17 +0200
committerGitHub <noreply@github.com>2017-10-23 11:09:17 +0200
commit1953a872932a63792293b4aec087880265ba89f7 (patch)
treefd16599e737fcdaf193c933ef3ec4a4ee248b117 /src/Wallabag/CoreBundle/Controller/TagController.php
parentd83d25dadec2c38460a32d96f5d2903426fec9d3 (diff)
parent702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff)
downloadwallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz
wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst
wallabag-1953a872932a63792293b4aec087880265ba89f7.zip
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php42
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
5use Pagerfanta\Adapter\ArrayAdapter; 5use Pagerfanta\Adapter\ArrayAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Bundle\FrameworkBundle\Controller\Controller; 9use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9use Symfony\Component\HttpFoundation\Request; 10use Symfony\Component\HttpFoundation\Request;
10use Wallabag\CoreBundle\Entity\Entry; 11use Wallabag\CoreBundle\Entity\Entry;
11use Wallabag\CoreBundle\Entity\Tag; 12use Wallabag\CoreBundle\Entity\Tag;
12use Wallabag\CoreBundle\Form\Type\NewTagType; 13use Wallabag\CoreBundle\Form\Type\NewTagType;
13use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
14 14
15class TagController extends Controller 15class 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}