xref: /webtrees/app/SurnameTradition/SpanishSurnameTradition.php (revision 89f7189b61a494347591c99bdb92afb7d8b66e1b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9323788f4SGreg Roach * (at your option) any later version.
10323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13323788f4SGreg Roach * GNU General Public License for more details.
14323788f4SGreg Roach * You should have received a copy of the GNU General Public License
15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16323788f4SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
20323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
21323788f4SGreg Roach
22323788f4SGreg Roach/**
23323788f4SGreg Roach * Children take one surname from the father and one surname from the mother.
24323788f4SGreg Roach *
25323788f4SGreg Roach * Mother: Maria /AAAA/ /BBBB/
26323788f4SGreg Roach * Father: Jose  /CCCC/ /DDDD/
27323788f4SGreg Roach * Child:  Pablo /CCCC/ /AAAA/
28323788f4SGreg Roach */
295206405dSRico Sonntagclass SpanishSurnameTradition extends DefaultSurnameTradition
30c1010edaSGreg Roach{
31323788f4SGreg Roach    /**
32323788f4SGreg Roach     * What names are given to a new child
33323788f4SGreg Roach     *
34323788f4SGreg Roach     * @param string $father_name A GEDCOM NAME
35323788f4SGreg Roach     * @param string $mother_name A GEDCOM NAME
36323788f4SGreg Roach     * @param string $child_sex   M, F or U
37323788f4SGreg Roach     *
38323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
39323788f4SGreg Roach     */
40771ae10aSGreg Roach    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
41c1010edaSGreg Roach    {
42323788f4SGreg Roach        if (preg_match(self::REGEX_SURNS, $father_name, $match_father)) {
43323788f4SGreg Roach            $father_surname = $match_father['SURN1'];
44323788f4SGreg Roach        } else {
45323788f4SGreg Roach            $father_surname = '';
46323788f4SGreg Roach        }
47323788f4SGreg Roach
48323788f4SGreg Roach        if (preg_match(self::REGEX_SURNS, $mother_name, $match_mother)) {
49323788f4SGreg Roach            $mother_surname = $match_mother['SURN1'];
50323788f4SGreg Roach        } else {
51323788f4SGreg Roach            $mother_surname = '';
52323788f4SGreg Roach        }
53323788f4SGreg Roach
5413abd6f3SGreg Roach        return [
55323788f4SGreg Roach            'NAME' => '/' . $father_surname . '/ /' . $mother_surname . '/',
56323788f4SGreg Roach            'SURN' => trim($father_surname . ',' . $mother_surname, ','),
5713abd6f3SGreg Roach        ];
58323788f4SGreg Roach    }
59323788f4SGreg Roach
60323788f4SGreg Roach    /**
61323788f4SGreg Roach     * What names are given to a new parent
62323788f4SGreg Roach     *
63323788f4SGreg Roach     * @param string $child_name A GEDCOM NAME
64323788f4SGreg Roach     * @param string $parent_sex M, F or U
65323788f4SGreg Roach     *
66323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
67323788f4SGreg Roach     */
68771ae10aSGreg Roach    public function newParentNames(string $child_name, string $parent_sex): array
69c1010edaSGreg Roach    {
70323788f4SGreg Roach        if (preg_match(self::REGEX_SURNS, $child_name, $match)) {
71323788f4SGreg Roach            switch ($parent_sex) {
72323788f4SGreg Roach                case 'M':
7313abd6f3SGreg Roach                    return [
74323788f4SGreg Roach                        'NAME' => '/' . $match['SURN1'] . '/ //',
75323788f4SGreg Roach                        'SURN' => $match['SURN1'],
7613abd6f3SGreg Roach                    ];
77323788f4SGreg Roach                case 'F':
7813abd6f3SGreg Roach                    return [
79323788f4SGreg Roach                        'NAME' => '/' . $match['SURN2'] . '/ //',
80323788f4SGreg Roach                        'SURN' => $match['SURN2'],
8113abd6f3SGreg Roach                    ];
82323788f4SGreg Roach            }
83323788f4SGreg Roach        }
84323788f4SGreg Roach
8513abd6f3SGreg Roach        return [
86fb6e3413SGreg Roach            'NAME' => '// //',
8713abd6f3SGreg Roach        ];
88323788f4SGreg Roach    }
89323788f4SGreg Roach
90323788f4SGreg Roach    /**
91323788f4SGreg Roach     * What names are given to a new spouse
92323788f4SGreg Roach     *
93323788f4SGreg Roach     * @param string $spouse_name A GEDCOM NAME
94323788f4SGreg Roach     * @param string $spouse_sex  M, F or U
95323788f4SGreg Roach     *
96323788f4SGreg Roach     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
97323788f4SGreg Roach     */
98771ae10aSGreg Roach    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
99c1010edaSGreg Roach    {
10013abd6f3SGreg Roach        return [
101323788f4SGreg Roach            'NAME' => '// //',
10213abd6f3SGreg Roach        ];
103323788f4SGreg Roach    }
104323788f4SGreg Roach}
105