Various bug fixes.

This commit is contained in:
James Cole
2014-09-27 06:06:31 +02:00
parent 9ab3679d49
commit 3bbecfe830
12 changed files with 218 additions and 72 deletions

View File

@@ -8,6 +8,8 @@
namespace Firefly\Helper\Controllers;
use Illuminate\Support\Collection;
/**
* Class Search
*
@@ -18,26 +20,89 @@ class Search implements SearchInterface
/**
* @param array $words
*
* @return Collection
*/
public function transactions(array $words)
public function searchTransactions(array $words)
{
$query = \TransactionJournal::withRelevantData();
$fullCount = $query->count();
$query->where(
return \Auth::user()->transactionjournals()->withRelevantData()->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;
)->get();
}
}
/**
* @param array $words
*
* @return Collection
*/
public function searchAccounts(array $words)
{
return \Auth::user()->accounts()->with('accounttype')->where(
function ($q) use ($words) {
foreach ($words as $word) {
$q->orWhere('name', 'LIKE', '%' . e($word) . '%');
}
}
)->get();
}
/**
* @param array $words
*
* @return Collection
*/
public function searchCategories(array $words)
{
/** @var Collection $set */
$set = \Auth::user()->categories()->get();
$newSet = $set->filter(
function (\Category $c) use ($words) {
$found = 0;
foreach ($words as $word) {
if (!(strpos(strtolower($c->name), strtolower($word)) === false)) {
$found++;
}
}
return $found > 0;
}
);
return $newSet;
}
/**
* @param array $words
*
* @return Collection
*/
public function searchBudgets(array $words)
{
/** @var Collection $set */
$set = \Auth::user()->budgets()->get();
$newSet = $set->filter(
function (\Budget $b) use ($words) {
$found = 0;
foreach ($words as $word) {
if (!(strpos(strtolower($b->name), strtolower($word)) === false)) {
$found++;
}
}
return $found > 0;
}
);
return $newSet;
}
/**
* @param array $words
*
* @return Collection
*/
public function searchTags(array $words)
{
return new Collection;
}
}

View File

@@ -18,5 +18,26 @@ interface SearchInterface
/**
* @param array $words
*/
public function transactions(array $words);
}
public function searchTransactions(array $words);
/**
* @param array $words
*/
public function searchAccounts(array $words);
/**
* @param array $words
*/
public function searchCategories(array $words);
/**
* @param array $words
*/
public function searchBudgets(array $words);
/**
* @param array $words
*/
public function searchTags(array $words);
}