]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/TagController.php
Update bundle & stock file
[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 {
fc732227 23 $tag = new Tag();
5c895a7f 24 $form = $this->createForm(NewTagType::class, $tag);
7244d6cb
NL
25 $form->handleRequest($request);
26
27 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine()
29 ->getRepository('WallabagCoreBundle:Tag')
fc732227 30 ->findOneByLabel($tag->getLabel());
7244d6cb
NL
31
32 $em = $this->getDoctrine()->getManager();
33
34 if (is_null($existingTag)) {
35 $entry->addTag($tag);
36 $em->persist($tag);
fc732227
JB
37 } elseif (!$existingTag->hasEntry($entry)) {
38 $entry->addTag($existingTag);
39 $em->persist($existingTag);
7244d6cb
NL
40 }
41
42 $em->flush();
43
44 $this->get('session')->getFlashBag()->add(
45 'notice',
46 'Tag added'
47 );
48
49 return $this->redirect($this->generateUrl('view', array('id' => $entry->getId())));
50 }
51
52 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', array(
53 'form' => $form->createView(),
54 'entry' => $entry,
55 ));
56 }
57
3f3fbef1
NL
58 /**
59 * Shows tags for current user.
60 *
61 * @Route("/tag/list", name="tag")
62 *
63 * @return \Symfony\Component\HttpFoundation\Response
64 */
65 public function showTagAction()
66 {
67 $tags = $this->getDoctrine()
68 ->getRepository('WallabagCoreBundle:Tag')
69 ->findTags($this->getUser()->getId());
70
71 return $this->render(
72 'WallabagCoreBundle:Tag:tags.html.twig',
73 array(
8ce32af6 74 'tags' => $tags,
3f3fbef1
NL
75 )
76 );
77 }
3f3fbef1 78}