17c7d1e03SGreg Roach<?php 27c7d1e03SGreg Roach 37c7d1e03SGreg Roach/** 47c7d1e03SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 67c7d1e03SGreg Roach * This program is free software: you can redistribute it and/or modify 77c7d1e03SGreg Roach * it under the terms of the GNU General Public License as published by 87c7d1e03SGreg Roach * the Free Software Foundation, either version 3 of the License, or 97c7d1e03SGreg Roach * (at your option) any later version. 107c7d1e03SGreg Roach * This program is distributed in the hope that it will be useful, 117c7d1e03SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 127c7d1e03SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 137c7d1e03SGreg Roach * GNU General Public License for more details. 147c7d1e03SGreg 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/>. 167c7d1e03SGreg Roach */ 177c7d1e03SGreg Roach 187c7d1e03SGreg Roachdeclare(strict_types=1); 197c7d1e03SGreg Roach 207c7d1e03SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 217c7d1e03SGreg Roach 227c7d1e03SGreg Roachuse Fisharebest\Webtrees\Auth; 23efd4768bSGreg Roachuse Fisharebest\Webtrees\Fact; 247c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 257c7d1e03SGreg Roachuse Fisharebest\Webtrees\I18N; 266b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 279ba2a180SGreg Roachuse Fisharebest\Webtrees\Services\GedcomEditService; 28b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 297c7d1e03SGreg Roachuse Psr\Http\Message\ResponseInterface; 307c7d1e03SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 317c7d1e03SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 327c7d1e03SGreg Roach 337c7d1e03SGreg Roach/** 347c7d1e03SGreg Roach * Link an existing individual as a new spouse. 357c7d1e03SGreg Roach */ 367c7d1e03SGreg Roachclass LinkSpouseToIndividualPage implements RequestHandlerInterface 377c7d1e03SGreg Roach{ 387c7d1e03SGreg Roach use ViewResponseTrait; 397c7d1e03SGreg Roach 409ba2a180SGreg Roach private GedcomEditService $gedcom_edit_service; 419ba2a180SGreg Roach 429ba2a180SGreg Roach /** 439ba2a180SGreg Roach * @param GedcomEditService $gedcom_edit_service 449ba2a180SGreg Roach */ 459ba2a180SGreg Roach public function __construct(GedcomEditService $gedcom_edit_service) 469ba2a180SGreg Roach { 479ba2a180SGreg Roach $this->gedcom_edit_service = $gedcom_edit_service; 489ba2a180SGreg Roach } 499ba2a180SGreg Roach 507c7d1e03SGreg Roach /** 517c7d1e03SGreg Roach * @param ServerRequestInterface $request 527c7d1e03SGreg Roach * 537c7d1e03SGreg Roach * @return ResponseInterface 547c7d1e03SGreg Roach */ 557c7d1e03SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 567c7d1e03SGreg Roach { 57b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 58b55cbc6bSGreg Roach $xref = Validator::attributes($request)->isXref()->string('xref'); 596b9cb339SGreg Roach $individual = Registry::individualFactory()->make($xref, $tree); 607c7d1e03SGreg Roach $individual = Auth::checkIndividualAccess($individual, true); 617c7d1e03SGreg Roach 62efd4768bSGreg Roach // Create a dummy family record, so we can create new/empty facts. 63efd4768bSGreg Roach $dummy = Registry::familyFactory()->new('', '0 @@ FAM', null, $tree); 64efd4768bSGreg Roach $facts = [ 65efd4768bSGreg Roach 'f' => [ 66efd4768bSGreg Roach new Fact('1 MARR', $dummy, ''), 67efd4768bSGreg Roach ], 68efd4768bSGreg Roach ]; 69efd4768bSGreg Roach 707c7d1e03SGreg Roach if ($individual->sex() === 'F') { 717c7d1e03SGreg Roach $title = $individual->fullName() . ' - ' . I18N::translate('Add a husband using an existing individual'); 727c7d1e03SGreg Roach $label = I18N::translate('Husband'); 737c7d1e03SGreg Roach } else { 747c7d1e03SGreg Roach $title = $individual->fullName() . ' - ' . I18N::translate('Add a wife using an existing individual'); 757c7d1e03SGreg Roach $label = I18N::translate('Wife'); 767c7d1e03SGreg Roach } 777c7d1e03SGreg Roach 787c7d1e03SGreg Roach return $this->viewResponse('edit/link-spouse-to-individual', [ 79efd4768bSGreg Roach 'cancel_url' => $individual->url(), 80efd4768bSGreg Roach 'facts' => $facts, 819ba2a180SGreg Roach 'gedcom_edit_service' => $this->gedcom_edit_service, 829ba2a180SGreg Roach 'label' => $label, 839ba2a180SGreg Roach 'post_url' => route(LinkSpouseToIndividualAction::class, ['tree' => $tree->name(), 'xref' => $xref]), 849ba2a180SGreg Roach 'title' => $title, 857c7d1e03SGreg Roach 'tree' => $tree, 867c7d1e03SGreg Roach 'xref' => $xref, 877c7d1e03SGreg Roach ]); 887c7d1e03SGreg Roach } 897c7d1e03SGreg Roach} 90