1c2ed51d1SGreg Roach<?php 2c2ed51d1SGreg Roach 3c2ed51d1SGreg Roach/** 4c2ed51d1SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6c2ed51d1SGreg Roach * This program is free software: you can redistribute it and/or modify 7c2ed51d1SGreg Roach * it under the terms of the GNU General Public License as published by 8c2ed51d1SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9c2ed51d1SGreg Roach * (at your option) any later version. 10c2ed51d1SGreg Roach * This program is distributed in the hope that it will be useful, 11c2ed51d1SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12c2ed51d1SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13c2ed51d1SGreg Roach * GNU General Public License for more details. 14c2ed51d1SGreg Roach * You should have received a copy of the GNU General Public License 15c2ed51d1SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16c2ed51d1SGreg Roach */ 17c2ed51d1SGreg Roach 18c2ed51d1SGreg Roachdeclare(strict_types=1); 19c2ed51d1SGreg Roach 20c2ed51d1SGreg Roachnamespace Fisharebest\Webtrees\Elements; 21c2ed51d1SGreg Roach 22c2ed51d1SGreg Roachuse Fisharebest\Webtrees\I18N; 237e128bbfSGreg Roachuse Fisharebest\Webtrees\Registry; 24c2ed51d1SGreg Roachuse Fisharebest\Webtrees\Tree; 25c2ed51d1SGreg Roach 26c2ed51d1SGreg Roachuse function e; 274da96842SGreg Roachuse function in_array; 28c2ed51d1SGreg Roachuse function view; 29c2ed51d1SGreg Roach 30c2ed51d1SGreg Roach/** 31c2ed51d1SGreg Roach * NAME_PERSONAL := {Size=1:120} 32c2ed51d1SGreg Roach * [ 33c2ed51d1SGreg Roach * <NAME_TEXT> | /<NAME_TEXT>/ | 34c2ed51d1SGreg Roach * <NAME_TEXT> /<NAME_TEXT>/ | /<NAME_TEXT>/ <NAME_TEXT> | 35c2ed51d1SGreg Roach * <NAME_TEXT> /<NAME_TEXT>/ <NAME_TEXT> ] 36c2ed51d1SGreg Roach * The surname of an individual, if known, is enclosed between two slash (/) 37c2ed51d1SGreg Roach * characters. The order of the name parts should be the order that the person 38c2ed51d1SGreg Roach * would, by custom of their culture, have used when giving it to a recorder. 39c2ed51d1SGreg Roach * Early versions of Personal Ancestral File ® and other products did not use 40c2ed51d1SGreg Roach * the trailing slash when the surname was the last element of the name. If 41c2ed51d1SGreg Roach * part of name is illegible, that part is indicated by an ellipsis (...). 42c2ed51d1SGreg Roach * Capitalize the name of a person or place in the conventional manner— 43c2ed51d1SGreg Roach * capitalize the first letter of each part and lowercase the other letters, 44c2ed51d1SGreg Roach * unless conventional usage is otherwise. For example: McMurray. 45c2ed51d1SGreg Roach * Examples: 46c2ed51d1SGreg Roach * William Lee (given name only or surname not known) 47c2ed51d1SGreg Roach * /Parry/ (surname only) 48c2ed51d1SGreg Roach * William Lee /Parry/ 49c2ed51d1SGreg Roach * William Lee /Mac Parry/ (both parts (Mac and Parry) are surname parts 50e63974caSStefan Weil * William /Lee/ Parry (surname embedded in the name string) 51c2ed51d1SGreg Roach * William Lee /Pa.../ 52c2ed51d1SGreg Roach */ 53c2ed51d1SGreg Roachclass NamePersonal extends AbstractElement 54c2ed51d1SGreg Roach{ 55ae0043b7SGreg Roach protected const MAXIMUM_LENGTH = 120; 56c2ed51d1SGreg Roach 57c2ed51d1SGreg Roach protected const SUBTAGS = [ 58c2ed51d1SGreg Roach 'TYPE' => '0:1', 59c2ed51d1SGreg Roach 'NPFX' => '0:1', 60c2ed51d1SGreg Roach 'GIVN' => '0:1', 61c2ed51d1SGreg Roach 'SPFX' => '0:1', 62c2ed51d1SGreg Roach 'SURN' => '0:1', 63c2ed51d1SGreg Roach 'NSFX' => '0:1', 64c2ed51d1SGreg Roach 'NICK' => '0:1', 654da96842SGreg Roach 'NOTE' => '0:M', 664da96842SGreg Roach 'SOUR' => '0:M', 674da96842SGreg Roach 'FONE' => '0:M', 684da96842SGreg Roach 'ROMN' => '0:M', 694da96842SGreg Roach ]; 704da96842SGreg Roach 714da96842SGreg Roach // For some languages, we want to show the surname field first. 724da96842SGreg Roach protected const SURNAME_FIRST_LANGUAGES = ['hu', 'jp', 'ko', 'zh-Hans', 'zh-Hant']; 734da96842SGreg Roach 744da96842SGreg Roach protected const SUBTAGS_SURNAME_FIRST = [ 754da96842SGreg Roach 'TYPE' => '0:1', 764da96842SGreg Roach 'NPFX' => '0:1', 774da96842SGreg Roach 'SPFX' => '0:1', 784da96842SGreg Roach 'SURN' => '0:1', 794da96842SGreg Roach 'GIVN' => '0:1', 804da96842SGreg Roach 'NSFX' => '0:1', 814da96842SGreg Roach 'NICK' => '0:1', 824da96842SGreg Roach 'NOTE' => '0:M', 834da96842SGreg Roach 'SOUR' => '0:M', 844da96842SGreg Roach 'FONE' => '0:M', 854da96842SGreg Roach 'ROMN' => '0:M', 86c2ed51d1SGreg Roach ]; 87c2ed51d1SGreg Roach 88c2ed51d1SGreg Roach /** 8978fee3e8SGreg Roach * AbstractGedcomElement constructor. 9078fee3e8SGreg Roach * 9178fee3e8SGreg Roach * @param string $label 9278fee3e8SGreg Roach * @param array<string>|null $subtags 9378fee3e8SGreg Roach */ 9478fee3e8SGreg Roach public function __construct(string $label, array $subtags = null) 9578fee3e8SGreg Roach { 9678fee3e8SGreg Roach if ($subtags === null && in_array(I18N::languageTag(), static::SURNAME_FIRST_LANGUAGES, true)) { 9778fee3e8SGreg Roach $subtags = static::SUBTAGS_SURNAME_FIRST; 9878fee3e8SGreg Roach } 9978fee3e8SGreg Roach parent::__construct($label, $subtags); 10078fee3e8SGreg Roach } 10178fee3e8SGreg Roach 10278fee3e8SGreg Roach /** 10300b57d36SGreg Roach * Convert a value to a canonical form. 10400b57d36SGreg Roach * 10500b57d36SGreg Roach * @param string $value 10600b57d36SGreg Roach * 10700b57d36SGreg Roach * @return string 10800b57d36SGreg Roach */ 10900b57d36SGreg Roach public function canonical(string $value): string 11000b57d36SGreg Roach { 11100b57d36SGreg Roach $value = parent::canonical($value); 11200b57d36SGreg Roach 11300b57d36SGreg Roach if ($value === '//') { 11400b57d36SGreg Roach return ''; 11500b57d36SGreg Roach } 11600b57d36SGreg Roach 11700b57d36SGreg Roach return $value; 11800b57d36SGreg Roach } 11900b57d36SGreg Roach 12000b57d36SGreg Roach 12100b57d36SGreg Roach 12200b57d36SGreg Roach /** 123c2ed51d1SGreg Roach * Create a default value for this element. 124c2ed51d1SGreg Roach * 125c2ed51d1SGreg Roach * @param Tree $tree 126c2ed51d1SGreg Roach * 127c2ed51d1SGreg Roach * @return string 128c2ed51d1SGreg Roach */ 129c2ed51d1SGreg Roach public function default(Tree $tree): string 130c2ed51d1SGreg Roach { 1317e128bbfSGreg Roach return Registry::surnameTraditionFactory() 1327e128bbfSGreg Roach ->make($tree->getPreference('SURNAME_TRADITION')) 1337e128bbfSGreg Roach ->defaultName(); 134c2ed51d1SGreg Roach } 135c2ed51d1SGreg Roach 136c2ed51d1SGreg Roach /** 137c2ed51d1SGreg Roach * An edit control for this data. 138c2ed51d1SGreg Roach * 139c2ed51d1SGreg Roach * @param string $id 140c2ed51d1SGreg Roach * @param string $name 141c2ed51d1SGreg Roach * @param string $value 142c2ed51d1SGreg Roach * @param Tree $tree 143c2ed51d1SGreg Roach * 144c2ed51d1SGreg Roach * @return string 145c2ed51d1SGreg Roach */ 146c2ed51d1SGreg Roach public function edit(string $id, string $name, string $value, Tree $tree): string 147c2ed51d1SGreg Roach { 148c2ed51d1SGreg Roach return 149c2ed51d1SGreg Roach '<div class="input-group">' . 150c2ed51d1SGreg Roach view('edit/input-addon-edit-name', ['id' => $id]) . 151*2978efeaSJonathan Jaubart '<input class="form-control" type="text" id="' . e($id) . '-disabled" name="' . e($name) . '" value="' . e($value) . '" readonly="readonly" disabled="disabled" />' . 152*2978efeaSJonathan Jaubart '<input class="form-control d-none" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" />' . 153c2ed51d1SGreg Roach view('edit/input-addon-keyboard', ['id' => $id]) . 154ab7d502dSGreg Roach view('edit/input-addon-help', ['topic' => 'NAME']) . 155c2ed51d1SGreg Roach '</div>'; 156c2ed51d1SGreg Roach } 157c2ed51d1SGreg Roach} 158