mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-30 06:50:49 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			99 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php namespace FireflyIII\Http\Controllers;
 | |
| 
 | |
| use Config;
 | |
| use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
 | |
| use Input;
 | |
| use Preferences;
 | |
| use Session;
 | |
| use View;
 | |
| 
 | |
| /**
 | |
|  * Class PreferencesController
 | |
|  *
 | |
|  * @package FireflyIII\Http\Controllers
 | |
|  */
 | |
| class PreferencesController extends Controller
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      *
 | |
|      */
 | |
|     public function __construct()
 | |
|     {
 | |
|         parent::__construct();
 | |
|         View::share('title', trans('firefly.preferences'));
 | |
|         View::share('mainTitleIcon', 'fa-gear');
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @param ARI $repository
 | |
|      *
 | |
|      * @return $this|\Illuminate\View\View
 | |
|      */
 | |
|     public function index(ARI $repository)
 | |
|     {
 | |
|         $accounts           = $repository->getAccounts(['Default account', 'Asset account']);
 | |
|         $viewRangePref      = Preferences::get('viewRange', '1M');
 | |
|         $viewRange          = $viewRangePref->data;
 | |
|         $frontPageAccounts  = Preferences::get('frontPageAccounts', []);
 | |
|         $budgetMax          = Preferences::get('budgetMaximum', 1000);
 | |
|         $language           = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
 | |
|         $budgetMaximum      = $budgetMax->data;
 | |
|         $customFiscalYear   = Preferences::get('customFiscalYear', 0)->data;
 | |
|         $fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
 | |
|         $fiscalYearStart    = date('Y') . '-' . $fiscalYearStartStr;
 | |
| 
 | |
|         $showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', 'false') == 'true';
 | |
| 
 | |
|         return view(
 | |
|             'preferences.index',
 | |
|             compact('budgetMaximum', 'language', 'accounts', 'frontPageAccounts', 'viewRange', 'customFiscalYear', 'fiscalYearStart', 'showIncomplete')
 | |
|         );
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @return \Illuminate\Http\RedirectResponse
 | |
|      */
 | |
|     public function postIndex()
 | |
|     {
 | |
|         // front page accounts
 | |
|         $frontPageAccounts = [];
 | |
|         if (is_array(Input::get('frontPageAccounts'))) {
 | |
|             foreach (Input::get('frontPageAccounts') as $id) {
 | |
|                 $frontPageAccounts[] = intval($id);
 | |
|             }
 | |
|             Preferences::set('frontPageAccounts', $frontPageAccounts);
 | |
|         }
 | |
| 
 | |
|         // 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);
 | |
| 
 | |
|         // custom fiscal year
 | |
|         $customFiscalYear = (int)Input::get('customFiscalYear');
 | |
|         Preferences::set('customFiscalYear', $customFiscalYear);
 | |
|         $fiscalYearStart = date('m-d', strtotime(Input::get('fiscalYearStart')));
 | |
|         Preferences::set('fiscalYearStart', $fiscalYearStart);
 | |
| 
 | |
|         // language:
 | |
|         $lang = Input::get('language');
 | |
|         if (in_array($lang, array_keys(Config::get('firefly.languages')))) {
 | |
|             Preferences::set('language', $lang);
 | |
|         }
 | |
| 
 | |
| 
 | |
|         Session::flash('success', 'Preferences saved!');
 | |
|         Preferences::mark();
 | |
| 
 | |
|         return redirect(route('preferences'));
 | |
|     }
 | |
| 
 | |
| }
 |