firefly-iii/app/Http/Controllers/PreferencesController.php

99 lines
3.1 KiB
PHP
Raw Normal View History

2015-02-25 14:19:06 -06:00
<?php namespace FireflyIII\Http\Controllers;
2015-05-14 02:59:30 -05:00
use Config;
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');
}
/**
* @param ARI $repository
2015-05-03 05:58:55 -05:00
*
2015-02-25 14:19:06 -06:00
* @return $this|\Illuminate\View\View
*/
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);
// custom fiscal year
2016-01-27 14:52:21 -06:00
$customFiscalYear = (int)Input::get('customFiscalYear');
Preferences::set('customFiscalYear', $customFiscalYear);
$fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart')));
Preferences::set('fiscalYearStart', $fiscalYearStart);
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!');
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
}
}