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)
22 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:User');
23 $user = $repository->find(1);
24 $entry = new Entry($user);
26 $form = $this->createFormBuilder($entry)
28 ->add('save', 'submit')
31 $form->handleRequest($request);
33 if ($form->isValid()) {
34 $content = Extractor
::extract($entry->getUrl());
36 $entry->setTitle($content->getTitle());
37 $entry->setContent($content->getBody());
39 $em = $this->getDoctrine()->getManager();
43 $this->get('session')->getFlashBag()->add(
48 return $this->redirect($this->generateUrl('homepage'));
51 return $this->render('WallabagCoreBundle:Entry:new.html.twig', array(
52 'form' => $form->createView(),
57 * Shows unread entries for current user
59 * @Route("/unread", name="unread")
60 * @return \Symfony\Component\HttpFoundation\Response
62 public function showUnreadAction()
64 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
65 // TODO don't give the user ID like this
66 // TODO change pagination
67 $entries = $repository->findUnreadByUser(1, 0);
70 'WallabagCoreBundle:Entry:entries.html.twig',
71 array('entries' => $entries)
76 * Shows read entries for current user
78 * @Route("/archive", name="archive")
79 * @return \Symfony\Component\HttpFoundation\Response
81 public function showArchiveAction()
83 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
84 // TODO don't give the user ID like this
85 // TODO change pagination
86 $entries = $repository->findArchiveByUser(1, 0);
89 'WallabagCoreBundle:Entry:entries.html.twig',
90 array('entries' => $entries)
95 * Shows starred entries for current user
97 * @Route("/starred", name="starred")
98 * @return \Symfony\Component\HttpFoundation\Response
100 public function showStarredAction()
102 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
103 // TODO don't give the user ID like this
104 // TODO change pagination
105 $entries = $repository->findStarredByUser(1, 0);
107 return $this->render(
108 'WallabagCoreBundle:Entry:entries.html.twig',
109 array('entries' => $entries)
114 * Shows entry content
116 * @param Entry $entry
117 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
118 * @return \Symfony\Component\HttpFoundation\Response
120 public function viewAction(Entry
$entry)
122 return $this->render(
123 'WallabagCoreBundle:Entry:entry.html.twig',
124 array('entry' => $entry)
129 * Changes read status for an entry
131 * @param Request $request
132 * @param Entry $entry
133 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
134 * @return \Symfony\Component\HttpFoundation\RedirectResponse
136 public function toggleArchiveAction(Request
$request, Entry
$entry)
138 $entry->toggleArchive();
139 $this->getDoctrine()->getManager()->flush();
141 $this->get('session')->getFlashBag()->add(
146 return $this->redirect($request->headers
->get('referer'));
150 * Changes favorite status for an entry
152 * @param Request $request
153 * @param Entry $entry
154 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
155 * @return \Symfony\Component\HttpFoundation\RedirectResponse
157 public function toggleStarAction(Request
$request, Entry
$entry)
159 $entry->toggleStar();
160 $this->getDoctrine()->getManager()->flush();
162 $this->get('session')->getFlashBag()->add(
167 return $this->redirect($request->headers
->get('referer'));
173 * @param Request $request
174 * @param Entry $entry
175 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
176 * @return \Symfony\Component\HttpFoundation\RedirectResponse
178 public function deleteEntryAction(Request
$request, Entry
$entry)
180 $em = $this->getDoctrine()->getManager();
181 $entry->setDeleted(1);
182 $em->persist($entry);
185 $this->get('session')->getFlashBag()->add(
190 return $this->redirect($request->headers
->get('referer'));