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; 237c7d1e03SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 247c7d1e03SGreg Roachuse Fisharebest\Webtrees\I18N; 256b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 269ba2a180SGreg Roachuse Fisharebest\Webtrees\Services\GedcomEditService; 27b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 287c7d1e03SGreg Roachuse Psr\Http\Message\ResponseInterface; 297c7d1e03SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 307c7d1e03SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 317c7d1e03SGreg Roach 32efd4768bSGreg Roachuse function route; 337c7d1e03SGreg Roach 347c7d1e03SGreg Roach/** 357c7d1e03SGreg Roach * Add a new parent to an individual, creating a one-parent family. 367c7d1e03SGreg Roach */ 377c7d1e03SGreg Roachclass AddParentToIndividualPage implements RequestHandlerInterface 387c7d1e03SGreg Roach{ 397c7d1e03SGreg Roach use ViewResponseTrait; 407c7d1e03SGreg Roach 419ba2a180SGreg Roach private GedcomEditService $gedcom_edit_service; 429ba2a180SGreg Roach 439ba2a180SGreg Roach /** 449ba2a180SGreg Roach * @param GedcomEditService $gedcom_edit_service 459ba2a180SGreg Roach */ 469ba2a180SGreg Roach public function __construct(GedcomEditService $gedcom_edit_service) 479ba2a180SGreg Roach { 489ba2a180SGreg Roach $this->gedcom_edit_service = $gedcom_edit_service; 499ba2a180SGreg Roach } 509ba2a180SGreg Roach 517c7d1e03SGreg Roach /** 527c7d1e03SGreg Roach * @param ServerRequestInterface $request 537c7d1e03SGreg Roach * 547c7d1e03SGreg Roach * @return ResponseInterface 557c7d1e03SGreg Roach */ 567c7d1e03SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 577c7d1e03SGreg Roach { 58b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 59b55cbc6bSGreg Roach $xref = Validator::attributes($request)->isXref()->string('xref'); 60b55cbc6bSGreg Roach $sex = Validator::attributes($request)->string('sex'); 616b9cb339SGreg Roach $individual = Registry::individualFactory()->make($xref, $tree); 627c7d1e03SGreg Roach $individual = Auth::checkIndividualAccess($individual, true); 637c7d1e03SGreg Roach 643a1e3ba4SGreg Roach // Name facts. 657e128bbfSGreg Roach $surname_tradition = Registry::surnameTraditionFactory() 667e128bbfSGreg Roach ->make($tree->getPreference('SURNAME_TRADITION')); 677e128bbfSGreg Roach 68cb7a42eaSGreg Roach $names = $surname_tradition->newParentNames($individual, $sex); 693a1e3ba4SGreg Roach 70efd4768bSGreg Roach $facts = [ 716102047cSGreg Roach 'i' => $this->gedcom_edit_service->newIndividualFacts($tree, $sex, $names), 72efd4768bSGreg Roach ]; 737c7d1e03SGreg Roach 74efd4768bSGreg Roach if ($sex === 'F') { 75efd4768bSGreg Roach $title = I18N::translate('Add a mother'); 767c7d1e03SGreg Roach } else { 77efd4768bSGreg Roach $title = I18N::translate('Add a father'); 787c7d1e03SGreg Roach } 797c7d1e03SGreg Roach 807c7d1e03SGreg Roach return $this->viewResponse('edit/new-individual', [ 81efd4768bSGreg Roach 'facts' => $facts, 829ba2a180SGreg Roach 'gedcom_edit_service' => $this->gedcom_edit_service, 83efd4768bSGreg Roach 'post_url' => route(AddParentToIndividualAction::class, ['tree' => $tree->name(), 'xref' => $xref]), 84efd4768bSGreg Roach 'title' => $individual->fullName() . ' - ' . $title, 857c7d1e03SGreg Roach 'tree' => $tree, 869f0bdfcdSGreg Roach 'url' => Validator::queryParams($request)->isLocalUrl()->string('url', $individual->url()), 877c7d1e03SGreg Roach ]); 887c7d1e03SGreg Roach } 897c7d1e03SGreg Roach} 90