firefly-iii/app/Http/Controllers/SearchController.php

54 lines
1.6 KiB
PHP
Raw Normal View History

2015-02-27 04:09:23 -06:00
<?php namespace FireflyIII\Http\Controllers;
use FireflyIII\Support\Search\SearchInterface;
use Input;
/**
* Class SearchController
*
* @package FireflyIII\Http\Controllers
*/
2015-03-10 11:26:31 -05:00
class SearchController extends Controller
{
/**
* SearchController constructor.
*/
2016-01-08 11:29:47 -06:00
public function __construct()
{
2016-01-08 13:40:48 -06:00
parent::__construct();
2016-01-08 11:29:47 -06:00
}
2015-02-27 04:09:23 -06:00
/**
* Results always come in the form of an array [results, count, fullCount]
2015-05-03 05:58:55 -05:00
*
* @param SearchInterface $searcher
*
* @return $this
2015-02-27 04:09:23 -06:00
*/
public function index(SearchInterface $searcher)
{
$subTitle = null;
$query = null;
$result = [];
$title = trans('firefly.search');
$mainTitleIcon = 'fa-search';
2015-02-27 04:09:23 -06:00
if (!is_null(Input::get('q')) && strlen(Input::get('q')) > 0) {
$query = trim(Input::get('q'));
$words = explode(' ', $query);
$subTitle = trans('firefly.search_results_for', ['query' => $query]);
2016-02-05 12:25:17 -06:00
$transactions = $searcher->searchTransactions($words);
$accounts = $searcher->searchAccounts($words);
$categories = $searcher->searchCategories($words);
$budgets = $searcher->searchBudgets($words);
$tags = $searcher->searchTags($words);
2015-02-27 04:09:23 -06:00
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
}
return view('search.index', compact('title', 'subTitle', 'mainTitleIcon', 'query', 'result'));
2015-02-27 04:09:23 -06:00
}
}