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