diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index b6d28e59..a6ad131f 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -5,19 +5,17 @@ namespace Wallabag\CoreBundle\Controller; | |||
5 | use Pagerfanta\Adapter\ArrayAdapter; | 5 | use Pagerfanta\Adapter\ArrayAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\Routing\Annotation\Route; | ||
11 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
12 | use Wallabag\CoreBundle\Entity\Tag; | 12 | use Wallabag\CoreBundle\Entity\Tag; |
13 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 13 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
14 | use Wallabag\CoreBundle\Form\Type\RenameTagType; | ||
14 | 15 | ||
15 | class TagController extends Controller | 16 | class TagController extends Controller |
16 | { | 17 | { |
17 | /** | 18 | /** |
18 | * @param Request $request | ||
19 | * @param Entry $entry | ||
20 | * | ||
21 | * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag") | 19 | * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag") |
22 | * | 20 | * |
23 | * @return \Symfony\Component\HttpFoundation\Response | 21 | * @return \Symfony\Component\HttpFoundation\Response |
@@ -86,14 +84,22 @@ class TagController extends Controller | |||
86 | { | 84 | { |
87 | $tags = $this->get('wallabag_core.tag_repository') | 85 | $tags = $this->get('wallabag_core.tag_repository') |
88 | ->findAllFlatTagsWithNbEntries($this->getUser()->getId()); | 86 | ->findAllFlatTagsWithNbEntries($this->getUser()->getId()); |
87 | $nbEntriesUntagged = $this->get('wallabag_core.entry_repository') | ||
88 | ->countUntaggedEntriesByUser($this->getUser()->getId()); | ||
89 | |||
90 | $renameForms = []; | ||
91 | foreach ($tags as $tag) { | ||
92 | $renameForms[$tag['id']] = $this->createForm(RenameTagType::class, new Tag())->createView(); | ||
93 | } | ||
89 | 94 | ||
90 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ | 95 | return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ |
91 | 'tags' => $tags, | 96 | 'tags' => $tags, |
97 | 'renameForms' => $renameForms, | ||
98 | 'nbEntriesUntagged' => $nbEntriesUntagged, | ||
92 | ]); | 99 | ]); |
93 | } | 100 | } |
94 | 101 | ||
95 | /** | 102 | /** |
96 | * @param Tag $tag | ||
97 | * @param int $page | 103 | * @param int $page |
98 | * | 104 | * |
99 | * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) | 105 | * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) |
@@ -130,4 +136,45 @@ class TagController extends Controller | |||
130 | 'tag' => $tag, | 136 | 'tag' => $tag, |
131 | ]); | 137 | ]); |
132 | } | 138 | } |
139 | |||
140 | /** | ||
141 | * Rename a given tag with a new label | ||
142 | * Create a new tag with the new name and drop the old one. | ||
143 | * | ||
144 | * @Route("/tag/rename/{slug}", name="tag_rename") | ||
145 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | ||
146 | * | ||
147 | * @return \Symfony\Component\HttpFoundation\Response | ||
148 | */ | ||
149 | public function renameTagAction(Tag $tag, Request $request) | ||
150 | { | ||
151 | $form = $this->createForm(RenameTagType::class, new Tag()); | ||
152 | $form->handleRequest($request); | ||
153 | |||
154 | if ($form->isSubmitted() && $form->isValid()) { | ||
155 | $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( | ||
156 | $this->getUser()->getId(), | ||
157 | $tag->getId() | ||
158 | ); | ||
159 | foreach ($entries as $entry) { | ||
160 | $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( | ||
161 | $entry, | ||
162 | $form->get('label')->getData() | ||
163 | ); | ||
164 | $entry->removeTag($tag); | ||
165 | } | ||
166 | |||
167 | $em = $this->getDoctrine()->getManager(); | ||
168 | $em->flush(); | ||
169 | } | ||
170 | |||
171 | $this->get('session')->getFlashBag()->add( | ||
172 | 'notice', | ||
173 | 'flashes.tag.notice.tag_renamed' | ||
174 | ); | ||
175 | |||
176 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); | ||
177 | |||
178 | return $this->redirect($redirectUrl); | ||
179 | } | ||
133 | } | 180 | } |