xref: /webtrees/app/SurnameTradition/IcelandicSurnameTradition.php (revision 323788f4145f5a5554b028e0581a6e2063364968)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2015 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16namespace Fisharebest\Webtrees\SurnameTradition;
17
18/**
19 * Children take a patronym instead of a surname.
20 *
21 * Sons get their father’s given name plus “sson”
22 * Daughters get their father’s given name plus “sdottir”
23 */
24class IcelandicSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface {
25	/**
26	 * What names are given to a new child
27	 *
28	 * @param string $father_name A GEDCOM NAME
29	 * @param string $mother_name A GEDCOM NAME
30	 * @param string $child_sex   M, F or U
31	 *
32	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
33	 */
34	public function newChildNames($father_name, $mother_name, $child_sex) {
35		if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) {
36			switch($child_sex) {
37			case 'M':
38				return array(
39					'NAME' => $father_match['GIVN'] . 'sson',
40				);
41			case 'F':
42				return array(
43					'NAME' => $father_match['GIVN'] . 'sdottir',
44				);
45			}
46		}
47
48		return array();
49	}
50
51	/**
52	 * What names are given to a new parent
53	 *
54	 * @param string $child_name A GEDCOM NAME
55	 * @param string $parent_sex M, F or U
56	 *
57	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
58	 */
59	public function newParentNames($child_name, $parent_sex) {
60		if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) {
61			return array(
62				'NAME' => $child_match['GIVN'],
63				'GIVN' => $child_match['GIVN'],
64			);
65		} else {
66			return array();
67		}
68	}
69
70	/**
71	 * What names are given to a new spouse
72	 *
73	 * @param string $spouse_name A GEDCOM NAME
74	 * @param string $spouse_sex  M, F or U
75	 *
76	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
77	 */
78	public function newSpouseNames($spouse_name, $spouse_sex) {
79		return array();
80	}
81}
82