3 namespace Wallabag\CoreBundle\Controller
;
5 use Pagerfanta\Adapter\ArrayAdapter
;
6 use Pagerfanta\Exception\OutOfRangeCurrentPageException
;
7 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
8 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
9 use Symfony\Component\HttpFoundation\Request
;
10 use Wallabag\CoreBundle\Entity\Entry
;
11 use Wallabag\CoreBundle\Entity\Tag
;
12 use Wallabag\CoreBundle\Form\Type\NewTagType
;
13 use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter
;
15 class TagController
extends Controller
18 * @param Request $request
21 * @Route("/new-tag/{entry}", requirements={"entry" = "\d+"}, name="new_tag")
23 * @return \Symfony\Component\HttpFoundation\Response
25 public function addTagFormAction(Request
$request, Entry
$entry)
27 $form = $this->createForm(NewTagType
::class, new Tag());
28 $form->handleRequest($request);
30 if ($form->isValid()) {
31 $this->get('wallabag_core.content_proxy')->assignTagsToEntry(
33 $form->get('label')->getData()
36 $em = $this->getDoctrine()->getManager();
40 $this->get('session')->getFlashBag()->add(
42 'flashes.tag.notice.tag_added'
45 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
48 return $this->render('WallabagCoreBundle:Tag:new_form.html.twig', [
49 'form' => $form->createView(),
55 * Removes tag from entry.
57 * @Route("/remove-tag/{entry}/{tag}", requirements={"entry" = "\d+", "tag" = "\d+"}, name="remove_tag")
59 * @return \Symfony\Component\HttpFoundation\Response
61 public function removeTagFromEntry(Request
$request, Entry
$entry, Tag
$tag)
63 $entry->removeTag($tag);
64 $em = $this->getDoctrine()->getManager();
66 if (count($tag->getEntries()) == 0) {
71 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers
->get('referer'));
73 return $this->redirect($redirectUrl);
77 * Shows tags for current user.
79 * @Route("/tag/list", name="tag")
81 * @return \Symfony\Component\HttpFoundation\Response
83 public function showTagAction()
85 $tags = $this->getDoctrine()
86 ->getRepository('WallabagCoreBundle:Tag')
87 ->findAllTagsWithEntries($this->getUser()->getId());
89 return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
98 * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"})
99 * @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
101 * @return \Symfony\Component\HttpFoundation\Response
103 public function showEntriesForTagAction(Tag
$tag, $page, Request
$request)
105 $entriesByTag = $this->getDoctrine()
106 ->getRepository('WallabagCoreBundle:Entry')
107 ->findAllByTagId($this->getUser()->getId(), $tag->getId());
109 $pagerAdapter = new ArrayAdapter($entriesByTag);
111 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
112 ->prepare($pagerAdapter, $page);
115 $entries->setCurrentPage($page);
116 } catch (OutOfRangeCurrentPageException
$e) {
118 return $this->redirect($this->generateUrl($request->get('_route'), [
119 'slug' => $tag->getSlug(),
120 'page' => $entries->getNbPages(),
125 return $this->render('WallabagCoreBundle:Entry:entries.html.twig', [
127 'entries' => $entries,
128 'currentPage' => $page,