diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 97bb3d12..8c13255e 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -13,10 +13,37 @@ use Wallabag\CoreBundle\Form\Type\EntryFilterType; | |||
13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 13 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 14 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
15 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | 15 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; |
16 | use Wallabag\CoreBundle\Event\EntrySavedEvent; | ||
17 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | ||
18 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; | ||
16 | 19 | ||
17 | class EntryController extends Controller | 20 | class EntryController extends Controller |
18 | { | 21 | { |
19 | /** | 22 | /** |
23 | * @param Request $request | ||
24 | * @param int $page | ||
25 | * | ||
26 | * @Route("/search/{page}", name="search", defaults={"page" = "1"}) | ||
27 | * | ||
28 | * @return \Symfony\Component\HttpFoundation\Response | ||
29 | */ | ||
30 | public function searchFormAction(Request $request, $page, $currentRoute) | ||
31 | { | ||
32 | $form = $this->createForm(SearchEntryType::class); | ||
33 | |||
34 | $form->handleRequest($request); | ||
35 | |||
36 | if ($form->isValid()) { | ||
37 | return $this->showEntries('search', $request, $page); | ||
38 | } | ||
39 | |||
40 | return $this->render('WallabagCoreBundle:Entry:search_form.html.twig', [ | ||
41 | 'form' => $form->createView(), | ||
42 | 'currentRoute' => $currentRoute, | ||
43 | ]); | ||
44 | } | ||
45 | |||
46 | /** | ||
20 | * Fetch content and update entry. | 47 | * Fetch content and update entry. |
21 | * In case it fails, entry will return to avod loosing the data. | 48 | * In case it fails, entry will return to avod loosing the data. |
22 | * | 49 | * |
@@ -81,6 +108,9 @@ class EntryController extends Controller | |||
81 | $em->persist($entry); | 108 | $em->persist($entry); |
82 | $em->flush(); | 109 | $em->flush(); |
83 | 110 | ||
111 | // entry saved, dispatch event about it! | ||
112 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
113 | |||
84 | return $this->redirect($this->generateUrl('homepage')); | 114 | return $this->redirect($this->generateUrl('homepage')); |
85 | } | 115 | } |
86 | 116 | ||
@@ -107,6 +137,9 @@ class EntryController extends Controller | |||
107 | $em = $this->getDoctrine()->getManager(); | 137 | $em = $this->getDoctrine()->getManager(); |
108 | $em->persist($entry); | 138 | $em->persist($entry); |
109 | $em->flush(); | 139 | $em->flush(); |
140 | |||
141 | // entry saved, dispatch event about it! | ||
142 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
110 | } | 143 | } |
111 | 144 | ||
112 | return $this->redirect($this->generateUrl('homepage')); | 145 | return $this->redirect($this->generateUrl('homepage')); |
@@ -236,8 +269,14 @@ class EntryController extends Controller | |||
236 | private function showEntries($type, Request $request, $page) | 269 | private function showEntries($type, Request $request, $page) |
237 | { | 270 | { |
238 | $repository = $this->get('wallabag_core.entry_repository'); | 271 | $repository = $this->get('wallabag_core.entry_repository'); |
272 | $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); | ||
273 | $currentRoute = (!is_null($request->get('currentRoute')) ? $request->get('currentRoute') : ''); | ||
239 | 274 | ||
240 | switch ($type) { | 275 | switch ($type) { |
276 | case 'search': | ||
277 | $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute); | ||
278 | |||
279 | break; | ||
241 | case 'untagged': | 280 | case 'untagged': |
242 | $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); | 281 | $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); |
243 | 282 | ||
@@ -286,11 +325,11 @@ class EntryController extends Controller | |||
286 | } | 325 | } |
287 | 326 | ||
288 | return $this->render( | 327 | return $this->render( |
289 | 'WallabagCoreBundle:Entry:entries.html.twig', | 328 | 'WallabagCoreBundle:Entry:entries.html.twig', [ |
290 | [ | ||
291 | 'form' => $form->createView(), | 329 | 'form' => $form->createView(), |
292 | 'entries' => $entries, | 330 | 'entries' => $entries, |
293 | 'currentPage' => $page, | 331 | 'currentPage' => $page, |
332 | 'searchTerm' => $searchTerm, | ||
294 | ] | 333 | ] |
295 | ); | 334 | ); |
296 | } | 335 | } |
@@ -343,6 +382,9 @@ class EntryController extends Controller | |||
343 | $em->persist($entry); | 382 | $em->persist($entry); |
344 | $em->flush(); | 383 | $em->flush(); |
345 | 384 | ||
385 | // entry saved, dispatch event about it! | ||
386 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
387 | |||
346 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); | 388 | return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); |
347 | } | 389 | } |
348 | 390 | ||
@@ -431,6 +473,9 @@ class EntryController extends Controller | |||
431 | UrlGeneratorInterface::ABSOLUTE_PATH | 473 | UrlGeneratorInterface::ABSOLUTE_PATH |
432 | ); | 474 | ); |
433 | 475 | ||
476 | // entry deleted, dispatch event about it! | ||
477 | $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); | ||
478 | |||
434 | $em = $this->getDoctrine()->getManager(); | 479 | $em = $this->getDoctrine()->getManager(); |
435 | $em->remove($entry); | 480 | $em->remove($entry); |
436 | $em->flush(); | 481 | $em->flush(); |