13b3db8adSGreg Roach<?php 23b3db8adSGreg Roach 33b3db8adSGreg Roach/** 43b3db8adSGreg Roach * webtrees: online genealogy 53b3db8adSGreg Roach * Copyright (C) 2019 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 153b3db8adSGreg Roach * along with this program. If not, see <http://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; 233b3db8adSGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 243b3db8adSGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService; 253b3db8adSGreg Roachuse Fisharebest\Webtrees\Tree; 263b3db8adSGreg Roachuse Psr\Http\Message\ResponseInterface; 273b3db8adSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 283b3db8adSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 293b3db8adSGreg Roach 303b3db8adSGreg Roachuse function assert; 31*ddeb3354SGreg Roachuse function is_string; 323b3db8adSGreg Roachuse function redirect; 333b3db8adSGreg Roach 343b3db8adSGreg Roach/** 353b3db8adSGreg Roach * Paste a fact from the clipboard. 363b3db8adSGreg Roach */ 373b3db8adSGreg Roachclass PasteFact implements RequestHandlerInterface 383b3db8adSGreg Roach{ 393b3db8adSGreg Roach /** @var ClipboardService */ 403b3db8adSGreg Roach private $clipboard_service; 413b3db8adSGreg Roach 423b3db8adSGreg Roach /** 432917771cSGreg Roach * PasteFact constructor. 443b3db8adSGreg Roach * 453b3db8adSGreg Roach * @param ClipboardService $clipboard_service 463b3db8adSGreg Roach */ 473b3db8adSGreg Roach public function __construct(ClipboardService $clipboard_service) 483b3db8adSGreg Roach { 493b3db8adSGreg Roach $this->clipboard_service = $clipboard_service; 503b3db8adSGreg Roach } 513b3db8adSGreg Roach 523b3db8adSGreg Roach /** 533b3db8adSGreg Roach * Paste a fact from the clipboard into a record. 543b3db8adSGreg Roach * 553b3db8adSGreg Roach * @param ServerRequestInterface $request 563b3db8adSGreg Roach * 573b3db8adSGreg Roach * @return ResponseInterface 583b3db8adSGreg Roach */ 593b3db8adSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 603b3db8adSGreg Roach { 613b3db8adSGreg Roach $tree = $request->getAttribute('tree'); 623b3db8adSGreg Roach assert($tree instanceof Tree); 633b3db8adSGreg Roach 643b3db8adSGreg Roach $xref = $request->getAttribute('xref'); 65*ddeb3354SGreg Roach assert(is_string($xref)); 66*ddeb3354SGreg Roach 673b3db8adSGreg Roach $fact_id = $request->getParsedBody()['fact_id']; 683b3db8adSGreg Roach $record = GedcomRecord::getInstance($xref, $tree); 69*ddeb3354SGreg Roach $record = Auth::checkRecordAccess($record, true); 703b3db8adSGreg Roach 713b3db8adSGreg Roach $this->clipboard_service->pasteFact($fact_id, $record); 723b3db8adSGreg Roach 733b3db8adSGreg Roach return redirect($record->url()); 743b3db8adSGreg Roach } 753b3db8adSGreg Roach} 76