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