1c2ed51d1SGreg Roach<?php 2c2ed51d1SGreg Roach 3c2ed51d1SGreg Roach/** 4c2ed51d1SGreg Roach * webtrees: online genealogy 55bfc6897SGreg Roach * Copyright (C) 2022 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; 23*7e128bbfSGreg 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 50c2ed51d1SGreg Roach * William /Lee/ Parry (surname imbedded 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 /** 89c2ed51d1SGreg Roach * Create a default value for this element. 90c2ed51d1SGreg Roach * 91c2ed51d1SGreg Roach * @param Tree $tree 92c2ed51d1SGreg Roach * 93c2ed51d1SGreg Roach * @return string 94c2ed51d1SGreg Roach */ 95c2ed51d1SGreg Roach public function default(Tree $tree): string 96c2ed51d1SGreg Roach { 97*7e128bbfSGreg Roach return Registry::surnameTraditionFactory() 98*7e128bbfSGreg Roach ->make($tree->getPreference('SURNAME_TRADITION')) 99*7e128bbfSGreg Roach ->defaultName(); 100c2ed51d1SGreg Roach } 101c2ed51d1SGreg Roach 102c2ed51d1SGreg Roach /** 103c2ed51d1SGreg Roach * An edit control for this data. 104c2ed51d1SGreg Roach * 105c2ed51d1SGreg Roach * @param string $id 106c2ed51d1SGreg Roach * @param string $name 107c2ed51d1SGreg Roach * @param string $value 108c2ed51d1SGreg Roach * @param Tree $tree 109c2ed51d1SGreg Roach * 110c2ed51d1SGreg Roach * @return string 111c2ed51d1SGreg Roach */ 112c2ed51d1SGreg Roach public function edit(string $id, string $name, string $value, Tree $tree): string 113c2ed51d1SGreg Roach { 114c2ed51d1SGreg Roach return 115c2ed51d1SGreg Roach '<div class="input-group">' . 116c2ed51d1SGreg Roach view('edit/input-addon-edit-name', ['id' => $id]) . 1174a213054SGreg Roach '<input class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" readonly="readonly" />' . 118c2ed51d1SGreg Roach view('edit/input-addon-keyboard', ['id' => $id]) . 119c2ed51d1SGreg Roach view('edit/input-addon-help', ['fact' => 'NAME']) . 120c2ed51d1SGreg Roach '</div>'; 121c2ed51d1SGreg Roach } 122c2ed51d1SGreg Roach 123c2ed51d1SGreg Roach /** 124c2ed51d1SGreg Roach * @return array<string,string> 125c2ed51d1SGreg Roach */ 1263d2c98d1SGreg Roach public function subtags(): array 127c2ed51d1SGreg Roach { 1284da96842SGreg Roach if (in_array(I18N::languageTag(), static::SURNAME_FIRST_LANGUAGES, true)) { 1294da96842SGreg Roach return static::SUBTAGS_SURNAME_FIRST; 130c2ed51d1SGreg Roach } 131c2ed51d1SGreg Roach 1324da96842SGreg Roach return static::SUBTAGS; 133c2ed51d1SGreg Roach } 134c2ed51d1SGreg Roach} 135