xref: /webtrees/app/SurnameTradition/SpanishSurnameTradition.php (revision fb6e3413fb313e6c01d932943e5d6b0806b128b3)
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 one surname from the father and one surname from the mother.
20 *
21 * Mother: Maria /AAAA/ /BBBB/
22 * Father: Jose  /CCCC/ /DDDD/
23 * Child:  Pablo /CCCC/ /AAAA/
24 */
25class SpanishSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface {
26	/**
27	 * What names are given to a new child
28	 *
29	 * @param string $father_name A GEDCOM NAME
30	 * @param string $mother_name A GEDCOM NAME
31	 * @param string $child_sex   M, F or U
32	 *
33	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
34	 */
35	public function newChildNames($father_name, $mother_name, $child_sex) {
36		if (preg_match(self::REGEX_SURNS, $father_name, $match_father)) {
37			$father_surname = $match_father['SURN1'];
38		} else {
39			$father_surname = '';
40		}
41
42		if (preg_match(self::REGEX_SURNS, $mother_name, $match_mother)) {
43			$mother_surname = $match_mother['SURN1'];
44		} else {
45			$mother_surname = '';
46		}
47
48		return array(
49			'NAME' => '/' . $father_surname . '/ /' . $mother_surname . '/',
50			'SURN' => trim($father_surname . ',' . $mother_surname, ','),
51		);
52	}
53
54	/**
55	 * What names are given to a new parent
56	 *
57	 * @param string $child_name A GEDCOM NAME
58	 * @param string $parent_sex M, F or U
59	 *
60	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
61	 */
62	public function newParentNames($child_name, $parent_sex) {
63		if (preg_match(self::REGEX_SURNS, $child_name, $match)) {
64			switch($parent_sex) {
65			case 'M':
66				return array(
67					'NAME' => '/' . $match['SURN1'] . '/ //',
68					'SURN' => $match['SURN1'],
69				);
70			case 'F':
71				return array(
72					'NAME' => '/' . $match['SURN2'] . '/ //',
73					'SURN' => $match['SURN2'],
74				);
75			}
76		}
77
78		return array(
79			'NAME' => '// //',
80		);
81	}
82
83	/**
84	 * What names are given to a new spouse
85	 *
86	 * @param string $spouse_name A GEDCOM NAME
87	 * @param string $spouse_sex  M, F or U
88	 *
89	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
90	 */
91	public function newSpouseNames($spouse_name, $spouse_sex) {
92		return array(
93			'NAME' => '// //',
94		);
95	}
96}
97