2014-07-06 08:18:11 -05:00
|
|
|
<?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
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
class PreferencesController extends BaseController
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
protected $_accounts;
|
|
|
|
protected $_preferences;
|
2014-07-06 08:18:11 -05:00
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @param ARI $accounts
|
|
|
|
* @param PHI $preferences
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function __construct(ARI $accounts, PHI $preferences)
|
|
|
|
{
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
$this->_accounts = $accounts;
|
|
|
|
$this->_preferences = $preferences;
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return $this|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function index()
|
|
|
|
{
|
2014-07-15 15:16:29 -05:00
|
|
|
$accounts = $this->_accounts->getDefault();
|
2014-07-06 08:18:11 -05:00
|
|
|
|
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;
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
// 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-06 08:18:11 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2014-07-06 08:18:11 -05:00
|
|
|
public function postIndex()
|
|
|
|
{
|
2014-07-14 23:58:08 -05:00
|
|
|
|
|
|
|
// frontpage accounts
|
2014-07-06 08:18:11 -05:00
|
|
|
$frontpageAccounts = [];
|
2014-07-15 15:16:29 -05:00
|
|
|
foreach (Input::get('frontpageAccounts') as $id) {
|
2014-07-06 08:18:11 -05:00
|
|
|
$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');
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
Session::flash('success', 'Preferences saved!');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
return Redirect::route('preferences');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|