2014-07-06 08:18:11 -05:00
|
|
|
<?php
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* Class PreferencesController
|
2014-09-09 13:00:04 -05:00
|
|
|
*
|
2014-12-21 04:15:37 -06:00
|
|
|
* @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
|
|
|
|
*
|
2014-07-15 15:16:29 -05:00
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
class PreferencesController extends BaseController
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
2014-11-12 00:31:48 -06:00
|
|
|
*
|
2014-07-15 15:16:29 -05:00
|
|
|
*/
|
2014-11-12 00:31:48 -06:00
|
|
|
public function __construct()
|
2014-07-06 08:18:11 -05:00
|
|
|
{
|
|
|
|
|
2014-11-12 00:31:48 -06:00
|
|
|
View::share('title', 'Preferences');
|
|
|
|
View::share('mainTitleIcon', 'fa-gear');
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function index()
|
|
|
|
{
|
2014-12-13 15:54:52 -06:00
|
|
|
/** @var \FireflyIII\Database\Account\Account $acct */
|
|
|
|
$acct = App::make('FireflyIII\Database\Account\Account');
|
2014-07-06 08:18:11 -05:00
|
|
|
|
2014-11-12 00:31:48 -06:00
|
|
|
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
|
|
|
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
2014-07-14 23:58:08 -05:00
|
|
|
|
2014-11-12 15:36:02 -06:00
|
|
|
$accounts = $acct->getAssetAccounts();
|
|
|
|
$viewRange = $preferences->get('viewRange', '1M');
|
2014-11-12 00:31:48 -06:00
|
|
|
$viewRangeValue = $viewRange->data;
|
2014-12-24 14:20:47 -06:00
|
|
|
$frontPage = $preferences->get('frontPageAccounts', []);
|
2014-12-23 14:13:59 -06:00
|
|
|
$budgetMax = $preferences->get('budgetMaximum', 1000);
|
|
|
|
$budgetMaximum = $budgetMax->data;
|
2014-12-21 04:15:37 -06:00
|
|
|
|
2014-12-24 14:20:47 -06:00
|
|
|
return View::make('preferences.index', compact('budgetMaximum'))->with('accounts', $accounts)->with('frontPageAccounts', $frontPage)->with(
|
2014-12-23 14:13:59 -06:00
|
|
|
'viewRange', $viewRangeValue
|
|
|
|
);
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function postIndex()
|
|
|
|
{
|
2014-11-12 00:31:48 -06:00
|
|
|
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
|
|
|
|
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
|
|
|
|
|
2014-12-24 14:20:47 -06:00
|
|
|
// front page accounts
|
|
|
|
$frontPageAccounts = [];
|
|
|
|
foreach (Input::get('frontPageAccounts') as $id) {
|
|
|
|
$frontPageAccounts[] = intval($id);
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
2014-12-24 14:20:47 -06:00
|
|
|
$preferences->set('frontPageAccounts', $frontPageAccounts);
|
2014-07-14 23:58:08 -05:00
|
|
|
|
|
|
|
// view range:
|
2014-11-12 00:31:48 -06:00
|
|
|
$preferences->set('viewRange', Input::get('viewRange'));
|
2014-07-14 23:58:08 -05:00
|
|
|
// forget session values:
|
|
|
|
Session::forget('start');
|
|
|
|
Session::forget('end');
|
|
|
|
Session::forget('range');
|
|
|
|
|
2014-12-23 14:13:59 -06:00
|
|
|
// budget maximum:
|
|
|
|
$budgetMaximum = intval(Input::get('budgetMaximum'));
|
|
|
|
$preferences->set('budgetMaximum', $budgetMaximum);
|
|
|
|
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
Session::flash('success', 'Preferences saved!');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
return Redirect::route('preferences');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|