xref: /webtrees/app/SurnameTradition/IcelandicSurnameTradition.php (revision c1010eda29c0909ed4d5d463f32d32bfefdd4dfe)
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 a patronym instead of a surname.
20323788f4SGreg Roach *
21323788f4SGreg Roach * Sons get their father’s given name plus “sson”
22323788f4SGreg Roach * Daughters get their father’s given name plus “sdottir”
23323788f4SGreg Roach */
24*c1010edaSGreg Roachclass IcelandicSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface
25*c1010edaSGreg Roach{
26323788f4SGreg Roach    /**
27c1ec7145SGreg Roach     * Does this surname tradition use surnames?
28c1ec7145SGreg Roach     *
29c1ec7145SGreg Roach     * @return bool
30c1ec7145SGreg Roach     */
31*c1010edaSGreg Roach    public function hasSurnames()
32*c1010edaSGreg Roach    {
33c1ec7145SGreg Roach        return false;
34c1ec7145SGreg Roach    }
35c1ec7145SGreg Roach
36c1ec7145SGreg Roach    /**
37323788f4SGreg Roach     * What names are given to a new child
38323788f4SGreg Roach     *
39323788f4SGreg Roach     * @param string $father_name A GEDCOM NAME
40323788f4SGreg Roach     * @param string $mother_name A GEDCOM NAME
41323788f4SGreg Roach     * @param string $child_sex   M, F or U
42323788f4SGreg Roach     *
43323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
44323788f4SGreg Roach     */
45*c1010edaSGreg Roach    public function newChildNames($father_name, $mother_name, $child_sex)
46*c1010edaSGreg Roach    {
47323788f4SGreg Roach        if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) {
48323788f4SGreg Roach            switch ($child_sex) {
49323788f4SGreg Roach                case 'M':
5013abd6f3SGreg Roach                    return [
51323788f4SGreg Roach                        'NAME' => $father_match['GIVN'] . 'sson',
5213abd6f3SGreg Roach                    ];
53323788f4SGreg Roach                case 'F':
5413abd6f3SGreg Roach                    return [
55323788f4SGreg Roach                        'NAME' => $father_match['GIVN'] . 'sdottir',
5613abd6f3SGreg Roach                    ];
57323788f4SGreg Roach            }
58323788f4SGreg Roach        }
59323788f4SGreg Roach
6013abd6f3SGreg Roach        return [];
61323788f4SGreg Roach    }
62323788f4SGreg Roach
63323788f4SGreg Roach    /**
64323788f4SGreg Roach     * What names are given to a new parent
65323788f4SGreg Roach     *
66323788f4SGreg Roach     * @param string $child_name A GEDCOM NAME
67323788f4SGreg Roach     * @param string $parent_sex M, F or U
68323788f4SGreg Roach     *
69323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
70323788f4SGreg Roach     */
71*c1010edaSGreg Roach    public function newParentNames($child_name, $parent_sex)
72*c1010edaSGreg Roach    {
73323788f4SGreg Roach        if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) {
7413abd6f3SGreg Roach            return [
75323788f4SGreg Roach                'NAME' => $child_match['GIVN'],
76323788f4SGreg Roach                'GIVN' => $child_match['GIVN'],
7713abd6f3SGreg Roach            ];
78323788f4SGreg Roach        } else {
7913abd6f3SGreg Roach            return [];
80323788f4SGreg Roach        }
81323788f4SGreg Roach    }
82323788f4SGreg Roach
83323788f4SGreg Roach    /**
84323788f4SGreg Roach     * What names are given to a new spouse
85323788f4SGreg Roach     *
86323788f4SGreg Roach     * @param string $spouse_name A GEDCOM NAME
87323788f4SGreg Roach     * @param string $spouse_sex  M, F or U
88323788f4SGreg Roach     *
89323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
90323788f4SGreg Roach     */
91*c1010edaSGreg Roach    public function newSpouseNames($spouse_name, $spouse_sex)
92*c1010edaSGreg Roach    {
9313abd6f3SGreg Roach        return [];
94323788f4SGreg Roach    }
95323788f4SGreg Roach}
96