]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Controller/TagController.php
Update bundle & stock file
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / TagController.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Controller;
4
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 use Symfony\Component\HttpFoundation\Request;
8 use Wallabag\CoreBundle\Entity\Entry;
9 use Wallabag\CoreBundle\Entity\Tag;
10 use Wallabag\CoreBundle\Form\Type\NewTagType;
11
12 class TagController extends Controller
13 {
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 {
23 $tag = new Tag();
24 $form = $this->createForm(NewTagType::class, $tag);
25 $form->handleRequest($request);
26
27 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine()
29 ->getRepository('WallabagCoreBundle:Tag')
30 ->findOneByLabel($tag->getLabel());
31
32 $em = $this->getDoctrine()->getManager();
33
34 if (is_null($existingTag)) {
35 $entry->addTag($tag);
36 $em->persist($tag);
37 } elseif (!$existingTag->hasEntry($entry)) {
38 $entry->addTag($existingTag);
39 $em->persist($existingTag);
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
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(
74 'tags' => $tags,
75 )
76 );
77 }
78 }