2015-02-25 14:19:06 -06:00
|
|
|
<?php namespace FireflyIII\Http\Controllers;
|
|
|
|
|
2015-05-14 02:59:30 -05:00
|
|
|
use Config;
|
2015-04-21 10:19:14 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
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
|
|
|
|
|
|
|
/**
|
2015-05-23 13:49:57 -05:00
|
|
|
* @codeCoverageIgnore
|
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-05-03 05:58:55 -05:00
|
|
|
* @param AccountRepositoryInterface $repository
|
|
|
|
*
|
2015-02-25 14:19:06 -06:00
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2015-04-21 10:19:14 -05:00
|
|
|
public function index(AccountRepositoryInterface $repository)
|
2015-02-25 14:19:06 -06:00
|
|
|
{
|
2015-05-05 03:23:01 -05: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);
|
2015-12-19 13:54:27 -06:00
|
|
|
$language = Preferences::get('language', env('DEFAULT_LANGUAGE','en_US'))->data;
|
2015-05-05 03:23:01 -05:00
|
|
|
$budgetMaximum = $budgetMax->data;
|
2015-02-25 14:19:06 -06:00
|
|
|
|
2015-05-14 02:59:30 -05:00
|
|
|
return view('preferences.index', compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange'));
|
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);
|
|
|
|
|
2015-05-14 02:59:30 -05:00
|
|
|
// language:
|
|
|
|
$lang = Input::get('language');
|
|
|
|
if (in_array($lang, array_keys(Config::get('firefly.lang')))) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|