17c7d1e03SGreg Roach<?php 27c7d1e03SGreg Roach 37c7d1e03SGreg Roach/** 47c7d1e03SGreg Roach * webtrees: online genealogy 5*89f7189bSGreg 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 15*89f7189bSGreg 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; 267c7d1e03SGreg Roachuse Fisharebest\Webtrees\Tree; 277c7d1e03SGreg Roachuse Psr\Http\Message\ResponseInterface; 287c7d1e03SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 297c7d1e03SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 307c7d1e03SGreg Roach 317c7d1e03SGreg Roachuse function assert; 327c7d1e03SGreg Roach 337c7d1e03SGreg Roach/** 347c7d1e03SGreg Roach * Add a new child to a family. 357c7d1e03SGreg Roach */ 367c7d1e03SGreg Roachclass AddChildToFamilyPage implements RequestHandlerInterface 377c7d1e03SGreg Roach{ 387c7d1e03SGreg Roach use ViewResponseTrait; 397c7d1e03SGreg Roach 407c7d1e03SGreg Roach /** 417c7d1e03SGreg Roach * @param ServerRequestInterface $request 427c7d1e03SGreg Roach * 437c7d1e03SGreg Roach * @return ResponseInterface 447c7d1e03SGreg Roach */ 457c7d1e03SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 467c7d1e03SGreg Roach { 477c7d1e03SGreg Roach $tree = $request->getAttribute('tree'); 487c7d1e03SGreg Roach assert($tree instanceof Tree); 497c7d1e03SGreg Roach 507c7d1e03SGreg Roach $xref = $request->getQueryParams()['xref']; 517c7d1e03SGreg Roach 526b9cb339SGreg Roach $family = Registry::familyFactory()->make($xref, $tree); 537c7d1e03SGreg Roach $family = Auth::checkFamilyAccess($family, true); 547c7d1e03SGreg Roach 557c7d1e03SGreg Roach $gender = $request->getQueryParams()['gender']; 567c7d1e03SGreg Roach 577c7d1e03SGreg Roach $subtitles = [ 587c7d1e03SGreg Roach 'M' => I18N::translate('Add a son'), 597c7d1e03SGreg Roach 'F' => I18N::translate('Add a daughter'), 607c7d1e03SGreg Roach 'U' => I18N::translate('Add a child'), 617c7d1e03SGreg Roach ]; 627c7d1e03SGreg Roach 637c7d1e03SGreg Roach $subtitle = $subtitles[$gender] ?? $subtitles['U']; 647c7d1e03SGreg Roach 657c7d1e03SGreg Roach $title = $family->fullName() . ' - ' . $subtitle; 667c7d1e03SGreg Roach 677c7d1e03SGreg Roach return $this->viewResponse('edit/new-individual', [ 687c7d1e03SGreg Roach 'next_action' => AddChildToFamilyAction::class, 697c7d1e03SGreg Roach 'tree' => $tree, 707c7d1e03SGreg Roach 'title' => $title, 717c7d1e03SGreg Roach 'individual' => null, 727c7d1e03SGreg Roach 'family' => $family, 737c7d1e03SGreg Roach 'name_fact' => null, 747c7d1e03SGreg Roach 'famtag' => 'CHIL', 757c7d1e03SGreg Roach 'gender' => $gender, 767c7d1e03SGreg Roach ]); 777c7d1e03SGreg Roach } 787c7d1e03SGreg Roach} 79