]>
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; | |
b84a8055 NL |
10 | use Wallabag\Wallabag\Tools; |
11 | use Wallabag\Wallabag\Url; | |
9d50517c NL |
12 | |
13 | class EntryController extends Controller | |
14 | { | |
b84a8055 NL |
15 | |
16 | /** | |
17 | * @param Request $request | |
18 | * @Route("/new", name="new_entry") | |
19 | * @return \Symfony\Component\HttpFoundation\Response | |
20 | */ | |
21 | public function addEntryAction(Request $request) | |
22 | { | |
23 | $entry = new Entries(); | |
24 | $entry->setUserId(1); | |
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()) { | |
34 | ||
35 | $content = Tools::getPageContent(new Url($entry->getUrl())); | |
36 | var_dump($content);die; | |
37 | ||
38 | $em = $this->getDoctrine()->getEntityManager(); | |
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'); |
163eae0b | 64 | $entries = $repository->findUnreadByUser(1, 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 | { | |
ad4d1caa | 80 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); |
163eae0b | 81 | $entries = $repository->findArchiveByUser(1, 0); |
bd9f0815 NL |
82 | |
83 | return $this->render( | |
ad4d1caa | 84 | 'WallabagCoreBundle:Entry:entries.html.twig', |
bd9f0815 NL |
85 | array('entries' => $entries) |
86 | ); | |
bd9f0815 NL |
87 | } |
88 | ||
89 | /** | |
163eae0b NL |
90 | * Shows starred entries for current user |
91 | * | |
bd9f0815 | 92 | * @Route("/starred", name="starred") |
163eae0b | 93 | * @return \Symfony\Component\HttpFoundation\Response |
bd9f0815 NL |
94 | */ |
95 | public function showStarredAction() | |
96 | { | |
ad4d1caa | 97 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); |
163eae0b | 98 | $entries = $repository->findStarredByUser(1, 0); |
bd9f0815 NL |
99 | |
100 | return $this->render( | |
ad4d1caa | 101 | 'WallabagCoreBundle:Entry:entries.html.twig', |
bd9f0815 NL |
102 | array('entries' => $entries) |
103 | ); | |
bd9f0815 NL |
104 | } |
105 | ||
106 | /** | |
163eae0b NL |
107 | * Shows entry content |
108 | * | |
109 | * @param Entries $entry | |
bd9f0815 | 110 | * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view") |
163eae0b | 111 | * @return \Symfony\Component\HttpFoundation\Response |
bd9f0815 | 112 | */ |
163eae0b | 113 | public function viewAction(Entries $entry) |
bd9f0815 | 114 | { |
bd9f0815 | 115 | return $this->render( |
ad4d1caa | 116 | 'WallabagCoreBundle:Entry:entry.html.twig', |
bd9f0815 NL |
117 | array('entry' => $entry) |
118 | ); | |
163eae0b NL |
119 | } |
120 | ||
121 | /** | |
122 | * Changes read status for an entry | |
123 | * | |
124 | * @param Request $request | |
125 | * @param Entries $entry | |
126 | * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry") | |
127 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
128 | */ | |
129 | public function toggleArchiveAction(Request $request, Entries $entry) | |
130 | { | |
131 | $entry->toggleArchive(); | |
132 | $this->getDoctrine()->getManager()->flush(); | |
133 | ||
134 | $this->get('session')->getFlashBag()->add( | |
135 | 'notice', | |
136 | 'Entry archived' | |
137 | ); | |
138 | ||
139 | return $this->redirect($request->headers->get('referer')); | |
140 | } | |
141 | ||
142 | /** | |
143 | * Changes favorite status for an entry | |
144 | * | |
145 | * @param Request $request | |
146 | * @param Entries $entry | |
147 | * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry") | |
148 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
149 | */ | |
150 | public function toggleStarAction(Request $request, Entries $entry) | |
151 | { | |
152 | $entry->toggleStar(); | |
153 | $this->getDoctrine()->getManager()->flush(); | |
154 | ||
155 | $this->get('session')->getFlashBag()->add( | |
156 | 'notice', | |
157 | 'Entry starred' | |
158 | ); | |
159 | ||
160 | return $this->redirect($request->headers->get('referer')); | |
161 | } | |
162 | ||
163 | /** | |
164 | * Deletes entry | |
165 | * | |
166 | * @param Request $request | |
167 | * @param Entries $entry | |
168 | * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry") | |
169 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
170 | */ | |
171 | public function deleteEntryAction(Request $request, Entries $entry) | |
172 | { | |
173 | $em = $this->getDoctrine()->getEntityManager(); | |
174 | $em->remove($entry); | |
175 | $em->flush(); | |
176 | ||
177 | $this->get('session')->getFlashBag()->add( | |
178 | 'notice', | |
179 | 'Entry deleted' | |
180 | ); | |
bd9f0815 | 181 | |
163eae0b | 182 | return $this->redirect($request->headers->get('referer')); |
bd9f0815 | 183 | } |
9d50517c | 184 | } |