15818a371SGreg Roach<?php 25818a371SGreg Roach 35818a371SGreg Roach/** 45818a371SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 65818a371SGreg Roach * This program is free software: you can redistribute it and/or modify 75818a371SGreg Roach * it under the terms of the GNU General Public License as published by 85818a371SGreg Roach * the Free Software Foundation, either version 3 of the License, or 95818a371SGreg Roach * (at your option) any later version. 105818a371SGreg Roach * This program is distributed in the hope that it will be useful, 115818a371SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 125818a371SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 135818a371SGreg Roach * GNU General Public License for more details. 145818a371SGreg 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/>. 165818a371SGreg Roach */ 175818a371SGreg Roach 185818a371SGreg Roachdeclare(strict_types=1); 195818a371SGreg Roach 205818a371SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 215818a371SGreg Roach 225818a371SGreg Roachuse Fisharebest\Webtrees\Auth; 235818a371SGreg Roachuse Fisharebest\Webtrees\Family; 241635452cSGreg Roachuse Fisharebest\Webtrees\Header; 255818a371SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 265818a371SGreg Roachuse Fisharebest\Webtrees\Individual; 27e8ded2caSGreg Roachuse Fisharebest\Webtrees\Location; 285818a371SGreg Roachuse Fisharebest\Webtrees\Media; 295818a371SGreg Roachuse Fisharebest\Webtrees\Note; 306b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 315818a371SGreg Roachuse Fisharebest\Webtrees\Repository; 325818a371SGreg Roachuse Fisharebest\Webtrees\Source; 331635452cSGreg Roachuse Fisharebest\Webtrees\Submission; 34ffc0a61fSGreg Roachuse Fisharebest\Webtrees\Submitter; 355818a371SGreg Roachuse Fisharebest\Webtrees\Tree; 36*0f5fd22fSGreg Roachuse Illuminate\Support\Collection; 375818a371SGreg Roachuse Psr\Http\Message\ResponseInterface; 385818a371SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 395818a371SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 405818a371SGreg Roach 415818a371SGreg Roachuse function assert; 425818a371SGreg Roachuse function is_string; 435818a371SGreg Roachuse function redirect; 445818a371SGreg Roach 455818a371SGreg Roach/** 465818a371SGreg Roach * Display non-standard genealogy records. 475818a371SGreg Roach */ 485818a371SGreg Roachclass GedcomRecordPage implements RequestHandlerInterface 495818a371SGreg Roach{ 505818a371SGreg Roach use ViewResponseTrait; 515818a371SGreg Roach 525818a371SGreg Roach // These standard genealogy record types have their own pages. 535818a371SGreg Roach private const STANDARD_RECORDS = [ 545818a371SGreg Roach Family::class, 551635452cSGreg Roach Header::class, 565818a371SGreg Roach Individual::class, 57e8ded2caSGreg Roach Location::class, 585818a371SGreg Roach Media::class, 595818a371SGreg Roach Note::class, 605818a371SGreg Roach Repository::class, 615818a371SGreg Roach Source::class, 621635452cSGreg Roach Submission::class, 63ffc0a61fSGreg Roach Submitter::class, 645818a371SGreg Roach ]; 655818a371SGreg Roach 665818a371SGreg Roach /** 675818a371SGreg Roach * Show a gedcom record's page. 685818a371SGreg Roach * 695818a371SGreg Roach * @param ServerRequestInterface $request 705818a371SGreg Roach * 715818a371SGreg Roach * @return ResponseInterface 725818a371SGreg Roach */ 735818a371SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 745818a371SGreg Roach { 755818a371SGreg Roach $tree = $request->getAttribute('tree'); 765818a371SGreg Roach assert($tree instanceof Tree); 775818a371SGreg Roach 785818a371SGreg Roach $xref = $request->getAttribute('xref'); 795818a371SGreg Roach assert(is_string($xref)); 805818a371SGreg Roach 816b9cb339SGreg Roach $record = Registry::gedcomRecordFactory()->make($xref, $tree); 825818a371SGreg Roach $record = Auth::checkRecordAccess($record); 835818a371SGreg Roach 845818a371SGreg Roach // Standard genealogy records have their own pages. 855818a371SGreg Roach if ($record->xref() !== $xref || in_array(get_class($record), self::STANDARD_RECORDS, true)) { 865818a371SGreg Roach return redirect($record->url()); 875818a371SGreg Roach } 885818a371SGreg Roach 89*0f5fd22fSGreg Roach return $this->viewResponse('record-page', [ 90*0f5fd22fSGreg Roach 'clipboard_facts' => new Collection(), 91*0f5fd22fSGreg Roach 'linked_families' => $record->linkedFamilies($record->tag()), 92*0f5fd22fSGreg Roach 'linked_individuals' => $record->linkedIndividuals($record->tag()), 93*0f5fd22fSGreg Roach 'linked_media_objects' => $record->linkedMedia($record->tag()), 94*0f5fd22fSGreg Roach 'linked_notes' => $record->linkedNotes($record->tag()), 95*0f5fd22fSGreg Roach 'linked_sources' => $record->linkedSources($record->tag()), 965818a371SGreg Roach 'record' => $record, 975818a371SGreg Roach 'title' => $record->fullName(), 985818a371SGreg Roach 'tree' => $tree, 995818a371SGreg Roach ]); 1005818a371SGreg Roach } 1015818a371SGreg Roach} 102