1323788f4SGreg Roach<?php 23976b470SGreg Roach 3323788f4SGreg Roach/** 4323788f4SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 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*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual; 23*cb7a42eaSGreg Roach 24323788f4SGreg Roach/** 25323788f4SGreg Roach * Children take a patronym instead of a surname. 26323788f4SGreg Roach * 27323788f4SGreg Roach * Sons get their father’s given name plus “sson” 28323788f4SGreg Roach * Daughters get their father’s given name plus “sdottir” 29323788f4SGreg Roach */ 305206405dSRico Sonntagclass IcelandicSurnameTradition extends DefaultSurnameTradition 31c1010edaSGreg Roach{ 32323788f4SGreg Roach /** 33c1ec7145SGreg Roach * Does this surname tradition use surnames? 34c1ec7145SGreg Roach * 35c1ec7145SGreg Roach * @return bool 36c1ec7145SGreg Roach */ 378f53f488SRico Sonntag public function hasSurnames(): bool 38c1010edaSGreg Roach { 39c1ec7145SGreg Roach return false; 40c1ec7145SGreg Roach } 41c1ec7145SGreg Roach 42c1ec7145SGreg Roach /** 43*cb7a42eaSGreg Roach * What name is given to a new child 44323788f4SGreg Roach * 45*cb7a42eaSGreg Roach * @param Individual|null $father 46*cb7a42eaSGreg Roach * @param Individual|null $mother 47*cb7a42eaSGreg Roach * @param string $sex 48323788f4SGreg Roach * 49*cb7a42eaSGreg Roach * @return array<string> 50323788f4SGreg Roach */ 51*cb7a42eaSGreg Roach public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 52c1010edaSGreg Roach { 53*cb7a42eaSGreg Roach if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match)) { 54*cb7a42eaSGreg Roach switch ($sex) { 55323788f4SGreg Roach case 'M': 56*cb7a42eaSGreg Roach $givn = $match['GIVN'] . 'sson'; 57*cb7a42eaSGreg Roach 5813abd6f3SGreg Roach return [ 59*cb7a42eaSGreg Roach $this->buildName($givn, ['TYPE' => 'birth', 'GIVN' => $givn]), 6013abd6f3SGreg Roach ]; 61*cb7a42eaSGreg Roach 62323788f4SGreg Roach case 'F': 63*cb7a42eaSGreg Roach $givn = $match['GIVN'] . 'sdottir'; 64*cb7a42eaSGreg Roach 6513abd6f3SGreg Roach return [ 66*cb7a42eaSGreg Roach $this->buildName($givn, ['TYPE' => 'birth', 'GIVN' => $givn]), 6713abd6f3SGreg Roach ]; 68323788f4SGreg Roach } 69323788f4SGreg Roach } 70323788f4SGreg Roach 71*cb7a42eaSGreg Roach return [ 72*cb7a42eaSGreg Roach $this->buildName('', ['TYPE' => 'birth']), 73*cb7a42eaSGreg Roach ]; 74323788f4SGreg Roach } 75323788f4SGreg Roach 76323788f4SGreg Roach /** 77*cb7a42eaSGreg Roach * What name is given to a new parent 78323788f4SGreg Roach * 79*cb7a42eaSGreg Roach * @param Individual $child 80*cb7a42eaSGreg Roach * @param string $sex 81323788f4SGreg Roach * 82*cb7a42eaSGreg Roach * @return array<string> 83323788f4SGreg Roach */ 84*cb7a42eaSGreg Roach public function newParentNames(Individual $child, string $sex): array 85c1010edaSGreg Roach { 86*cb7a42eaSGreg Roach if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match)) { 8713abd6f3SGreg Roach return [ 88*cb7a42eaSGreg Roach $this->buildName($match['GIVN'], ['TYPE' => 'birth', 'GIVN' => $match['GIVN']]), 8913abd6f3SGreg Roach ]; 90323788f4SGreg Roach } 91b2ce94c6SRico Sonntag 92*cb7a42eaSGreg Roach if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match)) { 93*cb7a42eaSGreg Roach return [ 94*cb7a42eaSGreg Roach $this->buildName($match['GIVN'], ['TYPE' => 'birth', 'GIVN' => $match['GIVN']]), 95*cb7a42eaSGreg Roach ]; 96*cb7a42eaSGreg Roach } 97*cb7a42eaSGreg Roach 98*cb7a42eaSGreg Roach return [ 99*cb7a42eaSGreg Roach $this->buildName('', ['TYPE' => 'birth']), 100*cb7a42eaSGreg Roach ]; 101323788f4SGreg Roach } 102323788f4SGreg Roach 103323788f4SGreg Roach /** 104323788f4SGreg Roach * What names are given to a new spouse 105323788f4SGreg Roach * 106*cb7a42eaSGreg Roach * @param Individual $spouse 107*cb7a42eaSGreg Roach * @param string $sex 108323788f4SGreg Roach * 109*cb7a42eaSGreg Roach * @return array<string> 110323788f4SGreg Roach */ 111*cb7a42eaSGreg Roach public function newSpouseNames(Individual $spouse, string $sex): array 112c1010edaSGreg Roach { 113*cb7a42eaSGreg Roach return [ 114*cb7a42eaSGreg Roach $this->buildName('', ['TYPE' => 'birth']), 115*cb7a42eaSGreg Roach ]; 116323788f4SGreg Roach } 117323788f4SGreg Roach} 118