firefly-iii/app/controllers/HomeController.php

114 lines
3.1 KiB
PHP
Raw Normal View History

2014-06-28 02:41:44 -05:00
<?php
use FireflyIII\Shared\Preferences\PreferencesInterface as Prefs;
2014-07-15 15:16:29 -05:00
/**
* Class HomeController
*
* @SuppressWarnings(PHPMD.CamelCasePropertyName)
2014-07-15 15:16:29 -05:00
*/
class HomeController extends BaseController
{
2014-07-15 15:16:29 -05:00
protected $_preferences;
/**
* @param Prefs $preferences
*/
public function __construct(Prefs $preferences)
{
2014-07-15 15:16:29 -05:00
$this->_preferences = $preferences;
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function sessionPrev()
{
/** @var \FireflyIII\Shared\Toolkit\Navigation $navigation */
$navigation = App::make('FireflyIII\Shared\Toolkit\Navigation');
$navigation->prev();
return Redirect::back();
//return Redirect::route('index');
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function sessionNext()
{
/** @var \FireflyIII\Shared\Toolkit\Navigation $navigation */
$navigation = App::make('FireflyIII\Shared\Toolkit\Navigation');
$navigation->next();
return Redirect::back();
//return Redirect::route('index');
}
/**
* @param $range
*
* @return \Illuminate\Http\RedirectResponse
*/
public function rangeJump($range)
{
2014-10-12 02:29:19 -05:00
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y',];
2014-10-12 02:29:19 -05:00
if (in_array($range, $valid)) {
$this->_preferences->set('viewRange', $range);
Session::forget('range');
}
return Redirect::back();
}
2014-08-09 01:18:07 -05:00
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function flush()
{
Cache::flush();
return Redirect::route('index');
}
2014-07-15 15:16:29 -05:00
/**
* @return $this|\Illuminate\View\View
*/
public function index()
{
// Event::fire('limits.check');
// Event::fire('piggybanks.check');
// Event::fire('recurring.check');
// count, maybe Firefly needs some introducing text to show:
/** @var \FireflyIII\Database\Account $acct */
$acct = App::make('FireflyIII\Database\Account');
/** @var \FireflyIII\Database\TransactionJournal $jrnls */
$jrnls = App::make('FireflyIII\Database\TransactionJournal');
$count = $acct->countAssetAccounts();
2014-08-09 01:18:07 -05:00
$start = Session::get('start');
$end = Session::get('end');
// get the preference for the home accounts to show:
$frontpage = $this->_preferences->get('frontpageAccounts', []);
2014-07-23 09:44:20 -05:00
if ($frontpage->data == []) {
$accounts = $acct->getAssetAccounts();
2014-07-21 00:40:38 -05:00
} else {
$accounts = $acct->getByIds($frontpage->data);
2014-07-21 00:40:38 -05:00
}
$transactions = [];
2014-07-23 09:44:20 -05:00
foreach ($accounts as $account) {
$set = $jrnls->getInDateRangeAccount($account, 10, $start, $end);
if (count($set) > 0) {
$transactions[] = [$set, $account];
}
}
// build the home screen:
2014-09-10 07:39:38 -05:00
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')
->with('subTitle', 'What\'s playing?')->with('mainTitleIcon', 'fa-fire');
}
2014-07-04 04:39:21 -05:00
}