]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/TagController.php
Merge pull request #2393 from wallabag/api-urls-exist
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / TagController.php
index b6514ea6e68b9ff23018f740d012b69d599b791e..c5746734d398fd2653a64ade83d66d150acbbafe 100644 (file)
@@ -63,10 +63,12 @@ class TagController extends Controller
         $entry->removeTag($tag);
         $em = $this->getDoctrine()->getManager();
         $em->flush();
-        if (count($tag->getEntries()) == 0) {
+
+        // remove orphan tag in case no entries are associated to it
+        if (count($tag->getEntries()) === 0) {
             $em->remove($tag);
+            $em->flush();
         }
-        $em->flush();
 
         $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
 
@@ -84,14 +86,11 @@ class TagController extends Controller
     {
         $tags = $this->getDoctrine()
             ->getRepository('WallabagCoreBundle:Tag')
-            ->findAllTags($this->getUser()->getId());
-
-        return $this->render(
-            'WallabagCoreBundle:Tag:tags.html.twig',
-            [
-                'tags' => $tags,
-            ]
-        );
+            ->findAllTagsWithEntries($this->getUser()->getId());
+
+        return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
+            'tags' => $tags,
+        ]);
     }
 
     /**
@@ -105,7 +104,11 @@ class TagController extends Controller
      */
     public function showEntriesForTagAction(Tag $tag, $page, Request $request)
     {
-        $pagerAdapter = new ArrayAdapter($tag->getEntries()->toArray());
+        $entriesByTag = $this->getDoctrine()
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findAllByTagId($this->getUser()->getId(), $tag->getId());
+
+        $pagerAdapter = new ArrayAdapter($entriesByTag);
 
         $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
             ->prepare($pagerAdapter, $page);
@@ -121,13 +124,10 @@ class TagController extends Controller
             }
         }
 
-        return $this->render(
-            'WallabagCoreBundle:Entry:entries.html.twig',
-            [
-                'form' => null,
-                'entries' => $entries,
-                'currentPage' => $page,
-            ]
-        );
+        return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [
+            'form' => null,
+            'entries' => $entries,
+            'currentPage' => $page,
+        ]);
     }
 }