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