From efcad0b9354af4b7c0b1e2707d1511138e5431b8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 22 Sep 2014 07:25:14 +0200 Subject: [PATCH] First version of a search interface. --- app/controllers/SearchController.php | 26 +++++++- app/lib/Firefly/Helper/Controllers/Search.php | 43 +++++++++++++ .../Helper/Controllers/SearchInterface.php | 22 +++++++ .../Firefly/Helper/HelperServiceProvider.php | 5 ++ app/views/partials/menu.blade.php | 8 ++- app/views/search/index.blade.php | 60 +++++++++++++++++++ 6 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 app/lib/Firefly/Helper/Controllers/Search.php create mode 100644 app/lib/Firefly/Helper/Controllers/SearchInterface.php create mode 100644 app/views/search/index.blade.php diff --git a/app/controllers/SearchController.php b/app/controllers/SearchController.php index 769055d35d..c3ad87bbf3 100644 --- a/app/controllers/SearchController.php +++ b/app/controllers/SearchController.php @@ -1,16 +1,40 @@ _helper = $helper; + + } /** - * + * Results always come in the form of an array [results, count, fullCount] */ public function index() { + $subTitle = null; + if (!is_null(Input::get('q'))) { + $rawQuery = trim(Input::get('q')); + $words = explode(' ', $rawQuery); + $subTitle = 'Results for "' . e($rawQuery) . '"'; + + /* + * Search for transactions: + */ + $result = $this->_helper->transactions($words); + + } + + return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with( + 'mainTitleIcon', 'fa-search' + ); } } \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Controllers/Search.php b/app/lib/Firefly/Helper/Controllers/Search.php new file mode 100644 index 0000000000..03ece09fed --- /dev/null +++ b/app/lib/Firefly/Helper/Controllers/Search.php @@ -0,0 +1,43 @@ +count(); + + $query->where( + function ($q) use ($words) { + foreach ($words as $word) { + $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); + } + } + ); + $count = $query->count(); + $set = $query->get(); + /* + * Build something with JSON? + */ + return $set; + } + +} \ No newline at end of file diff --git a/app/lib/Firefly/Helper/Controllers/SearchInterface.php b/app/lib/Firefly/Helper/Controllers/SearchInterface.php new file mode 100644 index 0000000000..3c0e5b78f2 --- /dev/null +++ b/app/lib/Firefly/Helper/Controllers/SearchInterface.php @@ -0,0 +1,22 @@ +app->bind( + 'Firefly\Helper\Controllers\SearchInterface', + 'Firefly\Helper\Controllers\Search' + ); + $this->app->bind( 'Firefly\Helper\Controllers\TransactionInterface', 'Firefly\Helper\Controllers\Transaction' diff --git a/app/views/partials/menu.blade.php b/app/views/partials/menu.blade.php index fb12a1e362..77f0ec1940 100644 --- a/app/views/partials/menu.blade.php +++ b/app/views/partials/menu.blade.php @@ -73,14 +73,18 @@