1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\SurnameTradition; 17 18/** 19 * Children take one surname from the mother and one surname from the father. 20 * 21 * Mother: Maria /AAAA/ /BBBB/ 22 * Father: Jose /CCCC/ /DDDD/ 23 * Child: Pablo /DDDD/ /BBBB/ 24 */ 25class PortugueseSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface 26{ 27 /** 28 * What names are given to a new child 29 * 30 * @param string $father_name A GEDCOM NAME 31 * @param string $mother_name A GEDCOM NAME 32 * @param string $child_sex M, F or U 33 * 34 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 35 */ 36 public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 37 { 38 if (preg_match(self::REGEX_SURNS, $father_name, $match_father)) { 39 $father_surname = $match_father['SURN2']; 40 } else { 41 $father_surname = ''; 42 } 43 44 if (preg_match(self::REGEX_SURNS, $mother_name, $match_mother)) { 45 $mother_surname = $match_mother['SURN2']; 46 } else { 47 $mother_surname = ''; 48 } 49 50 return [ 51 'NAME' => '/' . $father_surname . '/ /' . $mother_surname . '/', 52 'SURN' => trim($father_surname . ',' . $mother_surname, ','), 53 ]; 54 } 55 56 /** 57 * What names are given to a new parent 58 * 59 * @param string $child_name A GEDCOM NAME 60 * @param string $parent_sex M, F or U 61 * 62 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 63 */ 64 public function newParentNames(string $child_name, string $parent_sex): array 65 { 66 if (preg_match(self::REGEX_SURNS, $child_name, $match)) { 67 switch ($parent_sex) { 68 case 'M': 69 return [ 70 'NAME' => '// /' . $match['SURN1'] . '/', 71 'SURN' => $match['SURN1'], 72 ]; 73 case 'F': 74 return [ 75 'NAME' => '// /' . $match['SURN2'] . '/', 76 'SURN' => $match['SURN2'], 77 ]; 78 } 79 } 80 81 return [ 82 'NAME' => '// //', 83 ]; 84 } 85 86 /** 87 * What names are given to a new spouse 88 * 89 * @param string $spouse_name A GEDCOM NAME 90 * @param string $spouse_sex M, F or U 91 * 92 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 93 */ 94 public function newSpouseNames(string $spouse_name, string $spouse_sex): array 95 { 96 return [ 97 'NAME' => '// //', 98 ]; 99 } 100} 101