]>
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; |
b84a8055 NL |
11 | use Wallabag\Wallabag\Tools; |
12 | use Wallabag\Wallabag\Url; | |
9d50517c NL |
13 | |
14 | class 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'); |
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 | { | |
ad4d1caa | 83 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); |
163eae0b | 84 | $entries = $repository->findArchiveByUser(1, 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 | { | |
ad4d1caa | 100 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); |
163eae0b | 101 | $entries = $repository->findStarredByUser(1, 0); |
bd9f0815 NL |
102 | |
103 | return $this->render( | |
ad4d1caa | 104 | 'WallabagCoreBundle:Entry:entries.html.twig', |
bd9f0815 NL |
105 | array('entries' => $entries) |
106 | ); | |
bd9f0815 NL |
107 | } |
108 | ||
109 | /** | |
163eae0b NL |
110 | * Shows entry content |
111 | * | |
112 | * @param Entries $entry | |
bd9f0815 | 113 | * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view") |
163eae0b | 114 | * @return \Symfony\Component\HttpFoundation\Response |
bd9f0815 | 115 | */ |
163eae0b | 116 | public function viewAction(Entries $entry) |
bd9f0815 | 117 | { |
bd9f0815 | 118 | return $this->render( |
ad4d1caa | 119 | 'WallabagCoreBundle:Entry:entry.html.twig', |
bd9f0815 NL |
120 | array('entry' => $entry) |
121 | ); | |
163eae0b NL |
122 | } |
123 | ||
124 | /** | |
125 | * Changes read status for an entry | |
126 | * | |
127 | * @param Request $request | |
128 | * @param Entries $entry | |
129 | * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry") | |
130 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
131 | */ | |
132 | public function toggleArchiveAction(Request $request, Entries $entry) | |
133 | { | |
134 | $entry->toggleArchive(); | |
135 | $this->getDoctrine()->getManager()->flush(); | |
136 | ||
137 | $this->get('session')->getFlashBag()->add( | |
138 | 'notice', | |
139 | 'Entry archived' | |
140 | ); | |
141 | ||
142 | return $this->redirect($request->headers->get('referer')); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Changes favorite status for an entry | |
147 | * | |
148 | * @param Request $request | |
149 | * @param Entries $entry | |
150 | * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry") | |
151 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
152 | */ | |
153 | public function toggleStarAction(Request $request, Entries $entry) | |
154 | { | |
155 | $entry->toggleStar(); | |
156 | $this->getDoctrine()->getManager()->flush(); | |
157 | ||
158 | $this->get('session')->getFlashBag()->add( | |
159 | 'notice', | |
160 | 'Entry starred' | |
161 | ); | |
162 | ||
163 | return $this->redirect($request->headers->get('referer')); | |
164 | } | |
165 | ||
166 | /** | |
167 | * Deletes entry | |
168 | * | |
169 | * @param Request $request | |
170 | * @param Entries $entry | |
171 | * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry") | |
172 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
173 | */ | |
174 | public function deleteEntryAction(Request $request, Entries $entry) | |
175 | { | |
6b767d1c | 176 | $em = $this->getDoctrine()->getManager(); |
163eae0b NL |
177 | $em->remove($entry); |
178 | $em->flush(); | |
179 | ||
180 | $this->get('session')->getFlashBag()->add( | |
181 | 'notice', | |
182 | 'Entry deleted' | |
183 | ); | |
bd9f0815 | 184 | |
163eae0b | 185 | return $this->redirect($request->headers->get('referer')); |
bd9f0815 | 186 | } |
9d50517c | 187 | } |