]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/TagController.php
Merge remote-tracking branch 'origin/master' into 2.2
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / TagController.php
index 07cd3edb3e333a1cd7f7ea86de927844d6a4349c..a3e70fd0aeabf2661d15560b1e40142836fd2357 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,10 +86,25 @@ class TagController extends Controller
     {
         $tags = $this->getDoctrine()
             ->getRepository('WallabagCoreBundle:Tag')
-            ->findAllTagsWithEntries($this->getUser()->getId());
+            ->findAllTags($this->getUser()->getId());
+
+        $flatTags = [];
+
+        foreach ($tags as $tag) {
+            $nbEntries = $this->getDoctrine()
+                ->getRepository('WallabagCoreBundle:Entry')
+                ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId());
+
+            $flatTags[] = [
+                'id' => $tag->getId(),
+                'label' => $tag->getLabel(),
+                'slug' => $tag->getSlug(),
+                'nbEntries' => $nbEntries,
+            ];
+        }
 
         return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
-            'tags' => $tags,
+            'tags' => $flatTags,
         ]);
     }
 
@@ -122,10 +139,11 @@ class TagController extends Controller
             }
         }
 
-        return $this->render('WallabagCoreBundle:Entry:entries.html.twig',[
+        return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [
             'form' => null,
             'entries' => $entries,
             'currentPage' => $page,
+            'tag' => $tag->getLabel(),
         ]);
     }
 }