firefly-iii/app/controllers/SearchController.php

39 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2014-09-22 00:25:14 -05:00
2014-08-10 08:01:46 -05:00
/**
* Class SearchController
*/
class SearchController extends BaseController
{
2014-08-10 08:01:46 -05:00
/**
2014-09-22 00:25:14 -05:00
* Results always come in the form of an array [results, count, fullCount]
2014-08-10 08:01:46 -05:00
*/
public function index()
{
/** @var \FireflyIII\Search\Search $searcher */
$searcher = App::make('FireflyIII\Search\Search');
2014-09-22 00:25:14 -05:00
$subTitle = null;
2014-09-26 23:06:31 -05:00
$rawQuery = null;
2014-11-12 15:36:02 -06:00
$result = [];
2014-12-30 11:44:49 -06:00
if (!is_null(Input::get('q')) && strlen(Input::get('q')) > 0) {
2014-09-22 00:25:14 -05:00
$rawQuery = trim(Input::get('q'));
$words = explode(' ', $rawQuery);
$subTitle = 'Results for "' . e($rawQuery) . '"';
$transactions = $searcher->searchTransactions($words);
$accounts = $searcher->searchAccounts($words);
$categories = $searcher->searchCategories($words);
$budgets = $searcher->searchBudgets($words);
$tags = $searcher->searchTags($words);
2014-11-12 15:36:02 -06:00
$result = ['transactions' => $transactions, 'accounts' => $accounts, 'categories' => $categories, 'budgets' => $budgets, 'tags' => $tags];
2014-09-22 00:25:14 -05:00
}
return View::make('search.index')->with('title', 'Search')->with('subTitle', $subTitle)->with(
'mainTitleIcon', 'fa-search'
2014-11-12 15:36:02 -06:00
)->with('query', $rawQuery)->with('result', $result);
}
2015-01-01 23:16:49 -06:00
}