Skip to content

Firefly III: a personal finances manager

First version of a search interface.

James Coleefcad0b9354a
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 @@
<?php
+use Firefly\Helper\Controllers\SearchInterface as SI;
+
/**
* Class SearchController
*/
class SearchController extends BaseController
{
+ protected $_helper;
+
+ public function __construct(SI $helper)
+ {
+ $this->_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 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sander
+ * Date: 21/09/14
+ * Time: 20:58
+ */
+
+namespace Firefly\Helper\Controllers;
+
+/**
+ * Class Search
+ *
+ * @package Firefly\Helper\Controllers
+ */
+class Search implements SearchInterface
+{
+
+ /**
+ * @param array $words
+ */
+ public function transactions(array $words)
+ {
+ $query = \TransactionJournal::withRelevantData();
+
+ $fullCount = $query->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 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sander
+ * Date: 21/09/14
+ * Time: 20:58
+ */
+
+namespace Firefly\Helper\Controllers;
+
+/**
+ * Interface SearchInterface
+ *
+ * @package Firefly\Helper\Controllers
+ */
+interface SearchInterface
+{
+ /**
+ * @param array $words
+ */
+ public function transactions(array $words);
+}
\ No newline at end of file
diff --git a/app/lib/Firefly/Helper/HelperServiceProvider.php b/app/lib/Firefly/Helper/HelperServiceProvider.php
index dce71e667d..1e42d710e0 100644
--- a/app/lib/Firefly/Helper/HelperServiceProvider.php
+++ b/app/lib/Firefly/Helper/HelperServiceProvider.php
@@ -27,6 +27,11 @@ class HelperServiceProvider extends ServiceProvider
'Firefly\Helper\Controllers\Chart'
);
+ $this->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 @@
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li class="sidebar-search">
+ <form action="{{route('search')}}" method="GET" class="form-inline">
<div class="input-group custom-search-form">
- <input type="text" class="form-control" placeholder="Search...">
+
+ <input type="text" name="q" class="form-control" placeholder="Search...">
<span class="input-group-btn">
- <button class="btn btn-default" type="button">
+ <button class="btn btn-default" type="submit">
<i class="fa fa-search"></i>
</button>
</span>
+
</div>
+ </form>
<!-- /input-group -->
</li>
<li>
diff --git a/app/views/search/index.blade.php b/app/views/search/index.blade.php
new file mode 100644
index 0000000000..282e6418d8
--- /dev/null
+++ b/app/views/search/index.blade.php
@@ -0,0 +1,60 @@
+@extends('layouts.default')
+@section('content')
+<div class="row">
+ <div class="col-lg-6 col-md-12 col-sm-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-repeat"></i> Transactions
+ </div>
+ <div class="panel-body">
+ <p>Bla bla</p>
+ </div>
+ </div>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-bar-chart"></i> Categories
+ </div>
+ <div class="panel-body">
+ <p>Bla bla</p>
+ </div>
+ </div>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-bar-chart"></i> Tags
+ </div>
+ <div class="panel-body">
+ <p>Bla bla</p>
+ </div>
+ </div>
+ </div>
+ <div class="col-lg-6 col-md-12 col-sm-12">
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-credit-card"></i> Accounts
+ </div>
+ <div class="panel-body">
+ <p>Bla bla</p>
+ </div>
+ </div>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-tasks"></i> Budgets
+ </div>
+ <div class="panel-body">
+ <p>Bla bla</p>
+ </div>
+ </div>
+ <div class="panel panel-default">
+ <div class="panel-heading">
+ <i class="fa fa-search-plus"></i> Other results
+ </div>
+ <div class="panel-body">
+ <p>Bla bla</p>
+ </div>
+ </div>
+ </div>
+</div>
+
+
+
+@stop
\ No newline at end of file