X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FTagController.php;h=707f3bbe3ea152a45964189baaf5f5ba313fbbfb;hb=f74061f1e1e70f8f1ec1fb72f7cf6e1ed388023c;hp=b6514ea6e68b9ff23018f740d012b69d599b791e;hpb=891456ba9a592a200d8b23029e8f4514d9803080;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index b6514ea6..707f3bbe 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')); @@ -86,12 +88,24 @@ class TagController extends Controller ->getRepository('WallabagCoreBundle:Tag') ->findAllTags($this->getUser()->getId()); - return $this->render( - 'WallabagCoreBundle:Tag:tags.html.twig', - [ - 'tags' => $tags, - ] - ); + $flatTags = []; + + foreach ($tags as $key => $tag) { + $nbEntries = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']); + + $flatTags[] = [ + 'id' => $tag['id'], + 'label' => $tag['label'], + 'slug' => $tag['slug'], + 'nbEntries' => $nbEntries, + ]; + } + + return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ + 'tags' => $flatTags, + ]); } /** @@ -105,7 +119,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 +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(), + ]); } }