Files
firefly-iii/app/Http/Controllers/RuleGroup/CreateController.php

109 lines
3.2 KiB
PHP
Raw Normal View History

2019-07-21 17:15:06 +02:00
<?php
/**
* CreateController.php
2020-01-31 07:32:04 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-08-17 12:09:03 +02:00
declare(strict_types=1);
2019-07-21 17:15:06 +02:00
namespace FireflyIII\Http\Controllers\RuleGroup;
2021-03-28 11:46:23 +02:00
2019-07-21 17:15:06 +02:00
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\RuleGroupFormRequest;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
2019-07-21 17:15:06 +02:00
/**
* Class CreateController
*/
class CreateController extends Controller
{
/** @var RuleGroupRepositoryInterface */
private $repository;
/**
* CreateController constructor.
*
2019-07-21 17:15:06 +02:00
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
$this->middleware(
function ($request, $next) {
2021-03-28 11:46:23 +02:00
app('view')->share('title', (string)trans('firefly.rules'));
2019-07-21 17:15:06 +02:00
app('view')->share('mainTitleIcon', 'fa-random');
$this->repository = app(RuleGroupRepositoryInterface::class);
return $next($request);
}
);
}
/**
* Create a new rule group.
*
* @return Factory|View
2019-07-21 17:15:06 +02:00
*/
public function create()
{
$subTitleIcon = 'fa-clone';
2021-03-28 11:46:23 +02:00
$subTitle = (string)trans('firefly.make_new_rule_group');
2019-07-21 17:15:06 +02:00
// put previous url in session if not redirect from store (not "create another").
if (true !== session('rule-groups.create.fromStore')) {
$this->rememberPreviousUri('rule-groups.create.uri');
}
session()->forget('rule-groups.create.fromStore');
return prefixView('rules.rule-group.create', compact('subTitleIcon', 'subTitle'));
2019-07-21 17:15:06 +02:00
}
/**
* Store the rule group.
*
* @param RuleGroupFormRequest $request
*
* @return RedirectResponse|Redirector
2019-07-21 17:15:06 +02:00
*/
public function store(RuleGroupFormRequest $request)
{
$data = $request->getRuleGroupData();
2019-07-21 17:15:06 +02:00
$ruleGroup = $this->repository->store($data);
2021-03-28 11:46:23 +02:00
session()->flash('success', (string)trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
2019-07-21 17:15:06 +02:00
app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('rule-groups.create.uri'));
2021-03-28 11:46:23 +02:00
if (1 === (int)$request->get('create_another')) {
2021-04-07 07:28:43 +02:00
2019-07-21 17:15:06 +02:00
session()->put('rule-groups.create.fromStore', true);
$redirect = redirect(route('rule-groups.create'))->withInput();
2021-04-07 07:28:43 +02:00
2019-07-21 17:15:06 +02:00
}
return $redirect;
}
2019-08-17 12:09:03 +02:00
}