|
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
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\SurnameTradition; |
|
21
|
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\Individual; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Children take one surname from the mother and one surname from the father. |
|
26
|
|
|
* |
|
27
|
|
|
* Mother: Maria /AAAA/ /BBBB/ |
|
28
|
|
|
* Father: Jose /CCCC/ /DDDD/ |
|
29
|
|
|
* Child: Pablo /DDDD/ /BBBB/ |
|
30
|
|
|
*/ |
|
31
|
|
|
class PortugueseSurnameTradition extends DefaultSurnameTradition |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* A default/empty name |
|
35
|
|
|
* |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function defaultName(): string |
|
39
|
|
|
{ |
|
40
|
|
|
return '// //'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* What name is given to a new child |
|
45
|
|
|
* |
|
46
|
|
|
* @param Individual|null $father |
|
47
|
|
|
* @param Individual|null $mother |
|
48
|
|
|
* @param string $sex |
|
49
|
|
|
* |
|
50
|
|
|
* @return array<int,string> |
|
51
|
|
|
*/ |
|
52
|
|
|
public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array |
|
53
|
|
|
{ |
|
54
|
|
|
if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { |
|
55
|
|
|
$father_surname = $match_father['SURN2']; |
|
56
|
|
|
} else { |
|
57
|
|
|
$father_surname = ''; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { |
|
61
|
|
|
$mother_surname = $match_mother['SURN2']; |
|
62
|
|
|
} else { |
|
63
|
|
|
$mother_surname = ''; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return [ |
|
67
|
|
|
$this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [ |
|
68
|
|
|
'TYPE' => 'birth', |
|
69
|
|
|
'SURN' => trim($father_surname . ',' . $mother_surname, ','), |
|
70
|
|
|
]), |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* What name is given to a new parent |
|
76
|
|
|
* |
|
77
|
|
|
* @param Individual $child |
|
78
|
|
|
* @param string $sex |
|
79
|
|
|
* |
|
80
|
|
|
* @return array<int,string> |
|
81
|
|
|
*/ |
|
82
|
|
|
public function newParentNames(Individual $child, string $sex): array |
|
83
|
|
|
{ |
|
84
|
|
|
if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { |
|
85
|
|
|
switch ($sex) { |
|
86
|
|
|
case 'M': |
|
87
|
|
|
return [ |
|
88
|
|
|
$this->buildName('// /' . $match['SURN1'] . '/', [ |
|
89
|
|
|
'TYPE' => 'birth', |
|
90
|
|
|
'SURN' => $match['SURN1'], |
|
91
|
|
|
]), |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
|
|
case 'F': |
|
95
|
|
|
return [ |
|
96
|
|
|
$this->buildName('// /' . $match['SURN2'] . '/', [ |
|
97
|
|
|
'TYPE' => 'birth', |
|
98
|
|
|
'SURN' => $match['SURN2'], |
|
99
|
|
|
]), |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return [ |
|
105
|
|
|
$this->buildName('// //', ['TYPE' => 'birth']), |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* What names are given to a new spouse |
|
111
|
|
|
* |
|
112
|
|
|
* @param Individual $spouse |
|
113
|
|
|
* @param string $sex |
|
114
|
|
|
* |
|
115
|
|
|
* @return array<int,string> |
|
116
|
|
|
*/ |
|
117
|
|
|
public function newSpouseNames(Individual $spouse, string $sex): array |
|
118
|
|
|
{ |
|
119
|
|
|
return [ |
|
120
|
|
|
$this->buildName('// //', ['TYPE' => 'birth']), |
|
121
|
|
|
]; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|