xref: /webtrees/app/SurnameTradition/SpanishSurnameTradition.php (revision fd6c003f26d8770d21ea893811f0fc20a190c323)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2019 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17declare(strict_types=1);
18
19namespace Fisharebest\Webtrees\SurnameTradition;
20
21/**
22 * Children take one surname from the father and one surname from the mother.
23 *
24 * Mother: Maria /AAAA/ /BBBB/
25 * Father: Jose  /CCCC/ /DDDD/
26 * Child:  Pablo /CCCC/ /AAAA/
27 */
28class SpanishSurnameTradition extends DefaultSurnameTradition
29{
30    /**
31     * What names are given to a new child
32     *
33     * @param string $father_name A GEDCOM NAME
34     * @param string $mother_name A GEDCOM NAME
35     * @param string $child_sex   M, F or U
36     *
37     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
38     */
39    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
40    {
41        if (preg_match(self::REGEX_SURNS, $father_name, $match_father)) {
42            $father_surname = $match_father['SURN1'];
43        } else {
44            $father_surname = '';
45        }
46
47        if (preg_match(self::REGEX_SURNS, $mother_name, $match_mother)) {
48            $mother_surname = $match_mother['SURN1'];
49        } else {
50            $mother_surname = '';
51        }
52
53        return [
54            'NAME' => '/' . $father_surname . '/ /' . $mother_surname . '/',
55            'SURN' => trim($father_surname . ',' . $mother_surname, ','),
56        ];
57    }
58
59    /**
60     * What names are given to a new parent
61     *
62     * @param string $child_name A GEDCOM NAME
63     * @param string $parent_sex M, F or U
64     *
65     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
66     */
67    public function newParentNames(string $child_name, string $parent_sex): array
68    {
69        if (preg_match(self::REGEX_SURNS, $child_name, $match)) {
70            switch ($parent_sex) {
71                case 'M':
72                    return [
73                        'NAME' => '/' . $match['SURN1'] . '/ //',
74                        'SURN' => $match['SURN1'],
75                    ];
76                case 'F':
77                    return [
78                        'NAME' => '/' . $match['SURN2'] . '/ //',
79                        'SURN' => $match['SURN2'],
80                    ];
81            }
82        }
83
84        return [
85            'NAME' => '// //',
86        ];
87    }
88
89    /**
90     * What names are given to a new spouse
91     *
92     * @param string $spouse_name A GEDCOM NAME
93     * @param string $spouse_sex  M, F or U
94     *
95     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
96     */
97    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
98    {
99        return [
100            'NAME' => '// //',
101        ];
102    }
103}
104