firefly-iii/app/controllers/PreferencesController.php

76 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2014-07-15 15:16:29 -05:00
/**
* Class PreferencesController
*
2014-12-21 04:15:37 -06:00
*
2014-07-15 15:16:29 -05:00
*/
class PreferencesController extends BaseController
{
2014-07-15 15:16:29 -05:00
/**
*
2014-07-15 15:16:29 -05:00
*/
public function __construct()
{
View::share('title', 'Preferences');
View::share('mainTitleIcon', 'fa-gear');
}
2014-07-15 15:16:29 -05:00
/**
* @return $this|\Illuminate\View\View
*/
public function index()
{
2014-12-13 15:54:52 -06:00
/** @var \FireflyIII\Database\Account\Account $acct */
$acct = App::make('FireflyIII\Database\Account\Account');
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
2014-07-14 23:58:08 -05:00
2015-01-17 00:25:44 -06:00
$accounts = $acct->getAccountsByType(['Default account', 'Asset account']);
2014-11-12 15:36:02 -06:00
$viewRange = $preferences->get('viewRange', '1M');
$viewRangeValue = $viewRange->data;
2014-12-24 14:20:47 -06:00
$frontPage = $preferences->get('frontPageAccounts', []);
$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(
'viewRange', $viewRangeValue
);
}
2014-07-15 15:16:29 -05:00
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function postIndex()
{
/** @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-12-24 14:20:47 -06:00
$preferences->set('frontPageAccounts', $frontPageAccounts);
2014-07-14 23:58:08 -05:00
// view range:
$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');
// budget maximum:
$budgetMaximum = intval(Input::get('budgetMaximum'));
$preferences->set('budgetMaximum', $budgetMaximum);
Session::flash('success', 'Preferences saved!');
2014-07-28 14:33:32 -05:00
return Redirect::route('preferences');
}
2015-01-01 23:16:49 -06:00
}