diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index a342ec0b..fd2069e0 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php | |||
@@ -4,10 +4,60 @@ namespace Wallabag\CoreBundle\Controller; | |||
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | ||
8 | use Wallabag\CoreBundle\Form\Type\NewTagType; | ||
9 | use Wallabag\CoreBundle\Entity\Tag; | ||
10 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | 11 | ||
8 | class TagController extends Controller | 12 | class TagController extends Controller |
9 | { | 13 | { |
10 | /** | 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($this->getUser()); | ||
24 | $form = $this->createForm(new NewTagType(), $tag); | ||
25 | $form->handleRequest($request); | ||
26 | |||
27 | if ($form->isValid()) { | ||
28 | $existingTag = $this->getDoctrine() | ||
29 | ->getRepository('WallabagCoreBundle:Tag') | ||
30 | ->findOneByLabelAndUserId($tag->getLabel(), $this->getUser()->getId()); | ||
31 | |||
32 | $em = $this->getDoctrine()->getManager(); | ||
33 | |||
34 | if (is_null($existingTag)) { | ||
35 | $entry->addTag($tag); | ||
36 | $em->persist($tag); | ||
37 | } else { | ||
38 | if (!$existingTag->hasEntry($entry)) { | ||
39 | $entry->addTag($existingTag); | ||
40 | $em->persist($existingTag); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | $em->flush(); | ||
45 | |||
46 | $this->get('session')->getFlashBag()->add( | ||
47 | 'notice', | ||
48 | 'Tag added' | ||
49 | ); | ||
50 | |||
51 | return $this->redirect($this->generateUrl('view', array('id' => $entry->getId()))); | ||
52 | } | ||
53 | |||
54 | return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', array( | ||
55 | 'form' => $form->createView(), | ||
56 | 'entry' => $entry, | ||
57 | )); | ||
58 | } | ||
59 | |||
60 | /** | ||
11 | * Shows tags for current user. | 61 | * Shows tags for current user. |
12 | * | 62 | * |
13 | * @Route("/tag/list", name="tag") | 63 | * @Route("/tag/list", name="tag") |