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