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