]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/EntryController.php
remove Acme and AppBundle
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
CommitLineData
9d50517c
NL
1<?php
2
ad4d1caa 3namespace Wallabag\CoreBundle\Controller;
9d50517c
NL
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
163eae0b 7use Symfony\Component\HttpFoundation\Request;
ad4d1caa
NL
8use Wallabag\CoreBundle\Repository;
9use Wallabag\CoreBundle\Entity\Entries;
6b767d1c 10use Wallabag\CoreBundle\Service\Extractor;
b9ec99e2
NL
11use Wallabag\CoreBundle\Helper\Tools;
12use Wallabag\CoreBundle\Helper\Url;
9d50517c
NL
13
14class EntryController extends Controller
15{
b84a8055
NL
16
17 /**
18 * @param Request $request
19 * @Route("/new", name="new_entry")
20 * @return \Symfony\Component\HttpFoundation\Response
21 */
22 public function addEntryAction(Request $request)
23 {
24 $entry = new Entries();
25 $entry->setUserId(1);
26
27 $form = $this->createFormBuilder($entry)
28 ->add('url', 'url')
29 ->add('save', 'submit')
30 ->getForm();
31
32 $form->handleRequest($request);
33
34 if ($form->isValid()) {
35
6b767d1c 36 $content = Extractor::extract($entry->getUrl());
b84a8055 37
6b767d1c
NL
38 $entry->setTitle($content->getTitle());
39 $entry->setContent($content->getBody());
40
41 $em = $this->getDoctrine()->getManager();
b84a8055
NL
42 $em->persist($entry);
43 $em->flush();
44
45 $this->get('session')->getFlashBag()->add(
46 'notice',
47 'Entry saved'
48 );
49
50 return $this->redirect($this->generateUrl('homepage'));
51 }
52
ad4d1caa 53 return $this->render('WallabagCoreBundle:Entry:new.html.twig', array(
b84a8055
NL
54 'form' => $form->createView(),
55 ));
56 }
57
9d50517c 58 /**
163eae0b
NL
59 * Shows unread entries for current user
60 *
9d50517c 61 * @Route("/unread", name="unread")
163eae0b 62 * @return \Symfony\Component\HttpFoundation\Response
9d50517c 63 */
bd9f0815 64 public function showUnreadAction()
9d50517c 65 {
ad4d1caa 66 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
a8c90c5c
NL
67 // TODO don't give the user ID like this
68 // TODO change pagination
163eae0b 69 $entries = $repository->findUnreadByUser(1, 0);
9d50517c
NL
70
71 return $this->render(
ad4d1caa 72 'WallabagCoreBundle:Entry:entries.html.twig',
9d50517c
NL
73 array('entries' => $entries)
74 );
9d50517c 75 }
bd9f0815
NL
76
77 /**
163eae0b
NL
78 * Shows read entries for current user
79 *
bd9f0815 80 * @Route("/archive", name="archive")
163eae0b 81 * @return \Symfony\Component\HttpFoundation\Response
bd9f0815
NL
82 */
83 public function showArchiveAction()
84 {
ad4d1caa 85 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
a8c90c5c
NL
86 // TODO don't give the user ID like this
87 // TODO change pagination
163eae0b 88 $entries = $repository->findArchiveByUser(1, 0);
bd9f0815
NL
89
90 return $this->render(
ad4d1caa 91 'WallabagCoreBundle:Entry:entries.html.twig',
bd9f0815
NL
92 array('entries' => $entries)
93 );
bd9f0815
NL
94 }
95
96 /**
163eae0b
NL
97 * Shows starred entries for current user
98 *
bd9f0815 99 * @Route("/starred", name="starred")
163eae0b 100 * @return \Symfony\Component\HttpFoundation\Response
bd9f0815
NL
101 */
102 public function showStarredAction()
103 {
ad4d1caa 104 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
a8c90c5c
NL
105 // TODO don't give the user ID like this
106 // TODO change pagination
163eae0b 107 $entries = $repository->findStarredByUser(1, 0);
bd9f0815
NL
108
109 return $this->render(
ad4d1caa 110 'WallabagCoreBundle:Entry:entries.html.twig',
bd9f0815
NL
111 array('entries' => $entries)
112 );
bd9f0815
NL
113 }
114
115 /**
163eae0b
NL
116 * Shows entry content
117 *
118 * @param Entries $entry
bd9f0815 119 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
163eae0b 120 * @return \Symfony\Component\HttpFoundation\Response
bd9f0815 121 */
163eae0b 122 public function viewAction(Entries $entry)
bd9f0815 123 {
bd9f0815 124 return $this->render(
ad4d1caa 125 'WallabagCoreBundle:Entry:entry.html.twig',
bd9f0815
NL
126 array('entry' => $entry)
127 );
163eae0b
NL
128 }
129
130 /**
131 * Changes read status for an entry
132 *
133 * @param Request $request
134 * @param Entries $entry
135 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
136 * @return \Symfony\Component\HttpFoundation\RedirectResponse
137 */
138 public function toggleArchiveAction(Request $request, Entries $entry)
139 {
140 $entry->toggleArchive();
141 $this->getDoctrine()->getManager()->flush();
142
143 $this->get('session')->getFlashBag()->add(
144 'notice',
145 'Entry archived'
146 );
147
148 return $this->redirect($request->headers->get('referer'));
149 }
150
151 /**
152 * Changes favorite status for an entry
153 *
154 * @param Request $request
155 * @param Entries $entry
156 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
157 * @return \Symfony\Component\HttpFoundation\RedirectResponse
158 */
159 public function toggleStarAction(Request $request, Entries $entry)
160 {
161 $entry->toggleStar();
162 $this->getDoctrine()->getManager()->flush();
163
164 $this->get('session')->getFlashBag()->add(
165 'notice',
166 'Entry starred'
167 );
168
169 return $this->redirect($request->headers->get('referer'));
170 }
171
172 /**
173 * Deletes entry
174 *
175 * @param Request $request
176 * @param Entries $entry
177 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
178 * @return \Symfony\Component\HttpFoundation\RedirectResponse
179 */
180 public function deleteEntryAction(Request $request, Entries $entry)
181 {
6b767d1c 182 $em = $this->getDoctrine()->getManager();
163eae0b
NL
183 $em->remove($entry);
184 $em->flush();
185
186 $this->get('session')->getFlashBag()->add(
187 'notice',
188 'Entry deleted'
189 );
bd9f0815 190
163eae0b 191 return $this->redirect($request->headers->get('referer'));
bd9f0815 192 }
9d50517c 193}