13b3db8adSGreg Roach<?php 23b3db8adSGreg Roach 33b3db8adSGreg Roach/** 43b3db8adSGreg Roach * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 63b3db8adSGreg Roach * This program is free software: you can redistribute it and/or modify 73b3db8adSGreg Roach * it under the terms of the GNU General Public License as published by 83b3db8adSGreg Roach * the Free Software Foundation, either version 3 of the License, or 93b3db8adSGreg Roach * (at your option) any later version. 103b3db8adSGreg Roach * This program is distributed in the hope that it will be useful, 113b3db8adSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 123b3db8adSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 133b3db8adSGreg Roach * GNU General Public License for more details. 143b3db8adSGreg Roach * You should have received a copy of the GNU General Public License 15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 163b3db8adSGreg Roach */ 173b3db8adSGreg Roach 183b3db8adSGreg Roachdeclare(strict_types=1); 193b3db8adSGreg Roach 203b3db8adSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 213b3db8adSGreg Roach 223b3db8adSGreg Roachuse Fisharebest\Webtrees\Auth; 2319aed3a1SGreg Roachuse Fisharebest\Webtrees\Fact; 243b3db8adSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 253b3db8adSGreg Roachuse Fisharebest\Webtrees\I18N; 266b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 273b3db8adSGreg Roachuse Fisharebest\Webtrees\Tree; 283b3db8adSGreg Roachuse Psr\Http\Message\ResponseInterface; 293b3db8adSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 303b3db8adSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 313b3db8adSGreg Roach 323b3db8adSGreg Roachuse function assert; 33ddeb3354SGreg Roachuse function is_string; 343b3db8adSGreg Roachuse function redirect; 353b3db8adSGreg Roach 363b3db8adSGreg Roach/** 373b3db8adSGreg Roach * Edit the raw GEDCOM of a fact. 383b3db8adSGreg Roach */ 393b3db8adSGreg Roachclass EditRawFactPage implements RequestHandlerInterface 403b3db8adSGreg Roach{ 413b3db8adSGreg Roach use ViewResponseTrait; 423b3db8adSGreg Roach 433b3db8adSGreg Roach /** 443b3db8adSGreg Roach * @param ServerRequestInterface $request 453b3db8adSGreg Roach * 463b3db8adSGreg Roach * @return ResponseInterface 473b3db8adSGreg Roach */ 483b3db8adSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 493b3db8adSGreg Roach { 503b3db8adSGreg Roach $tree = $request->getAttribute('tree'); 513b3db8adSGreg Roach assert($tree instanceof Tree); 523b3db8adSGreg Roach 533b3db8adSGreg Roach $xref = $request->getAttribute('xref'); 54ddeb3354SGreg Roach assert(is_string($xref)); 553b3db8adSGreg Roach 566b9cb339SGreg Roach $record = Registry::gedcomRecordFactory()->make($xref, $tree); 57ddeb3354SGreg Roach $record = Auth::checkRecordAccess($record, true); 583b3db8adSGreg Roach 593b3db8adSGreg Roach $fact_id = $request->getAttribute('fact_id'); 603b3db8adSGreg Roach 613b3db8adSGreg Roach $title = I18N::translate('Edit the raw GEDCOM') . ' - ' . $record->fullName(); 623b3db8adSGreg Roach 6319aed3a1SGreg Roach $fact = $record->facts([], false, null, true) 6419aed3a1SGreg Roach ->first(static function (Fact $fact) use ($fact_id): bool { 6519aed3a1SGreg Roach return $fact->id() === $fact_id; 6619aed3a1SGreg Roach }); 6719aed3a1SGreg Roach 6819aed3a1SGreg Roach if ($fact instanceof Fact) { 693b3db8adSGreg Roach return $this->viewResponse('edit/raw-gedcom-fact', [ 703b3db8adSGreg Roach 'fact' => $fact, 713b3db8adSGreg Roach 'title' => $title, 72ef5d23f1SGreg Roach 'tree' => $tree, 739db6d3cbSGreg Roach 'url' => $request->getQueryParams()['url'] ?? null, 743b3db8adSGreg Roach ]); 753b3db8adSGreg Roach } 763b3db8adSGreg Roach 773b3db8adSGreg Roach return redirect($record->url()); 783b3db8adSGreg Roach } 793b3db8adSGreg Roach} 80