use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
use Wallabag\CoreBundle\Event\EntryDeletedEvent;
+use Wallabag\CoreBundle\Form\Type\SearchEntryType;
class EntryController extends Controller
{
+ /**
+ * @param Request $request
+ * @param int $page
+ *
+ * @Route("/search/{page}", name="search", defaults={"page" = 1})
+ *
+ * Default parameter for page is hardcoded (in duplication of the defaults from the Route)
+ * because this controller is also called inside the layout template without any page as argument
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function searchFormAction(Request $request, $page = 1, $currentRoute = null)
+ {
+ // fallback to retrieve currentRoute from query parameter instead of injected one (when using inside a template)
+ if (null === $currentRoute && $request->query->has('currentRoute')) {
+ $currentRoute = $request->query->get('currentRoute');
+ }
+
+ $form = $this->createForm(SearchEntryType::class);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ return $this->showEntries('search', $request, $page);
+ }
+
+ return $this->render('WallabagCoreBundle:Entry:search_form.html.twig', [
+ 'form' => $form->createView(),
+ 'currentRoute' => $currentRoute,
+ ]);
+ }
+
/**
* Fetch content and update entry.
* In case it fails, entry will return to avod loosing the data.
$form->handleRequest($request);
- if ($form->isValid()) {
+ if ($form->isSubmitted() && $form->isValid()) {
$existingEntry = $this->checkIfEntryAlreadyExists($entry);
if (false !== $existingEntry) {
$form->handleRequest($request);
- if ($form->isValid()) {
+ if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entry);
$em->flush();
private function showEntries($type, Request $request, $page)
{
$repository = $this->get('wallabag_core.entry_repository');
+ $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
+ $currentRoute = (!is_null($request->get('currentRoute')) ? $request->get('currentRoute') : '');
switch ($type) {
+ case 'search':
+ $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
+
+ break;
case 'untagged':
$qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
}
return $this->render(
- 'WallabagCoreBundle:Entry:entries.html.twig',
- [
+ 'WallabagCoreBundle:Entry:entries.html.twig', [
'form' => $form->createView(),
'entries' => $entries,
'currentPage' => $page,
+ 'searchTerm' => $searchTerm,
]
);
}