2020-06-07 11:30:02 +02:00
|
|
|
<?php
|
2020-06-30 19:05:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DeleteController.php
|
|
|
|
* Copyright (c) 2020 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-06-07 11:30:02 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Controllers\PiggyBank;
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2020-06-07 11:30:02 +02:00
|
|
|
use FireflyIII\Http\Controllers\Controller;
|
|
|
|
use FireflyIII\Models\PiggyBank;
|
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DeleteController
|
|
|
|
*/
|
|
|
|
class DeleteController extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
private PiggyBankRepositoryInterface $piggyRepos;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PiggyBankController constructor.
|
|
|
|
*
|
|
|
|
* @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.piggyBanks'));
|
2020-06-07 11:30:02 +02:00
|
|
|
app('view')->share('mainTitleIcon', 'fa-bullseye');
|
|
|
|
|
|
|
|
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a piggy bank.
|
|
|
|
*
|
|
|
|
* @param PiggyBank $piggyBank
|
|
|
|
*
|
|
|
|
* @return Factory|View
|
|
|
|
*/
|
|
|
|
public function delete(PiggyBank $piggyBank)
|
|
|
|
{
|
2021-03-28 11:46:23 +02:00
|
|
|
$subTitle = (string)trans('firefly.delete_piggy_bank', ['name' => $piggyBank->name]);
|
2020-06-07 11:30:02 +02:00
|
|
|
|
|
|
|
// put previous url in session
|
|
|
|
$this->rememberPreviousUri('piggy-banks.delete.uri');
|
|
|
|
|
2021-01-31 20:35:54 +01:00
|
|
|
return prefixView('piggy-banks.delete', compact('piggyBank', 'subTitle'));
|
2020-06-07 11:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the piggy bank.
|
|
|
|
*
|
|
|
|
* @param PiggyBank $piggyBank
|
|
|
|
*
|
|
|
|
* @return RedirectResponse
|
|
|
|
*/
|
|
|
|
public function destroy(PiggyBank $piggyBank): RedirectResponse
|
|
|
|
{
|
2021-03-28 11:46:23 +02:00
|
|
|
session()->flash('success', (string)trans('firefly.deleted_piggy_bank', ['name' => $piggyBank->name]));
|
2020-06-07 11:30:02 +02:00
|
|
|
app('preferences')->mark();
|
|
|
|
$this->piggyRepos->destroy($piggyBank);
|
|
|
|
|
|
|
|
return redirect($this->getPreviousUri('piggy-banks.delete.uri'));
|
|
|
|
}
|
|
|
|
}
|