1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 55bfc6897SGreg 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 22*7c29ac65SGreg Roachuse Fisharebest\Webtrees\Elements\NameType; 23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 24cb7a42eaSGreg Roach 25323788f4SGreg Roach/** 26323788f4SGreg Roach * Children take one surname from the mother and one surname from the father. 27323788f4SGreg Roach * 28323788f4SGreg Roach * Mother: Maria /AAAA/ /BBBB/ 29323788f4SGreg Roach * Father: Jose /CCCC/ /DDDD/ 30323788f4SGreg Roach * Child: Pablo /DDDD/ /BBBB/ 31323788f4SGreg Roach */ 325206405dSRico Sonntagclass PortugueseSurnameTradition extends DefaultSurnameTradition 33c1010edaSGreg Roach{ 34323788f4SGreg Roach /** 35a171b6a5SGreg Roach * A default/empty name 36a171b6a5SGreg Roach * 37a171b6a5SGreg Roach * @return string 38a171b6a5SGreg Roach */ 39a171b6a5SGreg Roach public function defaultName(): string 40a171b6a5SGreg Roach { 41a171b6a5SGreg Roach return '// //'; 42a171b6a5SGreg Roach } 43a171b6a5SGreg Roach 44a171b6a5SGreg Roach /** 45cb7a42eaSGreg Roach * What name is given to a new child 46323788f4SGreg Roach * 47cb7a42eaSGreg Roach * @param Individual|null $father 48cb7a42eaSGreg Roach * @param Individual|null $mother 49cb7a42eaSGreg Roach * @param string $sex 50323788f4SGreg Roach * 5101ffdfd0SGreg Roach * @return array<int,string> 52323788f4SGreg Roach */ 53cb7a42eaSGreg Roach public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 54c1010edaSGreg Roach { 55cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) { 56323788f4SGreg Roach $father_surname = $match_father['SURN2']; 57323788f4SGreg Roach } else { 58323788f4SGreg Roach $father_surname = ''; 59323788f4SGreg Roach } 60323788f4SGreg Roach 61cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) { 62323788f4SGreg Roach $mother_surname = $match_mother['SURN2']; 63323788f4SGreg Roach } else { 64323788f4SGreg Roach $mother_surname = ''; 65323788f4SGreg Roach } 66323788f4SGreg Roach 6713abd6f3SGreg Roach return [ 68cb7a42eaSGreg Roach $this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [ 69*7c29ac65SGreg Roach 'TYPE' => NameType::TYPE_BIRTH, 70323788f4SGreg Roach 'SURN' => trim($father_surname . ',' . $mother_surname, ','), 71cb7a42eaSGreg Roach ]), 7213abd6f3SGreg Roach ]; 73323788f4SGreg Roach } 74323788f4SGreg Roach 75323788f4SGreg Roach /** 76cb7a42eaSGreg Roach * What name is given to a new parent 77323788f4SGreg Roach * 78cb7a42eaSGreg Roach * @param Individual $child 79cb7a42eaSGreg Roach * @param string $sex 80323788f4SGreg Roach * 8101ffdfd0SGreg Roach * @return array<int,string> 82323788f4SGreg Roach */ 83cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 84c1010edaSGreg Roach { 85cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) { 86cb7a42eaSGreg Roach switch ($sex) { 87323788f4SGreg Roach case 'M': 8813abd6f3SGreg Roach return [ 89cb7a42eaSGreg Roach $this->buildName('// /' . $match['SURN1'] . '/', [ 90*7c29ac65SGreg Roach 'TYPE' => NameType::TYPE_BIRTH, 91323788f4SGreg Roach 'SURN' => $match['SURN1'], 92cb7a42eaSGreg Roach ]), 9313abd6f3SGreg Roach ]; 94cb7a42eaSGreg Roach 95323788f4SGreg Roach case 'F': 9613abd6f3SGreg Roach return [ 97cb7a42eaSGreg Roach $this->buildName('// /' . $match['SURN2'] . '/', [ 98*7c29ac65SGreg Roach 'TYPE' => NameType::TYPE_BIRTH, 99323788f4SGreg Roach 'SURN' => $match['SURN2'], 100cb7a42eaSGreg Roach ]), 10113abd6f3SGreg Roach ]; 102323788f4SGreg Roach } 103323788f4SGreg Roach } 104323788f4SGreg Roach 10513abd6f3SGreg Roach return [ 106*7c29ac65SGreg Roach $this->buildName('// //', ['TYPE' => NameType::TYPE_BIRTH]), 10713abd6f3SGreg Roach ]; 108323788f4SGreg Roach } 109323788f4SGreg Roach 110323788f4SGreg Roach /** 111323788f4SGreg Roach * What names are given to a new spouse 112323788f4SGreg Roach * 113cb7a42eaSGreg Roach * @param Individual $spouse 114cb7a42eaSGreg Roach * @param string $sex 115323788f4SGreg Roach * 11601ffdfd0SGreg Roach * @return array<int,string> 117323788f4SGreg Roach */ 118cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 119c1010edaSGreg Roach { 12013abd6f3SGreg Roach return [ 121*7c29ac65SGreg Roach $this->buildName('// //', ['TYPE' => NameType::TYPE_BIRTH]), 12213abd6f3SGreg Roach ]; 123323788f4SGreg Roach } 124323788f4SGreg Roach} 125