First version of a search interface.

This commit is contained in:
James Cole
2014-09-22 07:25:14 +02:00
parent e892b69a96
commit efcad0b935
6 changed files with 161 additions and 3 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -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'