1*7c7d1e03SGreg Roach<?php 2*7c7d1e03SGreg Roach 3*7c7d1e03SGreg Roach/** 4*7c7d1e03SGreg Roach * webtrees: online genealogy 5*7c7d1e03SGreg Roach * Copyright (C) 2020 webtrees development team 6*7c7d1e03SGreg Roach * This program is free software: you can redistribute it and/or modify 7*7c7d1e03SGreg Roach * it under the terms of the GNU General Public License as published by 8*7c7d1e03SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*7c7d1e03SGreg Roach * (at your option) any later version. 10*7c7d1e03SGreg Roach * This program is distributed in the hope that it will be useful, 11*7c7d1e03SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*7c7d1e03SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*7c7d1e03SGreg Roach * GNU General Public License for more details. 14*7c7d1e03SGreg Roach * You should have received a copy of the GNU General Public License 15*7c7d1e03SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*7c7d1e03SGreg Roach */ 17*7c7d1e03SGreg Roach 18*7c7d1e03SGreg Roachdeclare(strict_types=1); 19*7c7d1e03SGreg Roach 20*7c7d1e03SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*7c7d1e03SGreg Roach 22*7c7d1e03SGreg Roachuse Fisharebest\Webtrees\Auth; 23*7c7d1e03SGreg Roachuse Fisharebest\Webtrees\Factory; 24*7c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 25*7c7d1e03SGreg Roachuse Fisharebest\Webtrees\I18N; 26*7c7d1e03SGreg Roachuse Fisharebest\Webtrees\Tree; 27*7c7d1e03SGreg Roachuse Psr\Http\Message\ResponseInterface; 28*7c7d1e03SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29*7c7d1e03SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30*7c7d1e03SGreg Roach 31*7c7d1e03SGreg Roachuse function assert; 32*7c7d1e03SGreg Roach 33*7c7d1e03SGreg Roach/** 34*7c7d1e03SGreg Roach * Link an existing individual as a new spouse. 35*7c7d1e03SGreg Roach */ 36*7c7d1e03SGreg Roachclass LinkSpouseToIndividualPage implements RequestHandlerInterface 37*7c7d1e03SGreg Roach{ 38*7c7d1e03SGreg Roach use ViewResponseTrait; 39*7c7d1e03SGreg Roach 40*7c7d1e03SGreg Roach /** 41*7c7d1e03SGreg Roach * @param ServerRequestInterface $request 42*7c7d1e03SGreg Roach * 43*7c7d1e03SGreg Roach * @return ResponseInterface 44*7c7d1e03SGreg Roach */ 45*7c7d1e03SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 46*7c7d1e03SGreg Roach { 47*7c7d1e03SGreg Roach $tree = $request->getAttribute('tree'); 48*7c7d1e03SGreg Roach assert($tree instanceof Tree); 49*7c7d1e03SGreg Roach 50*7c7d1e03SGreg Roach $xref = $request->getQueryParams()['xref']; 51*7c7d1e03SGreg Roach 52*7c7d1e03SGreg Roach $individual = Factory::individual()->make($xref, $tree); 53*7c7d1e03SGreg Roach $individual = Auth::checkIndividualAccess($individual, true); 54*7c7d1e03SGreg Roach 55*7c7d1e03SGreg Roach if ($individual->sex() === 'F') { 56*7c7d1e03SGreg Roach $title = $individual->fullName() . ' - ' . I18N::translate('Add a husband using an existing individual'); 57*7c7d1e03SGreg Roach $label = I18N::translate('Husband'); 58*7c7d1e03SGreg Roach } else { 59*7c7d1e03SGreg Roach $title = $individual->fullName() . ' - ' . I18N::translate('Add a wife using an existing individual'); 60*7c7d1e03SGreg Roach $label = I18N::translate('Wife'); 61*7c7d1e03SGreg Roach } 62*7c7d1e03SGreg Roach 63*7c7d1e03SGreg Roach return $this->viewResponse('edit/link-spouse-to-individual', [ 64*7c7d1e03SGreg Roach 'individual' => $individual, 65*7c7d1e03SGreg Roach 'label' => $label, 66*7c7d1e03SGreg Roach 'title' => $title, 67*7c7d1e03SGreg Roach 'tree' => $tree, 68*7c7d1e03SGreg Roach 'xref' => $xref, 69*7c7d1e03SGreg Roach ]); 70*7c7d1e03SGreg Roach } 71*7c7d1e03SGreg Roach} 72