1323788f4SGreg Roach<?php 2*3976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 58fcd0d32SGreg Roach * Copyright (C) 2019 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 15323788f4SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16323788f4SGreg Roach */ 17e7f56f2aSGreg Roachdeclare(strict_types=1); 18e7f56f2aSGreg Roach 19323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition; 20323788f4SGreg Roach 21323788f4SGreg Roach/** 22323788f4SGreg Roach * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 23323788f4SGreg Roach */ 245206405dSRico Sonntagclass PolishSurnameTradition extends PaternalSurnameTradition 25c1010edaSGreg Roach{ 26e364afe4SGreg Roach // Inflect a surname for females 27e364afe4SGreg Roach private const INFLECT_FEMALE = [ 28323788f4SGreg Roach 'cki\b' => 'cka', 29323788f4SGreg Roach 'dzki\b' => 'dzka', 30323788f4SGreg Roach 'ski\b' => 'ska', 3104a105eeSGreg Roach 'żki\b' => 'żka', 3213abd6f3SGreg Roach ]; 33323788f4SGreg Roach 34e364afe4SGreg Roach // Inflect a surname for males 35e364afe4SGreg Roach private const INFLECT_MALE = [ 36323788f4SGreg Roach 'cka\b' => 'cki', 37323788f4SGreg Roach 'dzka\b' => 'dzki', 38323788f4SGreg Roach 'ska\b' => 'ski', 3904a105eeSGreg Roach 'żka\b' => 'żki', 4013abd6f3SGreg Roach ]; 41323788f4SGreg Roach 42323788f4SGreg Roach /** 43323788f4SGreg Roach * What names are given to a new child 44323788f4SGreg Roach * 45323788f4SGreg Roach * @param string $father_name A GEDCOM NAME 46323788f4SGreg Roach * @param string $mother_name A GEDCOM NAME 47323788f4SGreg Roach * @param string $child_sex M, F or U 48323788f4SGreg Roach * 49323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 50323788f4SGreg Roach */ 51771ae10aSGreg Roach public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 52c1010edaSGreg Roach { 53323788f4SGreg Roach if (preg_match(self::REGEX_SURN, $father_name, $match)) { 54323788f4SGreg Roach if ($child_sex === 'F') { 5513abd6f3SGreg Roach return array_filter([ 56e364afe4SGreg Roach 'NAME' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), 57e364afe4SGreg Roach 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 5813abd6f3SGreg Roach ]); 59b2ce94c6SRico Sonntag } 60b2ce94c6SRico Sonntag 6113abd6f3SGreg Roach return array_filter([ 62e364afe4SGreg Roach 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), 63e364afe4SGreg Roach 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 6413abd6f3SGreg Roach ]); 65323788f4SGreg Roach } 66b2ce94c6SRico Sonntag 6713abd6f3SGreg Roach return [ 68323788f4SGreg Roach 'NAME' => '//', 6913abd6f3SGreg Roach ]; 70323788f4SGreg Roach } 71323788f4SGreg Roach 72323788f4SGreg Roach /** 73323788f4SGreg Roach * What names are given to a new parent 74323788f4SGreg Roach * 75323788f4SGreg Roach * @param string $child_name A GEDCOM NAME 76323788f4SGreg Roach * @param string $parent_sex M, F or U 77323788f4SGreg Roach * 78323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 79323788f4SGreg Roach */ 80771ae10aSGreg Roach public function newParentNames(string $child_name, string $parent_sex): array 81c1010edaSGreg Roach { 82323788f4SGreg Roach if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { 8313abd6f3SGreg Roach return array_filter([ 84e364afe4SGreg Roach 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), 85e364afe4SGreg Roach 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 8613abd6f3SGreg Roach ]); 87b2ce94c6SRico Sonntag } 88b2ce94c6SRico Sonntag 8913abd6f3SGreg Roach return [ 90323788f4SGreg Roach 'NAME' => '//', 9113abd6f3SGreg Roach ]; 92323788f4SGreg Roach } 93323788f4SGreg Roach 94323788f4SGreg Roach /** 95323788f4SGreg Roach * What names are given to a new spouse 96323788f4SGreg Roach * 97323788f4SGreg Roach * @param string $spouse_name A GEDCOM NAME 98323788f4SGreg Roach * @param string $spouse_sex M, F or U 99323788f4SGreg Roach * 100323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 101323788f4SGreg Roach */ 102771ae10aSGreg Roach public function newSpouseNames(string $spouse_name, string $spouse_sex): array 103c1010edaSGreg Roach { 104323788f4SGreg Roach if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 10513abd6f3SGreg Roach return [ 106323788f4SGreg Roach 'NAME' => '//', 107e364afe4SGreg Roach '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), 10813abd6f3SGreg Roach ]; 109b2ce94c6SRico Sonntag } 110b2ce94c6SRico Sonntag 11113abd6f3SGreg Roach return [ 112323788f4SGreg Roach 'NAME' => '//', 11313abd6f3SGreg Roach ]; 114323788f4SGreg Roach } 115323788f4SGreg Roach} 116