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