xref: /webtrees/app/Family.php (revision 8fb4e87c164dd1c819d686ab0ce9556a2afb03f7)
1a25f0a04SGreg Roach<?php
23976b470SGreg Roach
3a25f0a04SGreg Roach/**
4a25f0a04SGreg Roach * webtrees: online genealogy
56b9cb339SGreg Roach * Copyright (C) 2020 webtrees development team
6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify
7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by
8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9a25f0a04SGreg Roach * (at your option) any later version.
10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful,
11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13a25f0a04SGreg Roach * GNU General Public License for more details.
14a25f0a04SGreg Roach * You should have received a copy of the GNU General Public License
15a25f0a04SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16a25f0a04SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees;
21a25f0a04SGreg Roach
22886b77daSGreg Roachuse Closure;
23d7daee59SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage;
24820b62dfSGreg Roachuse Illuminate\Support\Collection;
252e5b4452SGreg Roach
26a25f0a04SGreg Roach/**
2776692c8bSGreg Roach * A GEDCOM family (FAM) object.
28a25f0a04SGreg Roach */
29c1010edaSGreg Roachclass Family extends GedcomRecord
30c1010edaSGreg Roach{
3116d6367aSGreg Roach    public const RECORD_TYPE = 'FAM';
3216d6367aSGreg Roach
33d7daee59SGreg Roach    protected const ROUTE_NAME = FamilyPage::class;
34a25f0a04SGreg Roach
35a25f0a04SGreg Roach    /** @var Individual|null The husband (or first spouse for same-sex couples) */
36a25f0a04SGreg Roach    private $husb;
37a25f0a04SGreg Roach
38a25f0a04SGreg Roach    /** @var Individual|null The wife (or second spouse for same-sex couples) */
39a25f0a04SGreg Roach    private $wife;
40a25f0a04SGreg Roach
4176692c8bSGreg Roach    /**
4276692c8bSGreg Roach     * Create a GedcomRecord object from raw GEDCOM data.
4376692c8bSGreg Roach     *
4476692c8bSGreg Roach     * @param string      $xref
4576692c8bSGreg Roach     * @param string      $gedcom  an empty string for new/pending records
4676692c8bSGreg Roach     * @param string|null $pending null for a record with no pending edits,
4776692c8bSGreg Roach     *                             empty string for records with pending deletions
4876692c8bSGreg Roach     * @param Tree        $tree
4976692c8bSGreg Roach     */
50e364afe4SGreg Roach    public function __construct(string $xref, string $gedcom, ?string $pending, Tree $tree)
51c1010edaSGreg Roach    {
5224ec66ceSGreg Roach        parent::__construct($xref, $gedcom, $pending, $tree);
53a25f0a04SGreg Roach
5414239cc9SGreg Roach        // Make sure we find records in pending records.
5514239cc9SGreg Roach        $gedcom_pending = $gedcom . "\n" . $pending;
5614239cc9SGreg Roach
5714239cc9SGreg Roach        if (preg_match('/\n1 HUSB @(.+)@/', $gedcom_pending, $match)) {
586b9cb339SGreg Roach            $this->husb = Registry::individualFactory()->make($match[1], $tree);
59a25f0a04SGreg Roach        }
6014239cc9SGreg Roach        if (preg_match('/\n1 WIFE @(.+)@/', $gedcom_pending, $match)) {
616b9cb339SGreg Roach            $this->wife = Registry::individualFactory()->make($match[1], $tree);
62a25f0a04SGreg Roach        }
63a25f0a04SGreg Roach    }
64a25f0a04SGreg Roach
6576692c8bSGreg Roach    /**
66886b77daSGreg Roach     * A closure which will create a record from a database row.
67886b77daSGreg Roach     *
68bb03c9f0SGreg Roach     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::family()
69bb03c9f0SGreg Roach     *
70d5ad3db0SGreg Roach     * @param Tree $tree
71d5ad3db0SGreg Roach     *
72886b77daSGreg Roach     * @return Closure
73886b77daSGreg Roach     */
74d5ad3db0SGreg Roach    public static function rowMapper(Tree $tree): Closure
75886b77daSGreg Roach    {
766b9cb339SGreg Roach        return Registry::familyFactory()->mapper($tree);
77886b77daSGreg Roach    }
78886b77daSGreg Roach
79886b77daSGreg Roach    /**
80c156e8f5SGreg Roach     * A closure which will compare families by marriage date.
81c156e8f5SGreg Roach     *
82c156e8f5SGreg Roach     * @return Closure
83c156e8f5SGreg Roach     */
84c156e8f5SGreg Roach    public static function marriageDateComparator(): Closure
85c156e8f5SGreg Roach    {
866c2179e2SGreg Roach        return static function (Family $x, Family $y): int {
87c156e8f5SGreg Roach            return Date::compare($x->getMarriageDate(), $y->getMarriageDate());
88c156e8f5SGreg Roach        };
89c156e8f5SGreg Roach    }
90c156e8f5SGreg Roach
91c156e8f5SGreg Roach    /**
92e71ef9d2SGreg Roach     * Get an instance of a family object. For single records,
93e71ef9d2SGreg Roach     * we just receive the XREF. For bulk records (such as lists
94e71ef9d2SGreg Roach     * and search results) we can receive the GEDCOM data as well.
95e71ef9d2SGreg Roach     *
96bb03c9f0SGreg Roach     * @deprecated since 2.0.4.  Will be removed in 2.1.0 - Use Factory::family()
97bb03c9f0SGreg Roach     *
98e71ef9d2SGreg Roach     * @param string      $xref
99e71ef9d2SGreg Roach     * @param Tree        $tree
100e71ef9d2SGreg Roach     * @param string|null $gedcom
101e71ef9d2SGreg Roach     *
102e71ef9d2SGreg Roach     * @return Family|null
103e71ef9d2SGreg Roach     */
104ffc0a61fSGreg Roach    public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?Family
105c1010edaSGreg Roach    {
1066b9cb339SGreg Roach        return Registry::familyFactory()->make($xref, $tree, $gedcom);
107e71ef9d2SGreg Roach    }
108e71ef9d2SGreg Roach
109e71ef9d2SGreg Roach    /**
11076692c8bSGreg Roach     * Generate a private version of this record
11176692c8bSGreg Roach     *
11276692c8bSGreg Roach     * @param int $access_level
11376692c8bSGreg Roach     *
11476692c8bSGreg Roach     * @return string
11576692c8bSGreg Roach     */
1163c90ed31SGreg Roach    protected function createPrivateGedcomRecord(int $access_level): string
117c1010edaSGreg Roach    {
118d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
119d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
120d9e083e7SGreg Roach        }
121a25f0a04SGreg Roach
122a25f0a04SGreg Roach        $rec = '0 @' . $this->xref . '@ FAM';
123a25f0a04SGreg Roach        // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data
1248d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER);
125a25f0a04SGreg Roach        foreach ($matches as $match) {
1266b9cb339SGreg Roach            $rela = Registry::individualFactory()->make($match[1], $this->tree);
127d9e083e7SGreg Roach            if ($rela instanceof Individual && $rela->canShow($access_level)) {
128a25f0a04SGreg Roach                $rec .= $match[0];
129a25f0a04SGreg Roach            }
130a25f0a04SGreg Roach        }
131a25f0a04SGreg Roach
132a25f0a04SGreg Roach        return $rec;
133a25f0a04SGreg Roach    }
134a25f0a04SGreg Roach
13576692c8bSGreg Roach    /**
136a25f0a04SGreg Roach     * Get the male (or first female) partner of the family
137a25f0a04SGreg Roach     *
138e93111adSRico Sonntag     * @param int|null $access_level
139b3f49e6cSGreg Roach     *
140a25f0a04SGreg Roach     * @return Individual|null
141a25f0a04SGreg Roach     */
14239ca88baSGreg Roach    public function husband($access_level = null): ?Individual
143c1010edaSGreg Roach    {
144d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
145d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
146d9e083e7SGreg Roach        }
147b3f49e6cSGreg Roach
148d9e083e7SGreg Roach        if ($this->husb instanceof Individual && $this->husb->canShowName($access_level)) {
149a25f0a04SGreg Roach            return $this->husb;
150a25f0a04SGreg Roach        }
151b2ce94c6SRico Sonntag
152b2ce94c6SRico Sonntag        return null;
153a25f0a04SGreg Roach    }
154a25f0a04SGreg Roach
155a25f0a04SGreg Roach    /**
156a25f0a04SGreg Roach     * Get the female (or second male) partner of the family
157a25f0a04SGreg Roach     *
158e93111adSRico Sonntag     * @param int|null $access_level
159b3f49e6cSGreg Roach     *
160a25f0a04SGreg Roach     * @return Individual|null
161a25f0a04SGreg Roach     */
16239ca88baSGreg Roach    public function wife($access_level = null): ?Individual
163c1010edaSGreg Roach    {
164d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
165d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
166d9e083e7SGreg Roach        }
167b3f49e6cSGreg Roach
168d9e083e7SGreg Roach        if ($this->wife instanceof Individual && $this->wife->canShowName($access_level)) {
169a25f0a04SGreg Roach            return $this->wife;
170a25f0a04SGreg Roach        }
171b2ce94c6SRico Sonntag
172b2ce94c6SRico Sonntag        return null;
173a25f0a04SGreg Roach    }
174a25f0a04SGreg Roach
17576692c8bSGreg Roach    /**
17676692c8bSGreg Roach     * Each object type may have its own special rules, and re-implement this function.
17776692c8bSGreg Roach     *
17876692c8bSGreg Roach     * @param int $access_level
17976692c8bSGreg Roach     *
18076692c8bSGreg Roach     * @return bool
18176692c8bSGreg Roach     */
18235584196SGreg Roach    protected function canShowByType(int $access_level): bool
183c1010edaSGreg Roach    {
184a25f0a04SGreg Roach        // Hide a family if any member is private
1858d0ebef0SGreg Roach        preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches);
186a25f0a04SGreg Roach        foreach ($matches[1] as $match) {
1876b9cb339SGreg Roach            $person = Registry::individualFactory()->make($match, $this->tree);
188a25f0a04SGreg Roach            if ($person && !$person->canShow($access_level)) {
189a25f0a04SGreg Roach                return false;
190a25f0a04SGreg Roach            }
191a25f0a04SGreg Roach        }
192a25f0a04SGreg Roach
193a25f0a04SGreg Roach        return true;
194a25f0a04SGreg Roach    }
195a25f0a04SGreg Roach
19676692c8bSGreg Roach    /**
19776692c8bSGreg Roach     * Can the name of this record be shown?
19876692c8bSGreg Roach     *
19976692c8bSGreg Roach     * @param int|null $access_level
20076692c8bSGreg Roach     *
20176692c8bSGreg Roach     * @return bool
20276692c8bSGreg Roach     */
20335584196SGreg Roach    public function canShowName(int $access_level = null): bool
204c1010edaSGreg Roach    {
205a25f0a04SGreg Roach        // We can always see the name (Husband-name + Wife-name), however,
206a25f0a04SGreg Roach        // the name will often be "private + private"
207a25f0a04SGreg Roach        return true;
208a25f0a04SGreg Roach    }
209a25f0a04SGreg Roach
210a25f0a04SGreg Roach    /**
211a25f0a04SGreg Roach     * Find the spouse of a person.
212a25f0a04SGreg Roach     *
213a25f0a04SGreg Roach     * @param Individual $person
21413e3123bSGreg Roach     * @param int|null   $access_level
215a25f0a04SGreg Roach     *
216a25f0a04SGreg Roach     * @return Individual|null
217a25f0a04SGreg Roach     */
218e364afe4SGreg Roach    public function spouse(Individual $person, $access_level = null): ?Individual
219c1010edaSGreg Roach    {
220a25f0a04SGreg Roach        if ($person === $this->wife) {
22139ca88baSGreg Roach            return $this->husband($access_level);
222a25f0a04SGreg Roach        }
223b2ce94c6SRico Sonntag
22439ca88baSGreg Roach        return $this->wife($access_level);
225a25f0a04SGreg Roach    }
226a25f0a04SGreg Roach
227a25f0a04SGreg Roach    /**
228a25f0a04SGreg Roach     * Get the (zero, one or two) spouses from this family.
229a25f0a04SGreg Roach     *
230cbc1590aSGreg Roach     * @param int|null $access_level
231a25f0a04SGreg Roach     *
232b5c8fd7eSGreg Roach     * @return Collection<Individual>
233a25f0a04SGreg Roach     */
234820b62dfSGreg Roach    public function spouses($access_level = null): Collection
235c1010edaSGreg Roach    {
236820b62dfSGreg Roach        $spouses = new Collection([
23739ca88baSGreg Roach            $this->husband($access_level),
23839ca88baSGreg Roach            $this->wife($access_level),
23913abd6f3SGreg Roach        ]);
240820b62dfSGreg Roach
241820b62dfSGreg Roach        return $spouses->filter();
242a25f0a04SGreg Roach    }
243a25f0a04SGreg Roach
244a25f0a04SGreg Roach    /**
245a25f0a04SGreg Roach     * Get a list of this family’s children.
246a25f0a04SGreg Roach     *
247cbc1590aSGreg Roach     * @param int|null $access_level
248a25f0a04SGreg Roach     *
249b5c8fd7eSGreg Roach     * @return Collection<Individual>
250a25f0a04SGreg Roach     */
251820b62dfSGreg Roach    public function children($access_level = null): Collection
252c1010edaSGreg Roach    {
253d9e083e7SGreg Roach        $access_level = $access_level ?? Auth::accessLevel($this->tree);
2544b9ff166SGreg Roach
255d9e083e7SGreg Roach        if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
256d9e083e7SGreg Roach            $access_level = Auth::PRIV_HIDE;
257d9e083e7SGreg Roach        }
258a25f0a04SGreg Roach
259820b62dfSGreg Roach        $children = new Collection();
260820b62dfSGreg Roach
261d9e083e7SGreg Roach        foreach ($this->facts(['CHIL'], false, $access_level) as $fact) {
262dc124885SGreg Roach            $child = $fact->target();
263820b62dfSGreg Roach
264d9e083e7SGreg Roach            if ($child instanceof Individual && $child->canShowName($access_level)) {
265820b62dfSGreg Roach                $children->push($child);
266a25f0a04SGreg Roach            }
267a25f0a04SGreg Roach        }
268a25f0a04SGreg Roach
269a25f0a04SGreg Roach        return $children;
270a25f0a04SGreg Roach    }
271a25f0a04SGreg Roach
272a25f0a04SGreg Roach    /**
273a25f0a04SGreg Roach     * Number of children - for the individual list
274a25f0a04SGreg Roach     *
275cbc1590aSGreg Roach     * @return int
276a25f0a04SGreg Roach     */
27739ca88baSGreg Roach    public function numberOfChildren(): int
278c1010edaSGreg Roach    {
279820b62dfSGreg Roach        $nchi = $this->children()->count();
280820b62dfSGreg Roach
2818d0ebef0SGreg Roach        foreach ($this->facts(['NCHI']) as $fact) {
28284586c02SGreg Roach            $nchi = max($nchi, (int) $fact->value());
283a25f0a04SGreg Roach        }
284a25f0a04SGreg Roach
285a25f0a04SGreg Roach        return $nchi;
286a25f0a04SGreg Roach    }
287a25f0a04SGreg Roach
288a25f0a04SGreg Roach    /**
289a25f0a04SGreg Roach     * get the marriage event
290a25f0a04SGreg Roach     *
29166107289SGreg Roach     * @return Fact|null
292a25f0a04SGreg Roach     */
293820b62dfSGreg Roach    public function getMarriage(): ?Fact
294c1010edaSGreg Roach    {
295820b62dfSGreg Roach        return $this->facts(['MARR'])->first();
296a25f0a04SGreg Roach    }
297a25f0a04SGreg Roach
298a25f0a04SGreg Roach    /**
299a25f0a04SGreg Roach     * Get marriage date
300a25f0a04SGreg Roach     *
301a25f0a04SGreg Roach     * @return Date
302a25f0a04SGreg Roach     */
303820b62dfSGreg Roach    public function getMarriageDate(): Date
304c1010edaSGreg Roach    {
305a25f0a04SGreg Roach        $marriage = $this->getMarriage();
306a25f0a04SGreg Roach        if ($marriage) {
3072decada7SGreg Roach            return $marriage->date();
308a25f0a04SGreg Roach        }
309b2ce94c6SRico Sonntag
310b2ce94c6SRico Sonntag        return new Date('');
311a25f0a04SGreg Roach    }
312a25f0a04SGreg Roach
313a25f0a04SGreg Roach    /**
314a25f0a04SGreg Roach     * Get the marriage year - displayed on lists of families
315a25f0a04SGreg Roach     *
316cbc1590aSGreg Roach     * @return int
317a25f0a04SGreg Roach     */
3188f53f488SRico Sonntag    public function getMarriageYear(): int
319c1010edaSGreg Roach    {
3204a83f5d7SGreg Roach        return $this->getMarriageDate()->minimumDate()->year;
321a25f0a04SGreg Roach    }
322a25f0a04SGreg Roach
323a25f0a04SGreg Roach    /**
324a25f0a04SGreg Roach     * Get the marriage place
325a25f0a04SGreg Roach     *
326a25f0a04SGreg Roach     * @return Place
327a25f0a04SGreg Roach     */
3288f53f488SRico Sonntag    public function getMarriagePlace(): Place
329c1010edaSGreg Roach    {
330a25f0a04SGreg Roach        $marriage = $this->getMarriage();
331a25f0a04SGreg Roach
3327abafad0SGreg Roach        if ($marriage instanceof Fact) {
3334fb14fcbSGreg Roach            return $marriage->place();
334a25f0a04SGreg Roach        }
335a25f0a04SGreg Roach
3367abafad0SGreg Roach        return new Place('', $this->tree);
3377abafad0SGreg Roach    }
3387abafad0SGreg Roach
339a25f0a04SGreg Roach    /**
340a25f0a04SGreg Roach     * Get a list of all marriage dates - for the family lists.
341a25f0a04SGreg Roach     *
342a25f0a04SGreg Roach     * @return Date[]
343a25f0a04SGreg Roach     */
3448f53f488SRico Sonntag    public function getAllMarriageDates(): array
345c1010edaSGreg Roach    {
3468d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3477abafad0SGreg Roach            $array = $this->getAllEventDates([$event]);
3488af3e5c1SGreg Roach
34954c1ab5eSGreg Roach            if ($array !== []) {
350a25f0a04SGreg Roach                return $array;
351a25f0a04SGreg Roach            }
352a25f0a04SGreg Roach        }
353a25f0a04SGreg Roach
35413abd6f3SGreg Roach        return [];
355a25f0a04SGreg Roach    }
356a25f0a04SGreg Roach
357a25f0a04SGreg Roach    /**
358a25f0a04SGreg Roach     * Get a list of all marriage places - for the family lists.
359a25f0a04SGreg Roach     *
3604080d558SGreg Roach     * @return Place[]
361a25f0a04SGreg Roach     */
3628f53f488SRico Sonntag    public function getAllMarriagePlaces(): array
363c1010edaSGreg Roach    {
3648d0ebef0SGreg Roach        foreach (Gedcom::MARRIAGE_EVENTS as $event) {
3656e83554dSGreg Roach            $places = $this->getAllEventPlaces([$event]);
36654c1ab5eSGreg Roach            if ($places !== []) {
3674080d558SGreg Roach                return $places;
368a25f0a04SGreg Roach            }
369a25f0a04SGreg Roach        }
370a25f0a04SGreg Roach
37113abd6f3SGreg Roach        return [];
372a25f0a04SGreg Roach    }
373a25f0a04SGreg Roach
37476692c8bSGreg Roach    /**
37576692c8bSGreg Roach     * Derived classes should redefine this function, otherwise the object will have no name
37676692c8bSGreg Roach     *
37776692c8bSGreg Roach     * @return string[][]
37876692c8bSGreg Roach     */
3798f53f488SRico Sonntag    public function getAllNames(): array
380c1010edaSGreg Roach    {
3818f038c36SRico Sonntag        if ($this->getAllNames === null) {
382a25f0a04SGreg Roach            // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc.
383e88674d4SGreg Roach            $husb_names = [];
384a25f0a04SGreg Roach            if ($this->husb) {
3850b5fd0a6SGreg Roach                $husb_names = array_filter($this->husb->getAllNames(), static function (array $x): bool {
3868d68cabeSGreg Roach                    return $x['type'] !== '_MARNM';
3878d68cabeSGreg Roach                });
388e88674d4SGreg Roach            }
3891f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
39054c1ab5eSGreg Roach            if ($husb_names === []) {
391e88674d4SGreg Roach                $husb_names[] = [
392a25f0a04SGreg Roach                    'type' => 'BIRT',
393*8fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
394ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
39513abd6f3SGreg Roach                ];
396a25f0a04SGreg Roach            }
397a25f0a04SGreg Roach            foreach ($husb_names as $n => $husb_name) {
398a25f0a04SGreg Roach                $husb_names[$n]['script'] = I18N::textScript($husb_name['full']);
399a25f0a04SGreg Roach            }
400e88674d4SGreg Roach
401e88674d4SGreg Roach            $wife_names = [];
402a25f0a04SGreg Roach            if ($this->wife) {
4030b5fd0a6SGreg Roach                $wife_names = array_filter($this->wife->getAllNames(), static function (array $x): bool {
4048d68cabeSGreg Roach                    return $x['type'] !== '_MARNM';
4058d68cabeSGreg Roach                });
406e88674d4SGreg Roach            }
4071f244d77SGreg Roach            // If the individual only has married names, create a fake birth name.
40854c1ab5eSGreg Roach            if ($wife_names === []) {
409e88674d4SGreg Roach                $wife_names[] = [
410a25f0a04SGreg Roach                    'type' => 'BIRT',
411*8fb4e87cSGreg Roach                    'sort' => Individual::NOMEN_NESCIO,
412ad1a1cd2SGreg Roach                    'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'),
41313abd6f3SGreg Roach                ];
414a25f0a04SGreg Roach            }
415a25f0a04SGreg Roach            foreach ($wife_names as $n => $wife_name) {
416a25f0a04SGreg Roach                $wife_names[$n]['script'] = I18N::textScript($wife_name['full']);
417a25f0a04SGreg Roach            }
418e88674d4SGreg Roach
419a25f0a04SGreg Roach            // Add the matched names first
420a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
421a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
422e364afe4SGreg Roach                    if ($husb_name['script'] === $wife_name['script']) {
423bdb3725aSGreg Roach                        $this->getAllNames[] = [
424a25f0a04SGreg Roach                            'type' => $husb_name['type'],
425a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
426a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
427a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
42813abd6f3SGreg Roach                        ];
429a25f0a04SGreg Roach                    }
430a25f0a04SGreg Roach                }
431a25f0a04SGreg Roach            }
432e88674d4SGreg Roach
433a25f0a04SGreg Roach            // Add the unmatched names second (there may be no matched names)
434a25f0a04SGreg Roach            foreach ($husb_names as $husb_name) {
435a25f0a04SGreg Roach                foreach ($wife_names as $wife_name) {
436e364afe4SGreg Roach                    if ($husb_name['script'] !== $wife_name['script']) {
437bdb3725aSGreg Roach                        $this->getAllNames[] = [
438a25f0a04SGreg Roach                            'type' => $husb_name['type'],
439a25f0a04SGreg Roach                            'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'],
440a25f0a04SGreg Roach                            'full' => $husb_name['full'] . ' + ' . $wife_name['full'],
441a25f0a04SGreg Roach                            // No need for a fullNN entry - we do not currently store FAM names in the database
44213abd6f3SGreg Roach                        ];
443a25f0a04SGreg Roach                    }
444a25f0a04SGreg Roach                }
445a25f0a04SGreg Roach            }
446a25f0a04SGreg Roach        }
447a25f0a04SGreg Roach
448bdb3725aSGreg Roach        return $this->getAllNames;
449a25f0a04SGreg Roach    }
450a25f0a04SGreg Roach
45176692c8bSGreg Roach    /**
45276692c8bSGreg Roach     * This function should be redefined in derived classes to show any major
45376692c8bSGreg Roach     * identifying characteristics of this record.
45476692c8bSGreg Roach     *
45576692c8bSGreg Roach     * @return string
45676692c8bSGreg Roach     */
4578f53f488SRico Sonntag    public function formatListDetails(): string
458c1010edaSGreg Roach    {
459a25f0a04SGreg Roach        return
4608d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) .
4618d0ebef0SGreg Roach            $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1);
462a25f0a04SGreg Roach    }
463a25f0a04SGreg Roach}
464