2016-01-11 13:41:57 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* RuleController.php
|
|
|
|
* Copyright (C) 2016 Sander Dorigo
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers;
|
|
|
|
|
2016-01-13 08:59:45 -06:00
|
|
|
use Auth;
|
2016-01-11 13:41:57 -06:00
|
|
|
use FireflyIII\Http\Requests;
|
2016-01-13 11:34:56 -06:00
|
|
|
use FireflyIII\Http\Requests\RuleGroupFormRequest;
|
2016-01-13 09:05:39 -06:00
|
|
|
use FireflyIII\Models\Rule;
|
2016-01-13 09:08:05 -06:00
|
|
|
use FireflyIII\Models\RuleGroup;
|
2016-01-13 11:34:56 -06:00
|
|
|
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
|
|
|
use Input;
|
|
|
|
use Preferences;
|
|
|
|
use Session;
|
|
|
|
use URL;
|
2016-01-11 13:41:57 -06:00
|
|
|
use View;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RuleController
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Controllers
|
|
|
|
*/
|
|
|
|
class RuleController extends Controller
|
|
|
|
{
|
2016-01-12 13:56:53 -06:00
|
|
|
/**
|
|
|
|
* RuleController constructor.
|
|
|
|
*/
|
2016-01-11 13:41:57 -06:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
View::share('title', trans('firefly.rules'));
|
|
|
|
View::share('mainTitleIcon', 'fa-random');
|
|
|
|
}
|
|
|
|
|
2016-01-13 11:34:56 -06:00
|
|
|
/**
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function createRuleGroup()
|
|
|
|
{
|
|
|
|
$subTitleIcon = 'fa-clone';
|
|
|
|
$subTitle = trans('firefly.make_new_rule_group');
|
|
|
|
|
|
|
|
// put previous url in session if not redirect from store (not "create another").
|
2016-01-13 11:50:15 -06:00
|
|
|
if (Session::get('rules.rule-group.create.fromStore') !== true) {
|
|
|
|
Session::put('rules.rule-group.create.url', URL::previous());
|
2016-01-13 11:34:56 -06:00
|
|
|
}
|
|
|
|
Session::forget('accounts.create.fromStore');
|
|
|
|
Session::flash('gaEventCategory', 'rules');
|
|
|
|
Session::flash('gaEventAction', 'create-rule-group');
|
|
|
|
|
2016-01-13 11:50:15 -06:00
|
|
|
return view('rules.rule-group.create', compact('subTitleIcon', 'what', 'subTitle'));
|
2016-01-13 11:34:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param RuleGroupFormRequest $request
|
|
|
|
* @param RuleRepositoryInterface $repository
|
|
|
|
*
|
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
|
|
*/
|
|
|
|
public function storeRuleGroup(RuleGroupFormRequest $request, RuleRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'title' => $request->input('title'),
|
|
|
|
'description' => $request->input('description'),
|
|
|
|
'user' => Auth::user()->id,
|
|
|
|
];
|
|
|
|
|
|
|
|
$ruleGroup = $repository->storeRuleGroup($data);
|
|
|
|
|
|
|
|
Session::flash('success', trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
|
|
|
|
Preferences::mark();
|
|
|
|
|
|
|
|
if (intval(Input::get('create_another')) === 1) {
|
|
|
|
// set value so create routine will not overwrite URL:
|
2016-01-13 11:50:15 -06:00
|
|
|
Session::put('rules.rule-group.create.fromStore', true);
|
2016-01-13 11:34:56 -06:00
|
|
|
|
|
|
|
return redirect(route('rules.rule-group.create'))->withInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
// redirect to previous URL.
|
2016-01-13 11:50:15 -06:00
|
|
|
return redirect(Session::get('rules.rule-group.create.url'));
|
2016-01-13 11:34:56 -06:00
|
|
|
}
|
2016-01-11 13:41:57 -06:00
|
|
|
|
2016-01-13 11:50:15 -06:00
|
|
|
|
2016-01-12 13:56:53 -06:00
|
|
|
/**
|
2016-01-13 11:50:15 -06:00
|
|
|
* @param RuleGroup $ruleGroup
|
|
|
|
*
|
2016-01-12 13:56:53 -06:00
|
|
|
* @return View
|
|
|
|
*/
|
2016-01-13 11:50:15 -06:00
|
|
|
public function editRuleGroup(RuleGroup $ruleGroup)
|
2016-01-11 13:41:57 -06:00
|
|
|
{
|
2016-01-13 11:50:15 -06:00
|
|
|
$subTitle = trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
|
|
|
|
|
|
|
|
// put previous url in session if not redirect from store (not "return_to_edit").
|
|
|
|
if (Session::get('rules.rule-group.edit.fromUpdate') !== true) {
|
|
|
|
Session::put('rules.rule-group.edit.url', URL::previous());
|
|
|
|
}
|
|
|
|
Session::forget('rules.rule-group.edit.fromUpdate');
|
|
|
|
Session::flash('gaEventCategory', 'rules');
|
|
|
|
Session::flash('gaEventAction', 'edit-rule-group');
|
|
|
|
|
|
|
|
return view('rules.rule-group.edit', compact('ruleGroup', 'subTitle'));
|
2016-01-13 08:59:45 -06:00
|
|
|
|
2016-01-11 13:41:57 -06:00
|
|
|
}
|
2016-01-13 09:05:39 -06:00
|
|
|
|
|
|
|
/**
|
2016-01-13 11:50:15 -06:00
|
|
|
* @param RuleGroupFormRequest $request
|
|
|
|
* @param RuleRepositoryInterface $repository
|
|
|
|
* @param RuleGroup $ruleGroup
|
|
|
|
*
|
|
|
|
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
2016-01-13 09:05:39 -06:00
|
|
|
*/
|
2016-01-13 11:50:15 -06:00
|
|
|
public function updateRuleGroup(RuleGroupFormRequest $request, RuleRepositoryInterface $repository, RuleGroup $ruleGroup)
|
2016-01-13 09:05:39 -06:00
|
|
|
{
|
2016-01-13 11:50:15 -06:00
|
|
|
$data = [
|
|
|
|
'title' => $request->input('title'),
|
|
|
|
'description' => $request->input('description'),
|
|
|
|
'active' => intval($request->input('active')) == 1,
|
|
|
|
];
|
|
|
|
|
2016-01-13 14:44:26 -06:00
|
|
|
$repository->updateRuleGroup($ruleGroup, $data);
|
2016-01-13 11:50:15 -06:00
|
|
|
|
|
|
|
Session::flash('success', trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]));
|
|
|
|
Preferences::mark();
|
|
|
|
|
|
|
|
if (intval(Input::get('return_to_edit')) === 1) {
|
|
|
|
// set value so edit routine will not overwrite URL:
|
|
|
|
Session::put('rules.rule-group.edit.fromUpdate', true);
|
|
|
|
|
|
|
|
return redirect(route('rules.rule-group.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// redirect to previous URL.
|
|
|
|
return redirect(Session::get('rules.rule-group.edit.url'));
|
2016-01-13 09:05:39 -06:00
|
|
|
|
|
|
|
}
|
2016-01-13 09:08:05 -06:00
|
|
|
|
2016-01-13 14:44:26 -06:00
|
|
|
/**
|
|
|
|
* @param RuleGroup $budget
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
|
|
|
public function deleteRuleGroup(RuleGroup $ruleGroup)
|
|
|
|
{
|
|
|
|
$subTitle = trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]);
|
|
|
|
|
|
|
|
// put previous url in session
|
|
|
|
Session::put('rules.rule-group.delete.url', URL::previous());
|
|
|
|
Session::flash('gaEventCategory', 'rules');
|
|
|
|
Session::flash('gaEventAction', 'delete-rule-group');
|
|
|
|
|
|
|
|
return view('rules.rule-group.delete', compact('ruleGroup', 'subTitle'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param RuleGroup $ruleGroup
|
|
|
|
* @param RuleRepositoryInterface $repository
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function destroyRuleGroup(RuleGroup $ruleGroup, RuleRepositoryInterface $repository)
|
|
|
|
{
|
|
|
|
|
|
|
|
$title = $ruleGroup->title;
|
|
|
|
$repository->destroyRuleGroup($ruleGroup);
|
|
|
|
|
|
|
|
|
|
|
|
Session::flash('success', trans('firefly.deleted_rule_group', ['title' => $title]));
|
|
|
|
Preferences::mark();
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(Session::get('rules.rule-group.delete.url'));
|
|
|
|
}
|
|
|
|
|
2016-01-13 11:50:15 -06:00
|
|
|
|
2016-01-13 09:08:05 -06:00
|
|
|
/**
|
2016-01-13 11:50:15 -06:00
|
|
|
* @return View
|
2016-01-13 09:08:05 -06:00
|
|
|
*/
|
2016-01-13 11:50:15 -06:00
|
|
|
public function index()
|
2016-01-13 11:34:56 -06:00
|
|
|
{
|
2016-01-13 11:50:15 -06:00
|
|
|
$ruleGroups = Auth::user()->ruleGroups()->with('rules')->get();
|
2016-01-13 09:08:05 -06:00
|
|
|
|
2016-01-13 11:50:15 -06:00
|
|
|
return view('rules.index', compact('ruleGroups'));
|
2016-01-13 09:08:05 -06:00
|
|
|
}
|
2016-01-13 11:50:15 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Rule $rule
|
|
|
|
*/
|
|
|
|
public function upRule(Rule $rule)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-11 13:41:57 -06:00
|
|
|
}
|