firefly-iii/app/controllers/PreferencesController.php

66 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2014-07-15 15:16:29 -05:00
/**
* Class PreferencesController
*
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()
{
/** @var \FireflyIII\Database\Account $acct */
$acct = App::make('FireflyIII\Database\Account');
/** @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');
$viewRangeValue = $viewRange->data;
2014-11-12 15:36:02 -06:00
$frontpage = $preferences->get('frontpageAccounts', []);
2014-07-28 14:33:32 -05:00
2014-11-12 15:36:02 -06:00
return View::make('preferences.index')->with('accounts', $accounts)->with('frontpageAccounts', $frontpage)->with('viewRange', $viewRangeValue);
}
2014-07-15 15:16:29 -05:00
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function postIndex()
{
2014-07-14 23:58:08 -05:00
/** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
$preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
2014-07-14 23:58:08 -05:00
// frontpage accounts
$frontpageAccounts = [];
2014-07-15 15:16:29 -05:00
foreach (Input::get('frontpageAccounts') as $id) {
$frontpageAccounts[] = intval($id);
}
$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');
Session::flash('success', 'Preferences saved!');
2014-07-28 14:33:32 -05:00
return Redirect::route('preferences');
}
}