17c7d1e03SGreg Roach<?php 27c7d1e03SGreg Roach 37c7d1e03SGreg Roach/** 47c7d1e03SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 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\Http\ViewResponseTrait; 237c7d1e03SGreg Roachuse Fisharebest\Webtrees\I18N; 24efd4768bSGreg Roachuse Fisharebest\Webtrees\Registry; 259ba2a180SGreg Roachuse Fisharebest\Webtrees\Services\GedcomEditService; 26*b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 277c7d1e03SGreg Roachuse Psr\Http\Message\ResponseInterface; 287c7d1e03SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 297c7d1e03SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 307c7d1e03SGreg Roach 31efd4768bSGreg Roachuse function route; 327c7d1e03SGreg Roach 337c7d1e03SGreg Roach/** 347c7d1e03SGreg Roach * Create a new unlinked individual. 357c7d1e03SGreg Roach */ 367c7d1e03SGreg Roachclass AddUnlinkedPage implements RequestHandlerInterface 377c7d1e03SGreg Roach{ 387c7d1e03SGreg Roach use ViewResponseTrait; 397c7d1e03SGreg Roach 409ba2a180SGreg Roach private GedcomEditService $gedcom_edit_service; 419ba2a180SGreg Roach 429ba2a180SGreg Roach /** 439ba2a180SGreg Roach * LinkSpouseToIndividualPage constructor. 449ba2a180SGreg Roach * 459ba2a180SGreg Roach * @param GedcomEditService $gedcom_edit_service 469ba2a180SGreg Roach */ 479ba2a180SGreg Roach public function __construct(GedcomEditService $gedcom_edit_service) 489ba2a180SGreg Roach { 499ba2a180SGreg Roach $this->gedcom_edit_service = $gedcom_edit_service; 509ba2a180SGreg Roach } 519ba2a180SGreg Roach 527c7d1e03SGreg Roach /** 537c7d1e03SGreg Roach * @param ServerRequestInterface $request 547c7d1e03SGreg Roach * 557c7d1e03SGreg Roach * @return ResponseInterface 567c7d1e03SGreg Roach */ 577c7d1e03SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 587c7d1e03SGreg Roach { 59*b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 60e73150afSGreg Roach $sex = Registry::elementFactory()->make('INDI:SEX')->default($tree); 61e73150afSGreg Roach $name = Registry::elementFactory()->make('INDI:NAME')->default($tree); 623a1e3ba4SGreg Roach 63efd4768bSGreg Roach $facts = [ 64e73150afSGreg Roach 'i' => $this->gedcom_edit_service->newIndividualFacts($tree, $sex, ['1 NAME ' . $name]), 65efd4768bSGreg Roach ]; 66efd4768bSGreg Roach 672e6fecf0SGreg Roach $cancel_url = route(ManageTrees::class, ['tree' => $tree->name()]); 682e6fecf0SGreg Roach 697c7d1e03SGreg Roach return $this->viewResponse('edit/new-individual', [ 702e6fecf0SGreg Roach 'cancel_url' => $cancel_url, 71efd4768bSGreg Roach 'facts' => $facts, 729ba2a180SGreg Roach 'gedcom_edit_service' => $this->gedcom_edit_service, 73efd4768bSGreg Roach 'post_url' => route(AddUnlinkedAction::class, ['tree' => $tree->name()]), 747c7d1e03SGreg Roach 'tree' => $tree, 757c7d1e03SGreg Roach 'title' => I18N::translate('Create an individual'), 762e6fecf0SGreg Roach 'url' => $request->getQueryParams()['url'] ?? $cancel_url, 777c7d1e03SGreg Roach ]); 787c7d1e03SGreg Roach } 797c7d1e03SGreg Roach} 80