]>
Commit | Line | Data |
---|---|---|
3f3fbef1 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
7244d6cb | 7 | use Symfony\Component\HttpFoundation\Request; |
7244d6cb | 8 | use Wallabag\CoreBundle\Entity\Entry; |
619cc453 JB |
9 | use Wallabag\CoreBundle\Entity\Tag; |
10 | use Wallabag\CoreBundle\Form\Type\NewTagType; | |
3f3fbef1 NL |
11 | |
12 | class 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 | ||
af497a64 NL |
68 | $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer')); |
69 | ||
70 | return $this->redirect($redirectUrl); | |
567421af TC |
71 | } |
72 | ||
3f3fbef1 NL |
73 | /** |
74 | * Shows tags for current user. | |
75 | * | |
76 | * @Route("/tag/list", name="tag") | |
77 | * | |
78 | * @return \Symfony\Component\HttpFoundation\Response | |
79 | */ | |
80 | public function showTagAction() | |
81 | { | |
82 | $tags = $this->getDoctrine() | |
83 | ->getRepository('WallabagCoreBundle:Tag') | |
2a007fe4 | 84 | ->findAllTags($this->getUser()->getId()); |
3f3fbef1 NL |
85 | |
86 | return $this->render( | |
87 | 'WallabagCoreBundle:Tag:tags.html.twig', | |
4094ea47 | 88 | [ |
8ce32af6 | 89 | 'tags' => $tags, |
4094ea47 | 90 | ] |
3f3fbef1 NL |
91 | ); |
92 | } | |
3f3fbef1 | 93 | } |