diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-11-04 23:24:43 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-11-19 19:17:30 +0100 |
commit | ee122a7528f55dfb5f02e351c509d00b756fedaa (patch) | |
tree | b4b134dc00dda3394a1ab01408369803c8b0b889 /src/Wallabag/CoreBundle/Controller/EntryController.php | |
parent | 27dce581caba158a8ffffa5bc30648a21f47da12 (diff) | |
download | wallabag-ee122a7528f55dfb5f02e351c509d00b756fedaa.tar.gz wallabag-ee122a7528f55dfb5f02e351c509d00b756fedaa.tar.zst wallabag-ee122a7528f55dfb5f02e351c509d00b756fedaa.zip |
Added a simple search engine
Fix #18
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 3f4eb17d..fc1697be 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -15,10 +15,34 @@ 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; | 16 | use Wallabag\CoreBundle\Event\EntrySavedEvent; |
17 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | 17 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; |
18 | use Wallabag\CoreBundle\Form\Type\SearchEntryType; | ||
18 | 19 | ||
19 | class EntryController extends Controller | 20 | class EntryController extends Controller |
20 | { | 21 | { |
21 | /** | 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) | ||
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 | ]); | ||
43 | } | ||
44 | |||
45 | /** | ||
22 | * Fetch content and update entry. | 46 | * Fetch content and update entry. |
23 | * In case it fails, entry will return to avod loosing the data. | 47 | * In case it fails, entry will return to avod loosing the data. |
24 | * | 48 | * |
@@ -244,8 +268,13 @@ class EntryController extends Controller | |||
244 | private function showEntries($type, Request $request, $page) | 268 | private function showEntries($type, Request $request, $page) |
245 | { | 269 | { |
246 | $repository = $this->get('wallabag_core.entry_repository'); | 270 | $repository = $this->get('wallabag_core.entry_repository'); |
271 | $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : ''); | ||
247 | 272 | ||
248 | switch ($type) { | 273 | switch ($type) { |
274 | case 'search': | ||
275 | $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm); | ||
276 | |||
277 | break; | ||
249 | case 'untagged': | 278 | case 'untagged': |
250 | $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); | 279 | $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); |
251 | 280 | ||
@@ -294,11 +323,11 @@ class EntryController extends Controller | |||
294 | } | 323 | } |
295 | 324 | ||
296 | return $this->render( | 325 | return $this->render( |
297 | 'WallabagCoreBundle:Entry:entries.html.twig', | 326 | 'WallabagCoreBundle:Entry:entries.html.twig', [ |
298 | [ | ||
299 | 'form' => $form->createView(), | 327 | 'form' => $form->createView(), |
300 | 'entries' => $entries, | 328 | 'entries' => $entries, |
301 | 'currentPage' => $page, | 329 | 'currentPage' => $page, |
330 | 'searchTerm' => $searchTerm, | ||
302 | ] | 331 | ] |
303 | ); | 332 | ); |
304 | } | 333 | } |