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