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 $entry = new Entry($this->getUser());
24 $form = $this->createFormBuilder($entry)
26 ->add('save', 'submit')
29 $form->handleRequest($request);
31 if ($form->isValid()) {
32 $content = Extractor
::extract($entry->getUrl());
34 $entry->setTitle($content->getTitle());
35 $entry->setContent($content->getBody());
37 $em = $this->getDoctrine()->getManager();
41 $this->get('session')->getFlashBag()->add(
46 return $this->redirect($this->generateUrl('homepage'));
49 return $this->render('WallabagCoreBundle:Entry:new.html.twig', array(
50 'form' => $form->createView(),
55 * Shows unread entries for current user
57 * @Route("/unread", name="unread")
58 * @return \Symfony\Component\HttpFoundation\Response
60 public function showUnreadAction()
62 // TODO change pagination
63 $entries = $this->getDoctrine()
64 ->getRepository('WallabagCoreBundle:Entry')
65 ->findUnreadByUser($this->getUser()->getId(), 0);
68 'WallabagCoreBundle:Entry:entries.html.twig',
69 array('entries' => $entries)
74 * Shows read entries for current user
76 * @Route("/archive", name="archive")
77 * @return \Symfony\Component\HttpFoundation\Response
79 public function showArchiveAction()
81 // TODO change pagination
82 $entries = $this->getDoctrine()
83 ->getRepository('WallabagCoreBundle:Entry')
84 ->findArchiveByUser($this->getUser()->getId(), 0);
87 'WallabagCoreBundle:Entry:entries.html.twig',
88 array('entries' => $entries)
93 * Shows starred entries for current user
95 * @Route("/starred", name="starred")
96 * @return \Symfony\Component\HttpFoundation\Response
98 public function showStarredAction()
100 // TODO change pagination
101 $entries = $this->getDoctrine()
102 ->getRepository('WallabagCoreBundle:Entry')
103 ->findStarredByUser($this->getUser()->getId(), 0);
105 return $this->render(
106 'WallabagCoreBundle:Entry:entries.html.twig',
107 array('entries' => $entries)
112 * Shows entry content
114 * @param Entry $entry
115 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
116 * @return \Symfony\Component\HttpFoundation\Response
118 public function viewAction(Entry
$entry)
120 return $this->render(
121 'WallabagCoreBundle:Entry:entry.html.twig',
122 array('entry' => $entry)
127 * Changes read status for an entry
129 * @param Request $request
130 * @param Entry $entry
131 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
132 * @return \Symfony\Component\HttpFoundation\RedirectResponse
134 public function toggleArchiveAction(Request
$request, Entry
$entry)
136 $entry->toggleArchive();
137 $this->getDoctrine()->getManager()->flush();
139 $this->get('session')->getFlashBag()->add(
144 return $this->redirect($request->headers
->get('referer'));
148 * Changes favorite status for an entry
150 * @param Request $request
151 * @param Entry $entry
152 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
153 * @return \Symfony\Component\HttpFoundation\RedirectResponse
155 public function toggleStarAction(Request
$request, Entry
$entry)
157 $entry->toggleStar();
158 $this->getDoctrine()->getManager()->flush();
160 $this->get('session')->getFlashBag()->add(
165 return $this->redirect($request->headers
->get('referer'));
171 * @param Request $request
172 * @param Entry $entry
173 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
174 * @return \Symfony\Component\HttpFoundation\RedirectResponse
176 public function deleteEntryAction(Request
$request, Entry
$entry)
178 $em = $this->getDoctrine()->getManager();
179 $entry->setDeleted(1);
180 $em->persist($entry);
183 $this->get('session')->getFlashBag()->add(
188 return $this->redirect($request->headers
->get('referer'));