]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | |
4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
7 | use Symfony\Component\HttpFoundation\Request; | |
8 | use Wallabag\CoreBundle\Repository; | |
9 | use Wallabag\CoreBundle\Entity\Entries; | |
10 | use Wallabag\Wallabag\Tools; | |
11 | use Wallabag\Wallabag\Url; | |
12 | ||
13 | class EntryController extends Controller | |
14 | { | |
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 | ||
50 | return $this->render('WallabagCoreBundle:Entry:new.html.twig', array( | |
51 | 'form' => $form->createView(), | |
52 | )); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Shows unread entries for current user | |
57 | * | |
58 | * @Route("/unread", name="unread") | |
59 | * @return \Symfony\Component\HttpFoundation\Response | |
60 | */ | |
61 | public function showUnreadAction() | |
62 | { | |
63 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); | |
64 | $entries = $repository->findUnreadByUser(1, 0); | |
65 | ||
66 | return $this->render( | |
67 | 'WallabagCoreBundle:Entry:entries.html.twig', | |
68 | array('entries' => $entries) | |
69 | ); | |
70 | } | |
71 | ||
72 | /** | |
73 | * Shows read entries for current user | |
74 | * | |
75 | * @Route("/archive", name="archive") | |
76 | * @return \Symfony\Component\HttpFoundation\Response | |
77 | */ | |
78 | public function showArchiveAction() | |
79 | { | |
80 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); | |
81 | $entries = $repository->findArchiveByUser(1, 0); | |
82 | ||
83 | return $this->render( | |
84 | 'WallabagCoreBundle:Entry:entries.html.twig', | |
85 | array('entries' => $entries) | |
86 | ); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Shows starred entries for current user | |
91 | * | |
92 | * @Route("/starred", name="starred") | |
93 | * @return \Symfony\Component\HttpFoundation\Response | |
94 | */ | |
95 | public function showStarredAction() | |
96 | { | |
97 | $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); | |
98 | $entries = $repository->findStarredByUser(1, 0); | |
99 | ||
100 | return $this->render( | |
101 | 'WallabagCoreBundle:Entry:entries.html.twig', | |
102 | array('entries' => $entries) | |
103 | ); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Shows entry content | |
108 | * | |
109 | * @param Entries $entry | |
110 | * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view") | |
111 | * @return \Symfony\Component\HttpFoundation\Response | |
112 | */ | |
113 | public function viewAction(Entries $entry) | |
114 | { | |
115 | return $this->render( | |
116 | 'WallabagCoreBundle:Entry:entry.html.twig', | |
117 | array('entry' => $entry) | |
118 | ); | |
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 | ); | |
181 | ||
182 | return $this->redirect($request->headers->get('referer')); | |
183 | } | |
184 | } |