3 namespace Wallabag\CoreBundle\Controller
;
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Wallabag\CoreBundle\Repository
;
9 use Wallabag\CoreBundle\Entity\Entries
;
10 use Wallabag\CoreBundle\Service\Extractor
;
11 use Wallabag\CoreBundle\Helper\Tools
;
12 use Wallabag\CoreBundle\Helper\Url
;
14 class EntryController
extends Controller
18 * @param Request $request
19 * @Route("/new", name="new_entry")
20 * @return \Symfony\Component\HttpFoundation\Response
22 public function addEntryAction(Request
$request)
24 $entry = new Entries();
27 $form = $this->createFormBuilder($entry)
29 ->add('save', 'submit')
32 $form->handleRequest($request);
34 if ($form->isValid()) {
36 $content = Extractor
::extract($entry->getUrl());
38 $entry->setTitle($content->getTitle());
39 $entry->setContent($content->getBody());
41 $em = $this->getDoctrine()->getManager();
45 $this->get('session')->getFlashBag()->add(
50 return $this->redirect($this->generateUrl('homepage'));
53 return $this->render('WallabagCoreBundle:Entry:new.html.twig', array(
54 'form' => $form->createView(),
59 * Shows unread entries for current user
61 * @Route("/unread", name="unread")
62 * @return \Symfony\Component\HttpFoundation\Response
64 public function showUnreadAction()
66 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
67 // TODO don't give the user ID like this
68 // TODO change pagination
69 $entries = $repository->findUnreadByUser(1, 0);
72 'WallabagCoreBundle:Entry:entries.html.twig',
73 array('entries' => $entries)
78 * Shows read entries for current user
80 * @Route("/archive", name="archive")
81 * @return \Symfony\Component\HttpFoundation\Response
83 public function showArchiveAction()
85 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
86 // TODO don't give the user ID like this
87 // TODO change pagination
88 $entries = $repository->findArchiveByUser(1, 0);
91 'WallabagCoreBundle:Entry:entries.html.twig',
92 array('entries' => $entries)
97 * Shows starred entries for current user
99 * @Route("/starred", name="starred")
100 * @return \Symfony\Component\HttpFoundation\Response
102 public function showStarredAction()
104 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
105 // TODO don't give the user ID like this
106 // TODO change pagination
107 $entries = $repository->findStarredByUser(1, 0);
109 return $this->render(
110 'WallabagCoreBundle:Entry:entries.html.twig',
111 array('entries' => $entries)
116 * Shows entry content
118 * @param Entries $entry
119 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
120 * @return \Symfony\Component\HttpFoundation\Response
122 public function viewAction(Entries
$entry)
124 return $this->render(
125 'WallabagCoreBundle:Entry:entry.html.twig',
126 array('entry' => $entry)
131 * Changes read status for an entry
133 * @param Request $request
134 * @param Entries $entry
135 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
136 * @return \Symfony\Component\HttpFoundation\RedirectResponse
138 public function toggleArchiveAction(Request
$request, Entries
$entry)
140 $entry->toggleArchive();
141 $this->getDoctrine()->getManager()->flush();
143 $this->get('session')->getFlashBag()->add(
148 return $this->redirect($request->headers
->get('referer'));
152 * Changes favorite status for an entry
154 * @param Request $request
155 * @param Entries $entry
156 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
157 * @return \Symfony\Component\HttpFoundation\RedirectResponse
159 public function toggleStarAction(Request
$request, Entries
$entry)
161 $entry->toggleStar();
162 $this->getDoctrine()->getManager()->flush();
164 $this->get('session')->getFlashBag()->add(
169 return $this->redirect($request->headers
->get('referer'));
175 * @param Request $request
176 * @param Entries $entry
177 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
178 * @return \Symfony\Component\HttpFoundation\RedirectResponse
180 public function deleteEntryAction(Request
$request, Entries
$entry)
182 $em = $this->getDoctrine()->getManager();
186 $this->get('session')->getFlashBag()->add(
191 return $this->redirect($request->headers
->get('referer'));