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-21 04:15:37 -06:00
|
|
|
$frontPage = $preferences->get('frontpageAccounts', []);
|
|
|
|
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-12-21 04:15:37 -06:00
|
|
|
return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontPage)->with('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-07-14 23:58:08 -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
|
|
|
// frontpage accounts
|
2014-07-06 08:18:11 -05:00
|
|
|
$frontpageAccounts = [];
|
2014-07-15 15:16:29 -05:00
|
|
|
foreach (Input::get('frontpageAccounts') as $id) {
|
2014-07-06 08:18:11 -05:00
|
|
|
$frontpageAccounts[] = intval($id);
|
|
|
|
}
|
2014-11-12 00:31:48 -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-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');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|