2015-02-25 14:19:06 -06:00
|
|
|
<?php namespace FireflyIII\Http\Controllers;
|
|
|
|
|
2015-05-14 02:59:30 -05:00
|
|
|
use Config;
|
2015-12-30 01:00:52 -06:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
2015-02-25 14:19:06 -06:00
|
|
|
use Input;
|
2015-03-10 11:26:31 -05:00
|
|
|
use Preferences;
|
|
|
|
use Session;
|
|
|
|
use View;
|
|
|
|
|
2015-02-25 14:19:06 -06:00
|
|
|
/**
|
|
|
|
* Class PreferencesController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
2015-03-10 11:26:31 -05:00
|
|
|
class PreferencesController extends Controller
|
|
|
|
{
|
2015-02-25 14:19:06 -06:00
|
|
|
|
|
|
|
/**
|
2016-02-04 00:28:39 -06:00
|
|
|
*
|
2015-02-25 14:19:06 -06:00
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2015-04-28 08:26:30 -05:00
|
|
|
parent::__construct();
|
2015-05-14 08:53:56 -05:00
|
|
|
View::share('title', trans('firefly.preferences'));
|
2015-02-25 14:19:06 -06:00
|
|
|
View::share('mainTitleIcon', 'fa-gear');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-30 01:00:52 -06:00
|
|
|
* @param ARI $repository
|
2015-05-03 05:58:55 -05:00
|
|
|
*
|
2015-02-25 14:19:06 -06:00
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2015-12-30 01:00:52 -06:00
|
|
|
public function index(ARI $repository)
|
2015-02-25 14:19:06 -06:00
|
|
|
{
|
2016-01-27 14:52:21 -06:00
|
|
|
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
|
|
|
$viewRangePref = Preferences::get('viewRange', '1M');
|
|
|
|
$viewRange = $viewRangePref->data;
|
|
|
|
$frontPageAccounts = Preferences::get('frontPageAccounts', []);
|
|
|
|
$budgetMax = Preferences::get('budgetMaximum', 1000);
|
|
|
|
$language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
|
|
|
|
$budgetMaximum = $budgetMax->data;
|
|
|
|
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
|
|
|
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
|
|
|
|
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
|
2015-02-25 14:19:06 -06:00
|
|
|
|
2015-12-24 01:35:08 -06:00
|
|
|
$showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', 'false') == 'true';
|
|
|
|
|
2016-01-27 14:52:21 -06:00
|
|
|
return view(
|
|
|
|
'preferences.index',
|
|
|
|
compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange', 'customFiscalYear', 'fiscalYearStart', 'showIncomplete')
|
|
|
|
);
|
2015-02-25 14:19:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function postIndex()
|
|
|
|
{
|
|
|
|
// front page accounts
|
|
|
|
$frontPageAccounts = [];
|
2015-05-14 05:10:42 -05:00
|
|
|
if (is_array(Input::get('frontPageAccounts'))) {
|
|
|
|
foreach (Input::get('frontPageAccounts') as $id) {
|
|
|
|
$frontPageAccounts[] = intval($id);
|
|
|
|
}
|
|
|
|
Preferences::set('frontPageAccounts', $frontPageAccounts);
|
2015-02-25 14:19:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// view range:
|
|
|
|
Preferences::set('viewRange', Input::get('viewRange'));
|
|
|
|
// forget session values:
|
|
|
|
Session::forget('start');
|
|
|
|
Session::forget('end');
|
|
|
|
Session::forget('range');
|
|
|
|
|
|
|
|
// budget maximum:
|
|
|
|
$budgetMaximum = intval(Input::get('budgetMaximum'));
|
|
|
|
Preferences::set('budgetMaximum', $budgetMaximum);
|
|
|
|
|
2016-01-22 05:09:02 -06:00
|
|
|
// custom fiscal year
|
2016-01-27 14:52:21 -06:00
|
|
|
$customFiscalYear = (int)Input::get('customFiscalYear');
|
2016-01-22 05:09:02 -06:00
|
|
|
Preferences::set('customFiscalYear', $customFiscalYear);
|
2016-01-24 00:47:39 -06:00
|
|
|
$fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart')));
|
|
|
|
Preferences::set('fiscalYearStart', $fiscalYearStart);
|
2016-01-22 05:09:02 -06:00
|
|
|
|
2015-05-14 02:59:30 -05:00
|
|
|
// language:
|
|
|
|
$lang = Input::get('language');
|
2015-12-24 01:35:08 -06:00
|
|
|
if (in_array($lang, array_keys(Config::get('firefly.languages')))) {
|
2015-05-14 02:59:30 -05:00
|
|
|
Preferences::set('language', $lang);
|
|
|
|
}
|
|
|
|
|
2015-02-25 14:19:06 -06:00
|
|
|
|
|
|
|
Session::flash('success', 'Preferences saved!');
|
2015-06-02 10:44:50 -05:00
|
|
|
Preferences::mark();
|
2015-02-25 14:19:06 -06:00
|
|
|
|
2015-07-06 09:27:21 -05:00
|
|
|
return redirect(route('preferences'));
|
2015-02-25 14:19:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|