xref: /webtrees/app/Elements/NamePersonal.php (revision 78fee3e84e63c43d45ea62fdc40af779500b2bf6)
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;
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
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    /**
89*78fee3e8SGreg Roach     * AbstractGedcomElement constructor.
90*78fee3e8SGreg Roach     *
91*78fee3e8SGreg Roach     * @param string             $label
92*78fee3e8SGreg Roach     * @param array<string>|null $subtags
93*78fee3e8SGreg Roach     */
94*78fee3e8SGreg Roach    public function __construct(string $label, array $subtags = null)
95*78fee3e8SGreg Roach    {
96*78fee3e8SGreg Roach
97*78fee3e8SGreg Roach        if ($subtags === null && in_array(I18N::languageTag(), static::SURNAME_FIRST_LANGUAGES, true)) {
98*78fee3e8SGreg Roach            $subtags = static::SUBTAGS_SURNAME_FIRST;
99*78fee3e8SGreg Roach        }
100*78fee3e8SGreg Roach        parent::__construct($label, $subtags);
101*78fee3e8SGreg Roach    }
102*78fee3e8SGreg Roach
103*78fee3e8SGreg Roach    /**
104c2ed51d1SGreg Roach     * Create a default value for this element.
105c2ed51d1SGreg Roach     *
106c2ed51d1SGreg Roach     * @param Tree $tree
107c2ed51d1SGreg Roach     *
108c2ed51d1SGreg Roach     * @return string
109c2ed51d1SGreg Roach     */
110c2ed51d1SGreg Roach    public function default(Tree $tree): string
111c2ed51d1SGreg Roach    {
1127e128bbfSGreg Roach        return Registry::surnameTraditionFactory()
1137e128bbfSGreg Roach            ->make($tree->getPreference('SURNAME_TRADITION'))
1147e128bbfSGreg Roach            ->defaultName();
115c2ed51d1SGreg Roach    }
116c2ed51d1SGreg Roach
117c2ed51d1SGreg Roach    /**
118c2ed51d1SGreg Roach     * An edit control for this data.
119c2ed51d1SGreg Roach     *
120c2ed51d1SGreg Roach     * @param string $id
121c2ed51d1SGreg Roach     * @param string $name
122c2ed51d1SGreg Roach     * @param string $value
123c2ed51d1SGreg Roach     * @param Tree   $tree
124c2ed51d1SGreg Roach     *
125c2ed51d1SGreg Roach     * @return string
126c2ed51d1SGreg Roach     */
127c2ed51d1SGreg Roach    public function edit(string $id, string $name, string $value, Tree $tree): string
128c2ed51d1SGreg Roach    {
129c2ed51d1SGreg Roach        return
130c2ed51d1SGreg Roach            '<div class="input-group">' .
131c2ed51d1SGreg Roach            view('edit/input-addon-edit-name', ['id' => $id]) .
1324a213054SGreg Roach            '<input class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" readonly="readonly" />' .
133c2ed51d1SGreg Roach            view('edit/input-addon-keyboard', ['id' => $id]) .
134ab7d502dSGreg Roach            view('edit/input-addon-help', ['topic' => 'NAME']) .
135c2ed51d1SGreg Roach            '</div>';
136c2ed51d1SGreg Roach    }
137c2ed51d1SGreg Roach}
138