1323788f4SGreg Roach<?php 2323788f4SGreg Roach/** 3323788f4SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 5323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify 6323788f4SGreg Roach * it under the terms of the GNU General Public License as published by 7323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8323788f4SGreg Roach * (at your option) any later version. 9323788f4SGreg Roach * This program is distributed in the hope that it will be useful, 10323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12323788f4SGreg Roach * GNU General Public License for more details. 13323788f4SGreg Roach * You should have received a copy of the GNU General Public License 14323788f4SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15323788f4SGreg Roach */ 16323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition; 17323788f4SGreg Roach 18323788f4SGreg Roach/** 19323788f4SGreg Roach * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 20323788f4SGreg Roach */ 21c1010edaSGreg Roachclass PolishSurnameTradition extends PaternalSurnameTradition implements SurnameTraditionInterface 22c1010edaSGreg Roach{ 23323788f4SGreg Roach /** @var string[] Inflect a surname for females */ 2413abd6f3SGreg Roach protected $inflect_female = [ 25323788f4SGreg Roach 'cki\b' => 'cka', 26323788f4SGreg Roach 'dzki\b' => 'dzka', 27323788f4SGreg Roach 'ski\b' => 'ska', 2804a105eeSGreg Roach 'żki\b' => 'żka', 2913abd6f3SGreg Roach ]; 30323788f4SGreg Roach 31323788f4SGreg Roach /** @var string[] Inflect a surname for males */ 3213abd6f3SGreg Roach protected $inflect_male = [ 33323788f4SGreg Roach 'cka\b' => 'cki', 34323788f4SGreg Roach 'dzka\b' => 'dzki', 35323788f4SGreg Roach 'ska\b' => 'ski', 3604a105eeSGreg Roach 'żka\b' => 'żki', 3713abd6f3SGreg Roach ]; 38323788f4SGreg Roach 39323788f4SGreg Roach /** 40323788f4SGreg Roach * What names are given to a new child 41323788f4SGreg Roach * 42323788f4SGreg Roach * @param string $father_name A GEDCOM NAME 43323788f4SGreg Roach * @param string $mother_name A GEDCOM NAME 44323788f4SGreg Roach * @param string $child_sex M, F or U 45323788f4SGreg Roach * 46323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 47323788f4SGreg Roach */ 48*771ae10aSGreg Roach public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 49c1010edaSGreg Roach { 50323788f4SGreg Roach if (preg_match(self::REGEX_SURN, $father_name, $match)) { 51323788f4SGreg Roach if ($child_sex === 'F') { 5213abd6f3SGreg Roach return array_filter([ 53323788f4SGreg Roach 'NAME' => $this->inflect($match['NAME'], $this->inflect_female), 54323788f4SGreg Roach 'SURN' => $this->inflect($match['SURN'], $this->inflect_male), 5513abd6f3SGreg Roach ]); 56323788f4SGreg Roach } else { 5713abd6f3SGreg Roach return array_filter([ 58323788f4SGreg Roach 'NAME' => $this->inflect($match['NAME'], $this->inflect_male), 59323788f4SGreg Roach 'SURN' => $this->inflect($match['SURN'], $this->inflect_male), 6013abd6f3SGreg Roach ]); 61323788f4SGreg Roach } 62323788f4SGreg Roach } else { 6313abd6f3SGreg Roach return [ 64323788f4SGreg Roach 'NAME' => '//', 6513abd6f3SGreg Roach ]; 66323788f4SGreg Roach } 67323788f4SGreg Roach } 68323788f4SGreg Roach 69323788f4SGreg Roach /** 70323788f4SGreg Roach * What names are given to a new parent 71323788f4SGreg Roach * 72323788f4SGreg Roach * @param string $child_name A GEDCOM NAME 73323788f4SGreg Roach * @param string $parent_sex M, F or U 74323788f4SGreg Roach * 75323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 76323788f4SGreg Roach */ 77*771ae10aSGreg Roach public function newParentNames(string $child_name, string $parent_sex): array 78c1010edaSGreg Roach { 79323788f4SGreg Roach if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { 8013abd6f3SGreg Roach return array_filter([ 81323788f4SGreg Roach 'NAME' => $this->inflect($match['NAME'], $this->inflect_male), 82323788f4SGreg Roach 'SURN' => $this->inflect($match['SURN'], $this->inflect_male), 8313abd6f3SGreg Roach ]); 84323788f4SGreg Roach } else { 8513abd6f3SGreg Roach return [ 86323788f4SGreg Roach 'NAME' => '//', 8713abd6f3SGreg Roach ]; 88323788f4SGreg Roach } 89323788f4SGreg Roach } 90323788f4SGreg Roach 91323788f4SGreg Roach /** 92323788f4SGreg Roach * What names are given to a new spouse 93323788f4SGreg Roach * 94323788f4SGreg Roach * @param string $spouse_name A GEDCOM NAME 95323788f4SGreg Roach * @param string $spouse_sex M, F or U 96323788f4SGreg Roach * 97323788f4SGreg Roach * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 98323788f4SGreg Roach */ 99*771ae10aSGreg Roach public function newSpouseNames(string $spouse_name, string $spouse_sex): array 100c1010edaSGreg Roach { 101323788f4SGreg Roach if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 10213abd6f3SGreg Roach return [ 103323788f4SGreg Roach 'NAME' => '//', 104323788f4SGreg Roach '_MARNM' => $this->inflect($match['NAME'], $this->inflect_female), 10513abd6f3SGreg Roach ]; 106323788f4SGreg Roach } else { 10713abd6f3SGreg Roach return [ 108323788f4SGreg Roach 'NAME' => '//', 10913abd6f3SGreg Roach ]; 110323788f4SGreg Roach } 111323788f4SGreg Roach } 112323788f4SGreg Roach} 113