mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
First version of a search interface.
This commit is contained in:
43
app/lib/Firefly/Helper/Controllers/Search.php
Normal file
43
app/lib/Firefly/Helper/Controllers/Search.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
22
app/lib/Firefly/Helper/Controllers/SearchInterface.php
Normal file
22
app/lib/Firefly/Helper/Controllers/SearchInterface.php
Normal 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);
|
||||
}
|
@@ -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'
|
||||
|
Reference in New Issue
Block a user