diff --git a/config/routes/search.yaml b/config/routes/search.yaml index 239392bc..b3a53477 100644 --- a/config/routes/search.yaml +++ b/config/routes/search.yaml @@ -1,3 +1,8 @@ general_search: path: /search controller: App\Controller\SearchController::index + +search_history: + path: /search/history + controller: App\Controller\SearchController::search + methods: [POST] diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index d84e643c..ea9e8425 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -3,6 +3,10 @@ namespace App\Controller; use App\Ramcar\BaseController; +use App\Service\GeneralSearch; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use App\Menu\Generator as MenuGenerator; use App\Access\Generator as ACLGenerator; @@ -25,4 +29,27 @@ class SearchController extends BaseController // response return $this->render('search/list.html.twig', $params); } + + public function search(Request $req, GeneralSearch $search) + { + $this->denyAccessUnlessGranted('general.search', null, 'No access.'); + + $search_term = $req->request->get('data-rows-search'); + $results = $search->search($search_term); + + // process rows + // this is not how to process the results. + // TODO: fix this asap + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow[0]->getID(); + + $rows[] = $row; + } + + return $this->json([ + 'data' => $rows + ]); + } } diff --git a/templates/search/list.html.twig b/templates/search/list.html.twig index f2863436..7c325483 100644 --- a/templates/search/list.html.twig +++ b/templates/search/list.html.twig @@ -23,12 +23,14 @@
+
- +
+
@@ -46,6 +48,30 @@ {% block scripts %} {% endblock %}