xref: /webtrees/app/SurnameTradition/SpanishSurnameTradition.php (revision 1ff45046fabc22237b5d0d8e489c96f031fc598d)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg 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
227c29ac65SGreg Roachuse Fisharebest\Webtrees\Elements\NameType;
237e128bbfSGreg Roachuse Fisharebest\Webtrees\I18N;
24cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
25cb7a42eaSGreg Roach
26323788f4SGreg Roach/**
27323788f4SGreg Roach * Children take one surname from the father and one surname from the mother.
28323788f4SGreg Roach *
29323788f4SGreg Roach * Mother: Maria /AAAA/ /BBBB/
30323788f4SGreg Roach * Father: Jose  /CCCC/ /DDDD/
31323788f4SGreg Roach * Child:  Pablo /CCCC/ /AAAA/
32323788f4SGreg Roach */
335206405dSRico Sonntagclass SpanishSurnameTradition extends DefaultSurnameTradition
34c1010edaSGreg Roach{
35323788f4SGreg Roach    /**
367e128bbfSGreg Roach     * The name of this surname tradition
377e128bbfSGreg Roach     *
387e128bbfSGreg Roach     * @return string
397e128bbfSGreg Roach     */
407e128bbfSGreg Roach    public function name(): string
417e128bbfSGreg Roach    {
427e128bbfSGreg Roach        return I18N::translateContext('Surname tradition', 'Spanish');
437e128bbfSGreg Roach    }
447e128bbfSGreg Roach
457e128bbfSGreg Roach    /**
467e128bbfSGreg Roach     * A short description of this surname tradition
477e128bbfSGreg Roach     *
487e128bbfSGreg Roach     * @return string
497e128bbfSGreg Roach     */
507e128bbfSGreg Roach    public function description(): string
517e128bbfSGreg Roach    {
527e128bbfSGreg Roach        /* I18N: In the Spanish surname tradition, ... */
537e128bbfSGreg Roach        return I18N::translate('Children take one surname from the father and one surname from the mother.');
547e128bbfSGreg Roach    }
557e128bbfSGreg Roach
567e128bbfSGreg Roach    /**
57a171b6a5SGreg Roach     * A default/empty name
58a171b6a5SGreg Roach     *
59a171b6a5SGreg Roach     * @return string
60a171b6a5SGreg Roach     */
61a171b6a5SGreg Roach    public function defaultName(): string
62a171b6a5SGreg Roach    {
63a171b6a5SGreg Roach        return '// //';
64a171b6a5SGreg Roach    }
65a171b6a5SGreg Roach
66a171b6a5SGreg Roach    /**
67cb7a42eaSGreg Roach     * What name is given to a new child
68323788f4SGreg Roach     *
69cb7a42eaSGreg Roach     * @param Individual|null $father
70cb7a42eaSGreg Roach     * @param Individual|null $mother
71cb7a42eaSGreg Roach     * @param string          $sex
72323788f4SGreg Roach     *
7301ffdfd0SGreg Roach     * @return array<int,string>
74323788f4SGreg Roach     */
75*1ff45046SGreg Roach    public function newChildNames(Individual|null $father, Individual|null $mother, string $sex): array
76c1010edaSGreg Roach    {
77ef475b14SGreg Roach        if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father) === 1) {
78323788f4SGreg Roach            $father_surname = $match_father['SURN1'];
79323788f4SGreg Roach        } else {
80323788f4SGreg Roach            $father_surname = '';
81323788f4SGreg Roach        }
82323788f4SGreg Roach
83ef475b14SGreg Roach        if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother) === 1) {
84323788f4SGreg Roach            $mother_surname = $match_mother['SURN1'];
85323788f4SGreg Roach        } else {
86323788f4SGreg Roach            $mother_surname = '';
87323788f4SGreg Roach        }
88323788f4SGreg Roach
8913abd6f3SGreg Roach        return [
90cb7a42eaSGreg Roach            $this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [
9188a03560SGreg Roach                'TYPE' => NameType::VALUE_BIRTH,
92323788f4SGreg Roach                'SURN' => trim($father_surname . ',' . $mother_surname, ','),
93cb7a42eaSGreg Roach            ]),
9413abd6f3SGreg Roach        ];
95323788f4SGreg Roach    }
96323788f4SGreg Roach
97323788f4SGreg Roach    /**
98cb7a42eaSGreg Roach     * What name is given to a new parent
99323788f4SGreg Roach     *
100cb7a42eaSGreg Roach     * @param Individual $child
101cb7a42eaSGreg Roach     * @param string     $sex
102323788f4SGreg Roach     *
10301ffdfd0SGreg Roach     * @return array<int,string>
104323788f4SGreg Roach     */
105cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
106c1010edaSGreg Roach    {
107ef475b14SGreg Roach        if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match) === 1) {
108cb7a42eaSGreg Roach            switch ($sex) {
109323788f4SGreg Roach                case 'M':
11013abd6f3SGreg Roach                    return [
111cb7a42eaSGreg Roach                        $this->buildName('/' . $match['SURN1'] . '/ //', [
11288a03560SGreg Roach                            'TYPE' => NameType::VALUE_BIRTH,
113323788f4SGreg Roach                            'SURN' => $match['SURN1'],
114cb7a42eaSGreg Roach                        ]),
11513abd6f3SGreg Roach                    ];
116cb7a42eaSGreg Roach
117323788f4SGreg Roach                case 'F':
11813abd6f3SGreg Roach                    return [
119cb7a42eaSGreg Roach                        $this->buildName('/' . $match['SURN2'] . '/ //', [
12088a03560SGreg Roach                            'TYPE' => NameType::VALUE_BIRTH,
121323788f4SGreg Roach                            'SURN' => $match['SURN2'],
122cb7a42eaSGreg Roach                        ]),
12313abd6f3SGreg Roach                    ];
124323788f4SGreg Roach            }
125323788f4SGreg Roach        }
126323788f4SGreg Roach
12713abd6f3SGreg Roach        return [
12888a03560SGreg Roach            $this->buildName('// //', ['TYPE' => NameType::VALUE_BIRTH]),
12913abd6f3SGreg Roach        ];
130323788f4SGreg Roach    }
131323788f4SGreg Roach
132323788f4SGreg Roach    /**
133323788f4SGreg Roach     * What names are given to a new spouse
134323788f4SGreg Roach     *
135cb7a42eaSGreg Roach     * @param Individual $spouse
136cb7a42eaSGreg Roach     * @param string     $sex
137323788f4SGreg Roach     *
13801ffdfd0SGreg Roach     * @return array<int,string>
139323788f4SGreg Roach     */
140cb7a42eaSGreg Roach    public function newSpouseNames(Individual $spouse, string $sex): array
141c1010edaSGreg Roach    {
14213abd6f3SGreg Roach        return [
14388a03560SGreg Roach            $this->buildName('// //', ['TYPE' => NameType::VALUE_BIRTH]),
14413abd6f3SGreg Roach        ];
145323788f4SGreg Roach    }
146323788f4SGreg Roach}
147