1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 55bfc6897SGreg Roach * Copyright (C) 2022 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 22*7c29ac65SGreg Roachuse Fisharebest\Webtrees\Elements\NameType; 23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 24cb7a42eaSGreg Roach 25323788f4SGreg Roach/** 26323788f4SGreg Roach * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 27323788f4SGreg Roach */ 285206405dSRico Sonntagclass PolishSurnameTradition extends PaternalSurnameTradition 29c1010edaSGreg Roach{ 30e364afe4SGreg Roach // Inflect a surname for females 31e364afe4SGreg Roach private const INFLECT_FEMALE = [ 32323788f4SGreg Roach 'cki\b' => 'cka', 33323788f4SGreg Roach 'dzki\b' => 'dzka', 34323788f4SGreg Roach 'ski\b' => 'ska', 3504a105eeSGreg Roach 'żki\b' => 'żka', 3613abd6f3SGreg Roach ]; 37323788f4SGreg Roach 38e364afe4SGreg Roach // Inflect a surname for males 39e364afe4SGreg Roach private const INFLECT_MALE = [ 40323788f4SGreg Roach 'cka\b' => 'cki', 41323788f4SGreg Roach 'dzka\b' => 'dzki', 42323788f4SGreg Roach 'ska\b' => 'ski', 4304a105eeSGreg Roach 'żka\b' => 'żki', 4413abd6f3SGreg Roach ]; 45323788f4SGreg Roach 46323788f4SGreg Roach /** 47cb7a42eaSGreg Roach * What name is given to a new child 48323788f4SGreg Roach * 49cb7a42eaSGreg Roach * @param Individual|null $father 50cb7a42eaSGreg Roach * @param Individual|null $mother 51cb7a42eaSGreg Roach * @param string $sex 52323788f4SGreg Roach * 5301ffdfd0SGreg Roach * @return array<int,string> 54323788f4SGreg Roach */ 55cb7a42eaSGreg Roach public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 56c1010edaSGreg Roach { 57cb7a42eaSGreg Roach if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) { 58cb7a42eaSGreg Roach if ($sex === 'F') { 59cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 60cb7a42eaSGreg Roach } else { 61cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 62b2ce94c6SRico Sonntag } 63b2ce94c6SRico Sonntag 64cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 65cb7a42eaSGreg Roach 66*7c29ac65SGreg Roach return [$this->buildName($name, ['TYPE' => NameType::TYPE_BIRTH, 'SURN' => $surn])]; 67323788f4SGreg Roach } 68b2ce94c6SRico Sonntag 69*7c29ac65SGreg Roach return [$this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH])]; 70323788f4SGreg Roach } 71323788f4SGreg Roach 72323788f4SGreg Roach /** 73cb7a42eaSGreg Roach * What name is given to a new parent 74323788f4SGreg Roach * 75cb7a42eaSGreg Roach * @param Individual $child 76cb7a42eaSGreg Roach * @param string $sex 77323788f4SGreg Roach * 7801ffdfd0SGreg Roach * @return array<int,string> 79323788f4SGreg Roach */ 80cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 81c1010edaSGreg Roach { 82cb7a42eaSGreg Roach if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) { 83cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 84cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 85b2ce94c6SRico Sonntag 8613abd6f3SGreg Roach return [ 87*7c29ac65SGreg Roach $this->buildName($name, ['TYPE' => NameType::TYPE_BIRTH, 'SURN' => $surn]), 8813abd6f3SGreg Roach ]; 89323788f4SGreg Roach } 90323788f4SGreg Roach 91*7c29ac65SGreg Roach return [$this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH])]; 92cb7a42eaSGreg Roach } 93cb7a42eaSGreg Roach 94323788f4SGreg Roach /** 95323788f4SGreg Roach * What names are given to a new spouse 96323788f4SGreg Roach * 97cb7a42eaSGreg Roach * @param Individual $spouse 98cb7a42eaSGreg Roach * @param string $sex 99323788f4SGreg Roach * 10001ffdfd0SGreg Roach * @return array<int,string> 101323788f4SGreg Roach */ 102cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 103c1010edaSGreg Roach { 104cb7a42eaSGreg Roach if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) { 105cb7a42eaSGreg Roach $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 106cb7a42eaSGreg Roach $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 107cb7a42eaSGreg Roach 10813abd6f3SGreg Roach return [ 109*7c29ac65SGreg Roach $this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH]), 110*7c29ac65SGreg Roach $this->buildName($name, ['TYPE' => NameType::TYPE_MARRIED, 'SURN' => $surn]), 11113abd6f3SGreg Roach ]; 112b2ce94c6SRico Sonntag } 113b2ce94c6SRico Sonntag 114*7c29ac65SGreg Roach return [$this->buildName('//', ['TYPE' => NameType::TYPE_BIRTH])]; 115323788f4SGreg Roach } 116323788f4SGreg Roach} 117