xref: /webtrees/app/Elements/NamePersonal.php (revision 4da968426af896ee6732892cfd7b463b4397abaf)
1c2ed51d1SGreg Roach<?php
2c2ed51d1SGreg Roach
3c2ed51d1SGreg Roach/**
4c2ed51d1SGreg Roach * webtrees: online genealogy
5c2ed51d1SGreg Roach * Copyright (C) 2021 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;
23c2ed51d1SGreg Roachuse Fisharebest\Webtrees\SurnameTradition;
24c2ed51d1SGreg Roachuse Fisharebest\Webtrees\Tree;
25c2ed51d1SGreg Roach
26c2ed51d1SGreg Roachuse function e;
27*4da96842SGreg 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',
65*4da96842SGreg Roach        'NOTE' => '0:M',
66*4da96842SGreg Roach        'SOUR' => '0:M',
67*4da96842SGreg Roach        'FONE' => '0:M',
68*4da96842SGreg Roach        'ROMN' => '0:M',
69*4da96842SGreg Roach    ];
70*4da96842SGreg Roach
71*4da96842SGreg Roach    // For some languages, we want to show the surname field first.
72*4da96842SGreg Roach    protected const SURNAME_FIRST_LANGUAGES = ['hu', 'jp', 'ko', 'zh-Hans', 'zh-Hant'];
73*4da96842SGreg Roach
74*4da96842SGreg Roach    protected const SUBTAGS_SURNAME_FIRST = [
75*4da96842SGreg Roach        'TYPE' => '0:1',
76*4da96842SGreg Roach        'NPFX' => '0:1',
77*4da96842SGreg Roach        'SPFX' => '0:1',
78*4da96842SGreg Roach        'SURN' => '0:1',
79*4da96842SGreg Roach        'GIVN' => '0:1',
80*4da96842SGreg Roach        'NSFX' => '0:1',
81*4da96842SGreg Roach        'NICK' => '0:1',
82*4da96842SGreg Roach        'NOTE' => '0:M',
83*4da96842SGreg Roach        'SOUR' => '0:M',
84*4da96842SGreg Roach        'FONE' => '0:M',
85*4da96842SGreg 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    {
97c2ed51d1SGreg Roach        $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION'));
98c2ed51d1SGreg Roach
99c2ed51d1SGreg Roach        if ($surname_tradition->hasSurnames()) {
100c2ed51d1SGreg Roach            return '//';
101c2ed51d1SGreg Roach        }
102c2ed51d1SGreg Roach
103c2ed51d1SGreg Roach        return '';
104c2ed51d1SGreg Roach    }
105c2ed51d1SGreg Roach
106c2ed51d1SGreg Roach    /**
107c2ed51d1SGreg Roach     * An edit control for this data.
108c2ed51d1SGreg Roach     *
109c2ed51d1SGreg Roach     * @param string $id
110c2ed51d1SGreg Roach     * @param string $name
111c2ed51d1SGreg Roach     * @param string $value
112c2ed51d1SGreg Roach     * @param Tree   $tree
113c2ed51d1SGreg Roach     *
114c2ed51d1SGreg Roach     * @return string
115c2ed51d1SGreg Roach     */
116c2ed51d1SGreg Roach    public function edit(string $id, string $name, string $value, Tree $tree): string
117c2ed51d1SGreg Roach    {
118c2ed51d1SGreg Roach        return
119c2ed51d1SGreg Roach            '<div class="input-group">' .
120c2ed51d1SGreg Roach            view('edit/input-addon-edit-name', ['id' => $id]) .
1214a213054SGreg Roach            '<input class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" readonly="readonly" />' .
122c2ed51d1SGreg Roach            view('edit/input-addon-keyboard', ['id' => $id]) .
123c2ed51d1SGreg Roach            view('edit/input-addon-help', ['fact' => 'NAME']) .
124c2ed51d1SGreg Roach            '</div>';
125c2ed51d1SGreg Roach    }
126c2ed51d1SGreg Roach
127c2ed51d1SGreg Roach    /**
128c2ed51d1SGreg Roach     * @return array<string,string>
129c2ed51d1SGreg Roach     */
1303d2c98d1SGreg Roach    public function subtags(): array
131c2ed51d1SGreg Roach    {
132*4da96842SGreg Roach        if (in_array(I18N::languageTag(), static::SURNAME_FIRST_LANGUAGES, true)) {
133*4da96842SGreg Roach            return static::SUBTAGS_SURNAME_FIRST;
134c2ed51d1SGreg Roach        }
135c2ed51d1SGreg Roach
136*4da96842SGreg Roach        return static::SUBTAGS;
137c2ed51d1SGreg Roach    }
138c2ed51d1SGreg Roach}
139