firefly-iii/app/controllers/PreferencesController.php

67 lines
1.7 KiB
PHP
Raw Normal View History

<?php
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
2014-07-15 15:16:29 -05:00
/**
* Class PreferencesController
*/
class PreferencesController extends BaseController
{
2014-07-15 15:16:29 -05:00
protected $_accounts;
protected $_preferences;
2014-07-15 15:16:29 -05:00
/**
* @param ARI $accounts
* @param PHI $preferences
*/
public function __construct(ARI $accounts, PHI $preferences)
{
2014-07-15 15:16:29 -05:00
$this->_accounts = $accounts;
$this->_preferences = $preferences;
}
2014-07-15 15:16:29 -05:00
/**
* @return $this|\Illuminate\View\View
*/
public function index()
{
2014-07-15 15:16:29 -05:00
$accounts = $this->_accounts->getDefault();
2014-07-15 15:16:29 -05:00
$viewRange = $this->_preferences->get('viewRange', '1M');
2014-07-14 23:58:08 -05:00
$viewRangeValue = $viewRange->data;
// pref:
2014-07-15 15:16:29 -05:00
$frontpage = $this->_preferences->get('frontpageAccounts', []);
2014-07-28 14:33:32 -05:00
2014-07-15 15:16:29 -05: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
// frontpage accounts
$frontpageAccounts = [];
2014-07-15 15:16:29 -05:00
foreach (Input::get('frontpageAccounts') as $id) {
$frontpageAccounts[] = intval($id);
}
2014-07-15 15:16:29 -05:00
$this->_preferences->set('frontpageAccounts', $frontpageAccounts);
2014-07-14 23:58:08 -05:00
// view range:
2014-07-15 15:16:29 -05:00
$this->_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');
}
}