diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 623a6146..5acc6852 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -63,10 +63,12 @@ class TagController extends Controller | |||
63 | $entry->removeTag($tag); | 63 | $entry->removeTag($tag); |
64 | $em = $this->getDoctrine()->getManager(); | 64 | $em = $this->getDoctrine()->getManager(); |
65 | $em->flush(); | 65 | $em->flush(); |
66 | if (count($tag->getEntries()) == 0) { | 66 | |
67 | // remove orphan tag in case no entries are associated to it | ||
68 | if (count($tag->getEntries()) === 0) { | ||
67 | $em->remove($tag); | 69 | $em->remove($tag); |
70 | $em->flush(); | ||
68 | } | 71 | } |
69 | $em->flush(); | ||
70 | 72 | ||
71 | $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')); |
72 | 74 | ||
@@ -84,10 +86,25 @@ class TagController extends Controller | |||
84 | { | 86 | { |
85 | $tags = $this->getDoctrine() | 87 | $tags = $this->getDoctrine() |
86 | ->getRepository('WallabagCoreBundle:Tag') | 88 | ->getRepository('WallabagCoreBundle:Tag') |
87 | ->findAllTagsWithEntries($this->getUser()->getId()); | 89 | ->findAllTags($this->getUser()->getId()); |
90 | |||
91 | $flatTags = []; | ||
92 | |||
93 | foreach ($tags as $key => $tag) { | ||
94 | $nbEntries = $this->getDoctrine() | ||
95 | ->getRepository('WallabagCoreBundle:Entry') | ||
96 | ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag['id']); | ||
97 | |||
98 | $flatTags[] = [ | ||
99 | 'id' => $tag['id'], | ||
100 | 'label' => $tag['label'], | ||
101 | 'slug' => $tag['slug'], | ||
102 | 'nbEntries' => $nbEntries, | ||
103 | ]; | ||
104 | } | ||
88 | 105 | ||
89 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ | 106 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ |
90 | 'tags' => $tags, | 107 | 'tags' => $flatTags, |
91 | ]); | 108 | ]); |
92 | } | 109 | } |
93 | 110 | ||