1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 227c29ac65SGreg Roachuse Fisharebest\Webtrees\Elements\NameType; 237e128bbfSGreg Roachuse Fisharebest\Webtrees\I18N; 24cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 25cb7a42eaSGreg Roach 26323788f4SGreg Roach/** 27323788f4SGreg Roach * Children take their father’s surname. Wives take their husband’s surname. 28323788f4SGreg Roach */ 295206405dSRico Sonntagclass PaternalSurnameTradition extends PatrilinealSurnameTradition 30c1010edaSGreg Roach{ 31323788f4SGreg Roach /** 327e128bbfSGreg Roach * The name of this surname tradition 337e128bbfSGreg Roach * 347e128bbfSGreg Roach * @return string 357e128bbfSGreg Roach */ 367e128bbfSGreg Roach public function name(): string 377e128bbfSGreg Roach { 387e128bbfSGreg Roach return I18N::translateContext('Surname tradition', 'paternal'); 397e128bbfSGreg Roach } 407e128bbfSGreg Roach 417e128bbfSGreg Roach /** 427e128bbfSGreg Roach * A short description of this surname tradition 437e128bbfSGreg Roach * 447e128bbfSGreg Roach * @return string 457e128bbfSGreg Roach */ 467e128bbfSGreg Roach public function description(): string 477e128bbfSGreg Roach { 487e128bbfSGreg Roach /* I18N: In the paternal surname tradition, ... */ 497e128bbfSGreg Roach return 507e128bbfSGreg Roach I18N::translate('Children take their father’s surname.') . ' ' . 517e128bbfSGreg Roach I18N::translate('Wives take their husband’s surname.'); 527e128bbfSGreg Roach } 537e128bbfSGreg Roach 547e128bbfSGreg Roach /** 55cb7a42eaSGreg Roach * What name is given to a new parent 56323788f4SGreg Roach * 57cb7a42eaSGreg Roach * @param Individual $child 58cb7a42eaSGreg Roach * @param string $sex 59323788f4SGreg Roach * 6001ffdfd0SGreg Roach * @return array<int,string> 61323788f4SGreg Roach */ 62cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 63c1010edaSGreg Roach { 64ef475b14SGreg Roach if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match) === 1) { 65cb7a42eaSGreg Roach $name = $match['NAME']; 66cb7a42eaSGreg Roach $spfx = $match['SPFX']; 67cb7a42eaSGreg Roach $surn = $match['SURN']; 68323788f4SGreg Roach 6913abd6f3SGreg Roach return [ 7088a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 7188a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_MARRIED, 'SPFX' => $spfx, 'SURN' => $surn]), 7213abd6f3SGreg Roach ]; 73323788f4SGreg Roach } 74323788f4SGreg Roach 75cb7a42eaSGreg Roach return parent::newParentNames($child, $sex); 76cb7a42eaSGreg Roach } 77cb7a42eaSGreg Roach 78323788f4SGreg Roach /** 79323788f4SGreg Roach * What names are given to a new spouse 80323788f4SGreg Roach * 81cb7a42eaSGreg Roach * @param Individual $spouse 82cb7a42eaSGreg Roach * @param string $sex 83323788f4SGreg Roach * 8401ffdfd0SGreg Roach * @return array<int,string> 85323788f4SGreg Roach */ 86cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 87c1010edaSGreg Roach { 88ef475b14SGreg Roach if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($spouse), $match) === 1) { 89cb7a42eaSGreg Roach $name = $match['NAME']; 90cb7a42eaSGreg Roach $spfx = $match['SPFX']; 91cb7a42eaSGreg Roach $surn = $match['SURN']; 92cb7a42eaSGreg Roach 9313abd6f3SGreg Roach return [ 9488a03560SGreg Roach $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 9588a03560SGreg Roach $this->buildName($name, ['TYPE' => NameType::VALUE_MARRIED, 'SPFX' => $spfx, 'SURN' => $surn]), 9613abd6f3SGreg Roach ]; 97b2ce94c6SRico Sonntag } 98b2ce94c6SRico Sonntag 99cb7a42eaSGreg Roach return parent::newSpouseNames($spouse, $sex); 100323788f4SGreg Roach } 101323788f4SGreg Roach} 102