X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FTagController.php;h=a3e70fd0aeabf2661d15560b1e40142836fd2357;hb=5a619812ca3eb05a82a023ccdaee13501eb8d45f;hp=bc95a4d34ac4e6bda9e265c120b43d63397b4e3e;hpb=d7b4b2c72cd1c9ad967ecfec668d5b0b9e794149;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index bc95a4d3..a3e70fd0 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -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,16 +86,26 @@ class TagController extends Controller { $tags = $this->getDoctrine() ->getRepository('WallabagCoreBundle:Tag') - ->findAllTags($this->getUser()->getId()) - ->getQuery() - ->getResult(); - - return $this->render( - 'WallabagCoreBundle:Tag:tags.html.twig', - [ - 'tags' => $tags, - ] - ); + ->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' => $flatTags, + ]); } /** @@ -127,13 +139,11 @@ 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, + 'tag' => $tag->getLabel(), + ]); } }