]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/TagController.php
Merge pull request #1916 from wallabag/cleanup
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / TagController.php
CommitLineData
3f3fbef1
NL
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7244d6cb 7use Symfony\Component\HttpFoundation\Request;
7244d6cb 8use Wallabag\CoreBundle\Entity\Entry;
619cc453
JB
9use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\CoreBundle\Form\Type\NewTagType;
3f3fbef1
NL
11
12class TagController extends Controller
13{
7244d6cb
NL
14 /**
15 * @param Request $request
4094ea47 16 * @param Entry $entry
7244d6cb
NL
17 *
18 * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag")
19 *
20 * @return \Symfony\Component\HttpFoundation\Response
21 */
22 public function addTagFormAction(Request $request, Entry $entry)
23 {
2baca964 24 $form = $this->createForm(NewTagType::class, new Tag());
7244d6cb
NL
25 $form->handleRequest($request);
26
27 if ($form->isValid()) {
2baca964
JB
28 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
29 $entry,
30 $form->get('label')->getData()
31 );
7244d6cb
NL
32
33 $em = $this->getDoctrine()->getManager();
2baca964 34 $em->persist($entry);
7244d6cb
NL
35 $em->flush();
36
37 $this->get('session')->getFlashBag()->add(
38 'notice',
4204a06b 39 'flashes.tag.notice.tag_added'
7244d6cb
NL
40 );
41
4094ea47 42 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
7244d6cb
NL
43 }
44
4094ea47 45 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', [
7244d6cb
NL
46 'form' => $form->createView(),
47 'entry' => $entry,
4094ea47 48 ]);
7244d6cb
NL
49 }
50
567421af
TC
51 /**
52 * Removes tag from entry.
53 *
54 * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
55 *
56 * @return \Symfony\Component\HttpFoundation\Response
57 */
58 public function removeTagFromEntry(Request $request, Entry $entry, Tag $tag)
59 {
60 $entry->removeTag($tag);
61 $em = $this->getDoctrine()->getManager();
62 $em->flush();
63 if (count($tag->getEntries()) == 0) {
64 $em->remove($tag);
65 }
66 $em->flush();
67
68 return $this->redirect($request->headers->get('referer'));
69 }
70
3f3fbef1
NL
71 /**
72 * Shows tags for current user.
73 *
74 * @Route("/tag/list", name="tag")
75 *
76 * @return \Symfony\Component\HttpFoundation\Response
77 */
78 public function showTagAction()
79 {
80 $tags = $this->getDoctrine()
81 ->getRepository('WallabagCoreBundle:Tag')
82 ->findTags($this->getUser()->getId());
83
84 return $this->render(
85 'WallabagCoreBundle:Tag:tags.html.twig',
4094ea47 86 [
8ce32af6 87 'tags' => $tags,
4094ea47 88 ]
3f3fbef1
NL
89 );
90 }
3f3fbef1 91}