xref: /webtrees/app/Elements/NamePersonal.php (revision ae0043b720d44ad147874b2a3afe4e7a347c314a)
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;
27c2ed51d1SGreg Roachuse function view;
28c2ed51d1SGreg Roach
29c2ed51d1SGreg Roach/**
30c2ed51d1SGreg Roach * NAME_PERSONAL := {Size=1:120}
31c2ed51d1SGreg Roach * [
32c2ed51d1SGreg Roach * <NAME_TEXT> | /<NAME_TEXT>/ |
33c2ed51d1SGreg Roach * <NAME_TEXT> /<NAME_TEXT>/ | /<NAME_TEXT>/ <NAME_TEXT> |
34c2ed51d1SGreg Roach * <NAME_TEXT> /<NAME_TEXT>/ <NAME_TEXT> ]
35c2ed51d1SGreg Roach * The surname of an individual, if known, is enclosed between two slash (/)
36c2ed51d1SGreg Roach * characters. The order of the name parts should be the order that the person
37c2ed51d1SGreg Roach * would, by custom of their culture, have used when giving it to a recorder.
38c2ed51d1SGreg Roach * Early versions of Personal Ancestral File ® and other products did not use
39c2ed51d1SGreg Roach * the trailing slash when the surname was the last element of the name. If
40c2ed51d1SGreg Roach * part of name is illegible, that part is indicated by an ellipsis (...).
41c2ed51d1SGreg Roach * Capitalize the name of a person or place in the conventional manner—
42c2ed51d1SGreg Roach * capitalize the first letter of each part and lowercase the other letters,
43c2ed51d1SGreg Roach * unless conventional usage is otherwise. For example: McMurray.
44c2ed51d1SGreg Roach * Examples:
45c2ed51d1SGreg Roach * William Lee (given name only or surname not known)
46c2ed51d1SGreg Roach * /Parry/ (surname only)
47c2ed51d1SGreg Roach * William Lee /Parry/
48c2ed51d1SGreg Roach * William Lee /Mac Parry/ (both parts (Mac and Parry) are surname parts
49c2ed51d1SGreg Roach * William /Lee/ Parry (surname imbedded in the name string)
50c2ed51d1SGreg Roach * William Lee /Pa.../
51c2ed51d1SGreg Roach */
52c2ed51d1SGreg Roachclass NamePersonal extends AbstractElement
53c2ed51d1SGreg Roach{
54*ae0043b7SGreg Roach    protected const MAXIMUM_LENGTH = 120;
55c2ed51d1SGreg Roach
56c2ed51d1SGreg Roach    protected const SUBTAGS = [
57c2ed51d1SGreg Roach        'TYPE' => '0:1',
58c2ed51d1SGreg Roach        'NPFX' => '0:1',
59c2ed51d1SGreg Roach        'GIVN' => '0:1',
60c2ed51d1SGreg Roach        'SPFX' => '0:1',
61c2ed51d1SGreg Roach        'SURN' => '0:1',
62c2ed51d1SGreg Roach        'NSFX' => '0:1',
63c2ed51d1SGreg Roach        'NICK' => '0:1',
64c2ed51d1SGreg Roach    ];
65c2ed51d1SGreg Roach
66c2ed51d1SGreg Roach    /**
67c2ed51d1SGreg Roach     * Create a default value for this element.
68c2ed51d1SGreg Roach     *
69c2ed51d1SGreg Roach     * @param Tree $tree
70c2ed51d1SGreg Roach     *
71c2ed51d1SGreg Roach     * @return string
72c2ed51d1SGreg Roach     */
73c2ed51d1SGreg Roach    public function default(Tree $tree): string
74c2ed51d1SGreg Roach    {
75c2ed51d1SGreg Roach        $surname_tradition = SurnameTradition::create($tree->getPreference('SURNAME_TRADITION'));
76c2ed51d1SGreg Roach
77c2ed51d1SGreg Roach        if ($surname_tradition->hasSurnames()) {
78c2ed51d1SGreg Roach            return '//';
79c2ed51d1SGreg Roach        }
80c2ed51d1SGreg Roach
81c2ed51d1SGreg Roach        return '';
82c2ed51d1SGreg Roach    }
83c2ed51d1SGreg Roach
84c2ed51d1SGreg Roach    /**
85c2ed51d1SGreg Roach     * An edit control for this data.
86c2ed51d1SGreg Roach     *
87c2ed51d1SGreg Roach     * @param string $id
88c2ed51d1SGreg Roach     * @param string $name
89c2ed51d1SGreg Roach     * @param string $value
90c2ed51d1SGreg Roach     * @param Tree   $tree
91c2ed51d1SGreg Roach     *
92c2ed51d1SGreg Roach     * @return string
93c2ed51d1SGreg Roach     */
94c2ed51d1SGreg Roach    public function edit(string $id, string $name, string $value, Tree $tree): string
95c2ed51d1SGreg Roach    {
96c2ed51d1SGreg Roach        return
97c2ed51d1SGreg Roach            '<div class="input-group">' .
98c2ed51d1SGreg Roach            view('edit/input-addon-edit-name', ['id' => $id]) .
99c2ed51d1SGreg Roach            '<input class="form-control" type="text" id="' . e($id) . '" name="' . e($name) . '" value="' . e($value) . '" readonly>' .
100c2ed51d1SGreg Roach            view('edit/input-addon-keyboard', ['id' => $id]) .
101c2ed51d1SGreg Roach            view('edit/input-addon-help', ['fact' => 'NAME']) .
102c2ed51d1SGreg Roach            '</div>';
103c2ed51d1SGreg Roach    }
104c2ed51d1SGreg Roach
105c2ed51d1SGreg Roach    /**
106c2ed51d1SGreg Roach     * @param Tree $tree
107c2ed51d1SGreg Roach     *
108c2ed51d1SGreg Roach     * @return array<string,string>
109c2ed51d1SGreg Roach     */
110c2ed51d1SGreg Roach    public function subtags(Tree $tree): array
111c2ed51d1SGreg Roach    {
112c2ed51d1SGreg Roach        $language = I18N::languageTag();
113c2ed51d1SGreg Roach
114c2ed51d1SGreg Roach        switch ($language) {
115c2ed51d1SGreg Roach            case 'hu':
116c2ed51d1SGreg Roach            case 'jp':
117c2ed51d1SGreg Roach            case 'ko':
118c2ed51d1SGreg Roach            case 'zh-Hans':
119c2ed51d1SGreg Roach            case 'zh-Hant':
120c2ed51d1SGreg Roach                $subtags = [
121c2ed51d1SGreg Roach                    'TYPE' => '0:1',
122c2ed51d1SGreg Roach                    'NPFX' => '0:1',
123c2ed51d1SGreg Roach                    'SPFX' => '0:1',
124c2ed51d1SGreg Roach                    'SURN' => '0:1',
125c2ed51d1SGreg Roach                    'GIVN' => '0:1',
126c2ed51d1SGreg Roach                    'NSFX' => '0:1',
127c2ed51d1SGreg Roach                    'NICK' => '0:1',
128c2ed51d1SGreg Roach                ];
129c2ed51d1SGreg Roach                break;
130c2ed51d1SGreg Roach            default:
131c2ed51d1SGreg Roach                $subtags = [
132c2ed51d1SGreg Roach                    'TYPE' => '0:1',
133c2ed51d1SGreg Roach                    'NPFX' => '0:1',
134c2ed51d1SGreg Roach                    'GIVN' => '0:1',
135c2ed51d1SGreg Roach                    'SPFX' => '0:1',
136c2ed51d1SGreg Roach                    'SURN' => '0:1',
137c2ed51d1SGreg Roach                    'NSFX' => '0:1',
138c2ed51d1SGreg Roach                    'NICK' => '0:1',
139c2ed51d1SGreg Roach                ];
140c2ed51d1SGreg Roach                break;
141c2ed51d1SGreg Roach        }
142c2ed51d1SGreg Roach
143c2ed51d1SGreg Roach        return $subtags;
144c2ed51d1SGreg Roach    }
145c2ed51d1SGreg Roach}
146