1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5*5bfc6897SGreg Roach * Copyright (C) 2022 webtrees development team 6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify 7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by 8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9323788f4SGreg Roach * (at your option) any later version. 10323788f4SGreg Roach * This program is distributed in the hope that it will be useful, 11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13323788f4SGreg Roach * GNU General Public License for more details. 14323788f4SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16323788f4SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 20323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition; 21323788f4SGreg Roach 22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 23cb7a42eaSGreg Roach 24323788f4SGreg Roach/** 25323788f4SGreg Roach * Children take one surname from the mother and one surname from the father. 26323788f4SGreg Roach * 27323788f4SGreg Roach * Mother: Maria /AAAA/ /BBBB/ 28323788f4SGreg Roach * Father: Jose /CCCC/ /DDDD/ 29323788f4SGreg Roach * Child: Pablo /DDDD/ /BBBB/ 30323788f4SGreg Roach */ 315206405dSRico Sonntagclass PortugueseSurnameTradition extends DefaultSurnameTradition 32c1010edaSGreg Roach{ 33323788f4SGreg Roach /** 34a171b6a5SGreg Roach * A default/empty name 35a171b6a5SGreg Roach * 36a171b6a5SGreg Roach * @return string 37a171b6a5SGreg Roach */ 38a171b6a5SGreg Roach public function defaultName(): string 39a171b6a5SGreg Roach { 40a171b6a5SGreg Roach return '// //'; 41a171b6a5SGreg Roach } 42a171b6a5SGreg Roach 43a171b6a5SGreg Roach /** 44cb7a42eaSGreg Roach * What name is given to a new child 45323788f4SGreg Roach * 46cb7a42eaSGreg Roach * @param Individual|null $father 47cb7a42eaSGreg Roach * @param Individual|null $mother 48cb7a42eaSGreg Roach * @param string $sex 49323788f4SGreg Roach * 5001ffdfd0SGreg Roach * @return array<int,string> 51323788f4SGreg Roach */ 52cb7a42eaSGreg Roach public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 53c1010edaSGreg Roach { 54cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { 55323788f4SGreg Roach $father_surname = $match_father['SURN2']; 56323788f4SGreg Roach } else { 57323788f4SGreg Roach $father_surname = ''; 58323788f4SGreg Roach } 59323788f4SGreg Roach 60cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { 61323788f4SGreg Roach $mother_surname = $match_mother['SURN2']; 62323788f4SGreg Roach } else { 63323788f4SGreg Roach $mother_surname = ''; 64323788f4SGreg Roach } 65323788f4SGreg Roach 6613abd6f3SGreg Roach return [ 67cb7a42eaSGreg Roach $this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [ 68cb7a42eaSGreg Roach 'TYPE' => 'birth', 69323788f4SGreg Roach 'SURN' => trim($father_surname . ',' . $mother_surname, ','), 70cb7a42eaSGreg Roach ]), 7113abd6f3SGreg Roach ]; 72323788f4SGreg Roach } 73323788f4SGreg Roach 74323788f4SGreg Roach /** 75cb7a42eaSGreg Roach * What name is given to a new parent 76323788f4SGreg Roach * 77cb7a42eaSGreg Roach * @param Individual $child 78cb7a42eaSGreg Roach * @param string $sex 79323788f4SGreg Roach * 8001ffdfd0SGreg Roach * @return array<int,string> 81323788f4SGreg Roach */ 82cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 83c1010edaSGreg Roach { 84cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { 85cb7a42eaSGreg Roach switch ($sex) { 86323788f4SGreg Roach case 'M': 8713abd6f3SGreg Roach return [ 88cb7a42eaSGreg Roach $this->buildName('// /' . $match['SURN1'] . '/', [ 89cb7a42eaSGreg Roach 'TYPE' => 'birth', 90323788f4SGreg Roach 'SURN' => $match['SURN1'], 91cb7a42eaSGreg Roach ]), 9213abd6f3SGreg Roach ]; 93cb7a42eaSGreg Roach 94323788f4SGreg Roach case 'F': 9513abd6f3SGreg Roach return [ 96cb7a42eaSGreg Roach $this->buildName('// /' . $match['SURN2'] . '/', [ 97cb7a42eaSGreg Roach 'TYPE' => 'birth', 98323788f4SGreg Roach 'SURN' => $match['SURN2'], 99cb7a42eaSGreg Roach ]), 10013abd6f3SGreg Roach ]; 101323788f4SGreg Roach } 102323788f4SGreg Roach } 103323788f4SGreg Roach 10413abd6f3SGreg Roach return [ 105cb7a42eaSGreg Roach $this->buildName('// //', ['TYPE' => 'birth']), 10613abd6f3SGreg Roach ]; 107323788f4SGreg Roach } 108323788f4SGreg Roach 109323788f4SGreg Roach /** 110323788f4SGreg Roach * What names are given to a new spouse 111323788f4SGreg Roach * 112cb7a42eaSGreg Roach * @param Individual $spouse 113cb7a42eaSGreg Roach * @param string $sex 114323788f4SGreg Roach * 11501ffdfd0SGreg Roach * @return array<int,string> 116323788f4SGreg Roach */ 117cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 118c1010edaSGreg Roach { 11913abd6f3SGreg Roach return [ 120cb7a42eaSGreg Roach $this->buildName('// //', ['TYPE' => 'birth']), 12113abd6f3SGreg Roach ]; 122323788f4SGreg Roach } 123323788f4SGreg Roach} 124