1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2016 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 their father’s surname. Wives take their husband’s surname. 20 */ 21class PaternalSurnameTradition extends PatrilinealSurnameTradition implements SurnameTraditionInterface { 22 /** 23 * Does this surname tradition change surname at marriage? 24 * 25 * @return bool 26 */ 27 public function hasMarriedNames() { 28 return true; 29 } 30 31 /** 32 * What names are given to a new parent 33 * 34 * @param string $child_name A GEDCOM NAME 35 * @param string $parent_sex M, F or U 36 * 37 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 38 */ 39 public function newParentNames($child_name, $parent_sex) { 40 if (preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) { 41 switch ($parent_sex) { 42 case 'M': 43 return array_filter(array( 44 'NAME' => $match['NAME'], 45 'SPFX' => $match['SPFX'], 46 'SURN' => $match['SURN'], 47 )); 48 case 'F': 49 return array( 50 'NAME' => '//', 51 '_MARNM' => '/' . trim($match['SPFX'] . ' ' . $match['SURN']) . '/', 52 ); 53 } 54 } 55 56 return array( 57 'NAME' => '//', 58 ); 59 } 60 61 /** 62 * What names are given to a new spouse 63 * 64 * @param string $spouse_name A GEDCOM NAME 65 * @param string $spouse_sex M, F or U 66 * 67 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 68 */ 69 public function newSpouseNames($spouse_name, $spouse_sex) { 70 if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 71 return array( 72 'NAME' => '//', 73 '_MARNM' => $match['NAME'], 74 ); 75 } else { 76 return array( 77 'NAME' => '//', 78 ); 79 } 80 } 81} 82