xref: /webtrees/app/Elements/NamePersonal.php (revision d3e191dc13df4ee95fa867758ce98ec063566485)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Elements;
21
22use Fisharebest\Webtrees\I18N;
23use Fisharebest\Webtrees\SurnameTradition;
24use Fisharebest\Webtrees\Tree;
25
26use function e;
27use function view;
28
29/**
30 * NAME_PERSONAL := {Size=1:120}
31 * [
32 * <NAME_TEXT> | /<NAME_TEXT>/ |
33 * <NAME_TEXT> /<NAME_TEXT>/ | /<NAME_TEXT>/ <NAME_TEXT> |
34 * <NAME_TEXT> /<NAME_TEXT>/ <NAME_TEXT> ]
35 * The surname of an individual, if known, is enclosed between two slash (/)
36 * characters. The order of the name parts should be the order that the person
37 * would, by custom of their culture, have used when giving it to a recorder.
38 * Early versions of Personal Ancestral File ® and other products did not use
39 * the trailing slash when the surname was the last element of the name. If
40 * part of name is illegible, that part is indicated by an ellipsis (...).
41 * Capitalize the name of a person or place in the conventional manner—
42 * capitalize the first letter of each part and lowercase the other letters,
43 * unless conventional usage is otherwise. For example: McMurray.
44 * Examples:
45 * William Lee (given name only or surname not known)
46 * /Parry/ (surname only)
47 * William Lee /Parry/
48 * William Lee /Mac Parry/ (both parts (Mac and Parry) are surname parts
49 * William /Lee/ Parry (surname imbedded in the name string)
50 * William Lee /Pa.../
51 */
52class NamePersonal extends AbstractElement
53{
54    protected const MAXIMUM_LENGTH = 120;
55
56    protected const SUBTAGS = [
57        'TYPE' => '0:1',
58        'NPFX' => '0:1',
59        'GIVN' => '0:1',
60        'SPFX' => '0:1',
61        'SURN' => '0:1',
62        'NSFX' => '0:1',
63        'NICK' => '0:1',
64    ];
65
66    /**
67     * Create a default value for this element.
68     *
69     * @param Tree $tree
70     *
71     * @return string
72     */
73    public function default(Tree $tree): string
74    {
75        $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION'));
76
77        if ($surname_tradition->hasSurnames()) {
78            return '//';
79        }
80
81        return '';
82    }
83
84    /**
85     * An edit control for this data.
86     *
87     * @param string $id
88     * @param string $name
89     * @param string $value
90     * @param Tree   $tree
91     *
92     * @return string
93     */
94    public function edit(string $id, string $name, string $value, Tree $tree): string
95    {
96        return
97            '<div class="input-group">' .
98            view('edit/input-addon-edit-name', ['id' => $id]) .
99            '<input class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" readonly="readonly" />' .
100            view('edit/input-addon-keyboard', ['id' => $id]) .
101            view('edit/input-addon-help', ['fact' => 'NAME']) .
102            '</div>';
103    }
104
105    /**
106     * @return array<string,string>
107     */
108    public function subtags(): array
109    {
110        $language = I18N::languageTag();
111
112        switch ($language) {
113            case 'hu':
114            case 'jp':
115            case 'ko':
116            case 'zh-Hans':
117            case 'zh-Hant':
118                $subtags = [
119                    'TYPE' => '0:1',
120                    'NPFX' => '0:1',
121                    'SPFX' => '0:1',
122                    'SURN' => '0:1',
123                    'GIVN' => '0:1',
124                    'NSFX' => '0:1',
125                    'NICK' => '0:1',
126                ];
127                break;
128            default:
129                $subtags = [
130                    'TYPE' => '0:1',
131                    'NPFX' => '0:1',
132                    'GIVN' => '0:1',
133                    'SPFX' => '0:1',
134                    'SURN' => '0:1',
135                    'NSFX' => '0:1',
136                    'NICK' => '0:1',
137                ];
138                break;
139        }
140
141        return $subtags;
142    }
143}
144