194e35917SGreg Roach<?php 294e35917SGreg Roach 394e35917SGreg Roach/** 494e35917SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 694e35917SGreg Roach * This program is free software: you can redistribute it and/or modify 794e35917SGreg Roach * it under the terms of the GNU General Public License as published by 894e35917SGreg Roach * the Free Software Foundation, either version 3 of the License, or 994e35917SGreg Roach * (at your option) any later version. 1094e35917SGreg Roach * This program is distributed in the hope that it will be useful, 1194e35917SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1294e35917SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1394e35917SGreg Roach * GNU General Public License for more details. 1494e35917SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 1694e35917SGreg Roach */ 1794e35917SGreg Roach 1894e35917SGreg Roachdeclare(strict_types=1); 1994e35917SGreg Roach 2094e35917SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 2194e35917SGreg Roach 2294e35917SGreg Roachuse Fisharebest\Webtrees\Services\MapDataService; 2394e35917SGreg Roachuse Psr\Http\Message\ResponseInterface; 2494e35917SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 2594e35917SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 2694e35917SGreg Roach 2794e35917SGreg Roachuse function redirect; 2894e35917SGreg Roachuse function route; 2994e35917SGreg Roach 3094e35917SGreg Roach/** 317b5ff3baSGreg Roach * Delete a location from the control panel. 3294e35917SGreg Roach */ 3394e35917SGreg Roachclass MapDataDelete implements RequestHandlerInterface 3494e35917SGreg Roach{ 35c4943cffSGreg Roach private MapDataService $map_data_service; 3694e35917SGreg Roach 3794e35917SGreg Roach /** 3894e35917SGreg Roach * Dependency injection. 3994e35917SGreg Roach * 4094e35917SGreg Roach * @param MapDataService $map_data_service 4194e35917SGreg Roach */ 4294e35917SGreg Roach public function __construct(MapDataService $map_data_service) 4394e35917SGreg Roach { 4494e35917SGreg Roach $this->map_data_service = $map_data_service; 4594e35917SGreg Roach } 4694e35917SGreg Roach 4794e35917SGreg Roach /** 4894e35917SGreg Roach * @param ServerRequestInterface $request 4994e35917SGreg Roach * 5094e35917SGreg Roach * @return ResponseInterface 5194e35917SGreg Roach */ 5294e35917SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 5394e35917SGreg Roach { 540e54db38SGreg Roach $location_id = (int) $request->getAttribute('location_id'); 5594e35917SGreg Roach 560e54db38SGreg Roach $place = $this->map_data_service->findById($location_id); 5794e35917SGreg Roach 580e54db38SGreg Roach $this->map_data_service->deleteRecursively($location_id); 5994e35917SGreg Roach 6090949315SGreg Roach $url = route(MapDataList::class, ['parent_id' => $place->parent()->id()]); 6194e35917SGreg Roach 6294e35917SGreg Roach return redirect($url); 6394e35917SGreg Roach } 6494e35917SGreg Roach} 65