1ffc0a61fSGreg Roach<?php 2ffc0a61fSGreg Roach 3ffc0a61fSGreg Roach/** 4ffc0a61fSGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6ffc0a61fSGreg Roach * This program is free software: you can redistribute it and/or modify 7ffc0a61fSGreg Roach * it under the terms of the GNU General Public License as published by 8ffc0a61fSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9ffc0a61fSGreg Roach * (at your option) any later version. 10ffc0a61fSGreg Roach * This program is distributed in the hope that it will be useful, 11ffc0a61fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12ffc0a61fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13ffc0a61fSGreg Roach * GNU General Public License for more details. 14ffc0a61fSGreg 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/>. 16ffc0a61fSGreg Roach */ 17ffc0a61fSGreg Roach 18ffc0a61fSGreg Roachdeclare(strict_types=1); 19ffc0a61fSGreg Roach 20ffc0a61fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21ffc0a61fSGreg Roach 228256f465SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 23ffc0a61fSGreg Roachuse Fisharebest\Webtrees\Auth; 24ffc0a61fSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 256b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 26ffc0a61fSGreg Roachuse Fisharebest\Webtrees\Tree; 27ffc0a61fSGreg Roachuse Illuminate\Support\Collection; 28ffc0a61fSGreg Roachuse Psr\Http\Message\ResponseInterface; 29ffc0a61fSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 30ffc0a61fSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 31ffc0a61fSGreg Roach 32ffc0a61fSGreg Roachuse function assert; 33ffc0a61fSGreg Roachuse function is_string; 34ffc0a61fSGreg Roachuse function redirect; 35ffc0a61fSGreg Roach 36ffc0a61fSGreg Roach/** 37ffc0a61fSGreg Roach * Show a submitter's page. 38ffc0a61fSGreg Roach */ 39ffc0a61fSGreg Roachclass SubmitterPage implements RequestHandlerInterface 40ffc0a61fSGreg Roach{ 41ffc0a61fSGreg Roach use ViewResponseTrait; 42ffc0a61fSGreg Roach 43ffc0a61fSGreg Roach /** 44ffc0a61fSGreg Roach * @param ServerRequestInterface $request 45ffc0a61fSGreg Roach * 46ffc0a61fSGreg Roach * @return ResponseInterface 47ffc0a61fSGreg Roach */ 48ffc0a61fSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 49ffc0a61fSGreg Roach { 50ffc0a61fSGreg Roach $tree = $request->getAttribute('tree'); 51ffc0a61fSGreg Roach assert($tree instanceof Tree); 52ffc0a61fSGreg Roach 53ffc0a61fSGreg Roach $xref = $request->getAttribute('xref'); 54ffc0a61fSGreg Roach assert(is_string($xref)); 55ffc0a61fSGreg Roach 56*0f5fd22fSGreg Roach $record = Registry::submitterFactory()->make($xref, $tree); 57*0f5fd22fSGreg Roach $record = Auth::checkSubmitterAccess($record, false); 58ffc0a61fSGreg Roach 59ffc0a61fSGreg Roach // Redirect to correct xref/slug 60*0f5fd22fSGreg Roach $slug = Registry::slugFactory()->make($record); 61194b0938SGreg Roach 62*0f5fd22fSGreg Roach if ($record->xref() !== $xref || $request->getAttribute('slug') !== $slug) { 63*0f5fd22fSGreg Roach return redirect($record->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY); 64ffc0a61fSGreg Roach } 65ffc0a61fSGreg Roach 66*0f5fd22fSGreg Roach return $this->viewResponse('record-page', [ 67*0f5fd22fSGreg Roach 'clipboard_facts' => new Collection(), 68*0f5fd22fSGreg Roach 'linked_families' => $record->linkedFamilies('SUBM'), 69*0f5fd22fSGreg Roach 'linked_individuals' => $record->linkedIndividuals('SUBM'), 70*0f5fd22fSGreg Roach 'linked_media_objects' => null, 71*0f5fd22fSGreg Roach 'linked_notes' => null, 72*0f5fd22fSGreg Roach 'linked_sources' => null, 732406e0e0SGreg Roach 'meta_description' => '', 742406e0e0SGreg Roach 'meta_robots' => 'index,follow', 75*0f5fd22fSGreg Roach 'record' => $record, 76*0f5fd22fSGreg Roach 'title' => $record->fullName(), 77ffc0a61fSGreg Roach 'tree' => $tree, 78ffc0a61fSGreg Roach ]); 79ffc0a61fSGreg Roach } 80ffc0a61fSGreg Roach} 81