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\Entity\Entry
;
9 use Wallabag\CoreBundle\Repository
;
10 use Wallabag\CoreBundle\Service\Extractor
;
11 use Wallabag\CoreBundle\Helper\Url
;
13 class EntryController
extends Controller
16 * @param Request $request
17 * @Route("/new", name="new_entry")
18 * @return \Symfony\Component\HttpFoundation\Response
20 public function addEntryAction(Request
$request)
25 $form = $this->createFormBuilder($entry)
27 ->add('save', 'submit')
30 $form->handleRequest($request);
32 if ($form->isValid()) {
33 $content = Extractor
::extract($entry->getUrl());
35 $entry->setTitle($content->getTitle());
36 $entry->setContent($content->getBody());
38 $em = $this->getDoctrine()->getManager();
42 $this->get('session')->getFlashBag()->add(
47 return $this->redirect($this->generateUrl('homepage'));
50 return $this->render('WallabagCoreBundle:Entry:new.html.twig', array(
51 'form' => $form->createView(),
56 * Shows unread entries for current user
58 * @Route("/unread", name="unread")
59 * @return \Symfony\Component\HttpFoundation\Response
61 public function showUnreadAction()
63 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
64 // TODO don't give the user ID like this
65 // TODO change pagination
66 $entries = $repository->findUnreadByUser(1, 0);
69 'WallabagCoreBundle:Entry:entries.html.twig',
70 array('entries' => $entries)
75 * Shows read entries for current user
77 * @Route("/archive", name="archive")
78 * @return \Symfony\Component\HttpFoundation\Response
80 public function showArchiveAction()
82 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
83 // TODO don't give the user ID like this
84 // TODO change pagination
85 $entries = $repository->findArchiveByUser(1, 0);
88 'WallabagCoreBundle:Entry:entries.html.twig',
89 array('entries' => $entries)
94 * Shows starred entries for current user
96 * @Route("/starred", name="starred")
97 * @return \Symfony\Component\HttpFoundation\Response
99 public function showStarredAction()
101 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
102 // TODO don't give the user ID like this
103 // TODO change pagination
104 $entries = $repository->findStarredByUser(1, 0);
106 return $this->render(
107 'WallabagCoreBundle:Entry:entries.html.twig',
108 array('entries' => $entries)
113 * Shows entry content
115 * @param Entry $entry
116 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
117 * @return \Symfony\Component\HttpFoundation\Response
119 public function viewAction(Entry
$entry)
121 return $this->render(
122 'WallabagCoreBundle:Entry:entry.html.twig',
123 array('entry' => $entry)
128 * Changes read status for an entry
130 * @param Request $request
131 * @param Entry $entry
132 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
133 * @return \Symfony\Component\HttpFoundation\RedirectResponse
135 public function toggleArchiveAction(Request
$request, Entry
$entry)
137 $entry->toggleArchive();
138 $this->getDoctrine()->getManager()->flush();
140 $this->get('session')->getFlashBag()->add(
145 return $this->redirect($request->headers
->get('referer'));
149 * Changes favorite status for an entry
151 * @param Request $request
152 * @param Entry $entry
153 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
154 * @return \Symfony\Component\HttpFoundation\RedirectResponse
156 public function toggleStarAction(Request
$request, Entry
$entry)
158 $entry->toggleStar();
159 $this->getDoctrine()->getManager()->flush();
161 $this->get('session')->getFlashBag()->add(
166 return $this->redirect($request->headers
->get('referer'));
172 * @param Request $request
173 * @param Entry $entry
174 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
175 * @return \Symfony\Component\HttpFoundation\RedirectResponse
177 public function deleteEntryAction(Request
$request, Entry
$entry)
179 $em = $this->getDoctrine()->getManager();
180 $entry->setDeleted(1);
181 $em->persist($entry);
184 $this->get('session')->getFlashBag()->add(
189 return $this->redirect($request->headers
->get('referer'));