aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/EntryController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php73
1 files changed, 63 insertions, 10 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 97bb3d12..f7398e69 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -13,10 +13,45 @@ use Wallabag\CoreBundle\Form\Type\EntryFilterType;
13use Wallabag\CoreBundle\Form\Type\EditEntryType; 13use Wallabag\CoreBundle\Form\Type\EditEntryType;
14use Wallabag\CoreBundle\Form\Type\NewEntryType; 14use Wallabag\CoreBundle\Form\Type\NewEntryType;
15use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; 15use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
16use Wallabag\CoreBundle\Event\EntrySavedEvent;
17use Wallabag\CoreBundle\Event\EntryDeletedEvent;
18use Wallabag\CoreBundle\Form\Type\SearchEntryType;
16 19
17class EntryController extends Controller 20class 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 * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
29 * because this controller is also called inside the layout template without any page as argument
30 *
31 * @return \Symfony\Component\HttpFoundation\Response
32 */
33 public function searchFormAction(Request $request, $page = 1, $currentRoute = null)
34 {
35 // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template)
36 if (null === $currentRoute && $request->query->has('currentRoute')) {
37 $currentRoute = $request->query->get('currentRoute');
38 }
39
40 $form = $this->createForm(SearchEntryType::class);
41
42 $form->handleRequest($request);
43
44 if ($form->isSubmitted() && $form->isValid()) {
45 return $this->showEntries('search', $request, $page);
46 }
47
48 return $this->render('WallabagCoreBundle:Entry:search_form.html.twig', [
49 'form' => $form->createView(),
50 'currentRoute' => $currentRoute,
51 ]);
52 }
53
54 /**
20 * Fetch content and update entry. 55 * Fetch content and update entry.
21 * In case it fails, entry will return to avod loosing the data. 56 * In case it fails, entry will return to avod loosing the data.
22 * 57 *
@@ -63,7 +98,7 @@ class EntryController extends Controller
63 98
64 $form->handleRequest($request); 99 $form->handleRequest($request);
65 100
66 if ($form->isValid()) { 101 if ($form->isSubmitted() && $form->isValid()) {
67 $existingEntry = $this->checkIfEntryAlreadyExists($entry); 102 $existingEntry = $this->checkIfEntryAlreadyExists($entry);
68 103
69 if (false !== $existingEntry) { 104 if (false !== $existingEntry) {
@@ -81,6 +116,9 @@ class EntryController extends Controller
81 $em->persist($entry); 116 $em->persist($entry);
82 $em->flush(); 117 $em->flush();
83 118
119 // entry saved, dispatch event about it!
120 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
121
84 return $this->redirect($this->generateUrl('homepage')); 122 return $this->redirect($this->generateUrl('homepage'));
85 } 123 }
86 124
@@ -107,6 +145,9 @@ class EntryController extends Controller
107 $em = $this->getDoctrine()->getManager(); 145 $em = $this->getDoctrine()->getManager();
108 $em->persist($entry); 146 $em->persist($entry);
109 $em->flush(); 147 $em->flush();
148
149 // entry saved, dispatch event about it!
150 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
110 } 151 }
111 152
112 return $this->redirect($this->generateUrl('homepage')); 153 return $this->redirect($this->generateUrl('homepage'));
@@ -140,7 +181,7 @@ class EntryController extends Controller
140 181
141 $form->handleRequest($request); 182 $form->handleRequest($request);
142 183
143 if ($form->isValid()) { 184 if ($form->isSubmitted() && $form->isValid()) {
144 $em = $this->getDoctrine()->getManager(); 185 $em = $this->getDoctrine()->getManager();
145 $em->persist($entry); 186 $em->persist($entry);
146 $em->flush(); 187 $em->flush();
@@ -236,8 +277,14 @@ class EntryController extends Controller
236 private function showEntries($type, Request $request, $page) 277 private function showEntries($type, Request $request, $page)
237 { 278 {
238 $repository = $this->get('wallabag_core.entry_repository'); 279 $repository = $this->get('wallabag_core.entry_repository');
280 $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
281 $currentRoute = (!is_null($request->query->get('currentRoute')) ? $request->query->get('currentRoute') : '');
239 282
240 switch ($type) { 283 switch ($type) {
284 case 'search':
285 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
286
287 break;
241 case 'untagged': 288 case 'untagged':
242 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); 289 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
243 290
@@ -272,7 +319,7 @@ class EntryController extends Controller
272 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb); 319 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
273 } 320 }
274 321
275 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); 322 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
276 323
277 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') 324 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
278 ->prepare($pagerAdapter, $page); 325 ->prepare($pagerAdapter, $page);
@@ -286,11 +333,11 @@ class EntryController extends Controller
286 } 333 }
287 334
288 return $this->render( 335 return $this->render(
289 'WallabagCoreBundle:Entry:entries.html.twig', 336 'WallabagCoreBundle:Entry:entries.html.twig', [
290 [
291 'form' => $form->createView(), 337 'form' => $form->createView(),
292 'entries' => $entries, 338 'entries' => $entries,
293 'currentPage' => $page, 339 'currentPage' => $page,
340 'searchTerm' => $searchTerm,
294 ] 341 ]
295 ); 342 );
296 } 343 }
@@ -343,6 +390,9 @@ class EntryController extends Controller
343 $em->persist($entry); 390 $em->persist($entry);
344 $em->flush(); 391 $em->flush();
345 392
393 // entry saved, dispatch event about it!
394 $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));
395
346 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()])); 396 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
347 } 397 }
348 398
@@ -431,6 +481,9 @@ class EntryController extends Controller
431 UrlGeneratorInterface::ABSOLUTE_PATH 481 UrlGeneratorInterface::ABSOLUTE_PATH
432 ); 482 );
433 483
484 // entry deleted, dispatch event about it!
485 $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
486
434 $em = $this->getDoctrine()->getManager(); 487 $em = $this->getDoctrine()->getManager();
435 $em->remove($entry); 488 $em->remove($entry);
436 $em->flush(); 489 $em->flush();
@@ -486,8 +539,8 @@ class EntryController extends Controller
486 { 539 {
487 $this->checkUserAction($entry); 540 $this->checkUserAction($entry);
488 541
489 if (null === $entry->getUuid()) { 542 if (null === $entry->getUid()) {
490 $entry->generateUuid(); 543 $entry->generateUid();
491 544
492 $em = $this->getDoctrine()->getManager(); 545 $em = $this->getDoctrine()->getManager();
493 $em->persist($entry); 546 $em->persist($entry);
@@ -495,7 +548,7 @@ class EntryController extends Controller
495 } 548 }
496 549
497 return $this->redirect($this->generateUrl('share_entry', [ 550 return $this->redirect($this->generateUrl('share_entry', [
498 'uuid' => $entry->getUuid(), 551 'uid' => $entry->getUid(),
499 ])); 552 ]));
500 } 553 }
501 554
@@ -512,7 +565,7 @@ class EntryController extends Controller
512 { 565 {
513 $this->checkUserAction($entry); 566 $this->checkUserAction($entry);
514 567
515 $entry->cleanUuid(); 568 $entry->cleanUid();
516 569
517 $em = $this->getDoctrine()->getManager(); 570 $em = $this->getDoctrine()->getManager();
518 $em->persist($entry); 571 $em->persist($entry);
@@ -528,7 +581,7 @@ class EntryController extends Controller
528 * 581 *
529 * @param Entry $entry 582 * @param Entry $entry
530 * 583 *
531 * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") 584 * @Route("/share/{uid}", requirements={"uid" = ".+"}, name="share_entry")
532 * @Cache(maxage="25200", smaxage="25200", public=true) 585 * @Cache(maxage="25200", smaxage="25200", public=true)
533 * 586 *
534 * @return \Symfony\Component\HttpFoundation\Response 587 * @return \Symfony\Component\HttpFoundation\Response