| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2024-11-25 04:18:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * DeleteController.php | 
					
						
							| 
									
										
										
										
											2020-01-31 07:32:04 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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-06-25 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers\Category; | 
					
						
							| 
									
										
										
										
											2021-03-28 11:46:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  | use FireflyIII\Http\Controllers\Controller; | 
					
						
							|  |  |  | use FireflyIII\Models\Category; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  | use Illuminate\Contracts\View\Factory; | 
					
						
							|  |  |  | use Illuminate\Http\RedirectResponse; | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  | use Illuminate\Routing\Redirector; | 
					
						
							|  |  |  | use Illuminate\View\View; | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class DeleteController | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class DeleteController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** @var CategoryRepositoryInterface The category repository */ | 
					
						
							|  |  |  |     private $repository; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * CategoryController constructor. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::__construct(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->middleware( | 
					
						
							|  |  |  |             function ($request, $next) { | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |                 app('view')->share('title', (string) trans('firefly.categories')); | 
					
						
							| 
									
										
										
										
											2020-05-01 18:54:08 -03:00
										 |  |  |                 app('view')->share('mainTitleIcon', 'fa-bookmark'); | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  |                 $this->repository = app(CategoryRepositoryInterface::class); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return $next($request); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Delete a category. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2020-03-17 15:01:00 +01:00
										 |  |  |      * @return Factory|View | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function delete(Category $category) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         $subTitle = (string) trans('firefly.delete_category', ['name' => $category->name]); | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // put previous url in session
 | 
					
						
							| 
									
										
										
										
											2022-04-12 18:19:30 +02:00
										 |  |  |         $this->rememberPreviousUrl('categories.delete.url'); | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-29 14:11:12 +01:00
										 |  |  |         return view('categories.delete', compact('category', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Destroy a category. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * @return Redirector|RedirectResponse | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function destroy(Request $request, Category $category) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $name = $category->name; | 
					
						
							|  |  |  |         $this->repository->destroy($category); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         $request->session()->flash('success', (string) trans('firefly.deleted_category', ['name' => $name])); | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  |         app('preferences')->mark(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 18:19:30 +02:00
										 |  |  |         return redirect($this->getPreviousUrl('categories.delete.url')); | 
					
						
							| 
									
										
										
										
											2019-06-25 19:24:01 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-17 12:09:03 +02:00
										 |  |  | } |