1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 58fcd0d32SGreg Roach * Copyright (C) 2019 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; 236ccdf4f0SGreg Roachuse Exception; 24*d7daee59SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage; 252e5b4452SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 26820b62dfSGreg Roachuse Illuminate\Support\Collection; 27886b77daSGreg Roachuse stdClass; 282e5b4452SGreg Roach 29a25f0a04SGreg Roach/** 3076692c8bSGreg Roach * A GEDCOM family (FAM) object. 31a25f0a04SGreg Roach */ 32c1010edaSGreg Roachclass Family extends GedcomRecord 33c1010edaSGreg Roach{ 3416d6367aSGreg Roach public const RECORD_TYPE = 'FAM'; 3516d6367aSGreg Roach 36*d7daee59SGreg Roach protected const ROUTE_NAME = FamilyPage::class; 37a25f0a04SGreg Roach 38a25f0a04SGreg Roach /** @var Individual|null The husband (or first spouse for same-sex couples) */ 39a25f0a04SGreg Roach private $husb; 40a25f0a04SGreg Roach 41a25f0a04SGreg Roach /** @var Individual|null The wife (or second spouse for same-sex couples) */ 42a25f0a04SGreg Roach private $wife; 43a25f0a04SGreg Roach 4476692c8bSGreg Roach /** 4576692c8bSGreg Roach * Create a GedcomRecord object from raw GEDCOM data. 4676692c8bSGreg Roach * 4776692c8bSGreg Roach * @param string $xref 4876692c8bSGreg Roach * @param string $gedcom an empty string for new/pending records 4976692c8bSGreg Roach * @param string|null $pending null for a record with no pending edits, 5076692c8bSGreg Roach * empty string for records with pending deletions 5176692c8bSGreg Roach * @param Tree $tree 5276692c8bSGreg Roach */ 53e364afe4SGreg Roach public function __construct(string $xref, string $gedcom, ?string $pending, Tree $tree) 54c1010edaSGreg Roach { 5524ec66ceSGreg Roach parent::__construct($xref, $gedcom, $pending, $tree); 56a25f0a04SGreg Roach 57395f0fe0SGreg Roach // Fetch family members 58395f0fe0SGreg Roach if (preg_match_all('/^1 (?:HUSB|WIFE|CHIL) @(.+)@/m', $gedcom . $pending, $match)) { 59395f0fe0SGreg Roach Individual::load($tree, $match[1]); 60395f0fe0SGreg Roach } 61395f0fe0SGreg Roach 62a25f0a04SGreg Roach if (preg_match('/^1 HUSB @(.+)@/m', $gedcom . $pending, $match)) { 6324ec66ceSGreg Roach $this->husb = Individual::getInstance($match[1], $tree); 64a25f0a04SGreg Roach } 65a25f0a04SGreg Roach if (preg_match('/^1 WIFE @(.+)@/m', $gedcom . $pending, $match)) { 6624ec66ceSGreg Roach $this->wife = Individual::getInstance($match[1], $tree); 67a25f0a04SGreg Roach } 68a25f0a04SGreg Roach } 69a25f0a04SGreg Roach 7076692c8bSGreg Roach /** 71886b77daSGreg Roach * A closure which will create a record from a database row. 72886b77daSGreg Roach * 73886b77daSGreg Roach * @return Closure 74886b77daSGreg Roach */ 75c0804649SGreg Roach public static function rowMapper(): Closure 76886b77daSGreg Roach { 776c2179e2SGreg Roach return static function (stdClass $row): Family { 78a7a24840SGreg Roach return Family::getInstance($row->f_id, Tree::findById((int) $row->f_file), $row->f_gedcom); 79886b77daSGreg Roach }; 80886b77daSGreg Roach } 81886b77daSGreg Roach 82886b77daSGreg Roach /** 83c156e8f5SGreg Roach * A closure which will compare families by marriage date. 84c156e8f5SGreg Roach * 85c156e8f5SGreg Roach * @return Closure 86c156e8f5SGreg Roach */ 87c156e8f5SGreg Roach public static function marriageDateComparator(): Closure 88c156e8f5SGreg Roach { 896c2179e2SGreg Roach return static function (Family $x, Family $y): int { 90c156e8f5SGreg Roach return Date::compare($x->getMarriageDate(), $y->getMarriageDate()); 91c156e8f5SGreg Roach }; 92c156e8f5SGreg Roach } 93c156e8f5SGreg Roach 94c156e8f5SGreg Roach /** 95e71ef9d2SGreg Roach * Get an instance of a family object. For single records, 96e71ef9d2SGreg Roach * we just receive the XREF. For bulk records (such as lists 97e71ef9d2SGreg Roach * and search results) we can receive the GEDCOM data as well. 98e71ef9d2SGreg Roach * 99e71ef9d2SGreg Roach * @param string $xref 100e71ef9d2SGreg Roach * @param Tree $tree 101e71ef9d2SGreg Roach * @param string|null $gedcom 102e71ef9d2SGreg Roach * 1036ccdf4f0SGreg Roach * @throws Exception 104e71ef9d2SGreg Roach * 105e71ef9d2SGreg Roach * @return Family|null 106e71ef9d2SGreg Roach */ 107e364afe4SGreg Roach public static function getInstance(string $xref, Tree $tree, string $gedcom = null): ?self 108c1010edaSGreg Roach { 109e71ef9d2SGreg Roach $record = parent::getInstance($xref, $tree, $gedcom); 110e71ef9d2SGreg Roach 111e364afe4SGreg Roach if ($record instanceof self) { 112e71ef9d2SGreg Roach return $record; 113e71ef9d2SGreg Roach } 114b2ce94c6SRico Sonntag 115b2ce94c6SRico Sonntag return null; 116e71ef9d2SGreg Roach } 117e71ef9d2SGreg Roach 118e71ef9d2SGreg Roach /** 11976692c8bSGreg Roach * Generate a private version of this record 12076692c8bSGreg Roach * 12176692c8bSGreg Roach * @param int $access_level 12276692c8bSGreg Roach * 12376692c8bSGreg Roach * @return string 12476692c8bSGreg Roach */ 1253c90ed31SGreg Roach protected function createPrivateGedcomRecord(int $access_level): string 126c1010edaSGreg Roach { 127d86cc606SGreg Roach $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS'); 128a25f0a04SGreg Roach 129a25f0a04SGreg Roach $rec = '0 @' . $this->xref . '@ FAM'; 130a25f0a04SGreg Roach // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data 1318d0ebef0SGreg Roach preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER); 132a25f0a04SGreg Roach foreach ($matches as $match) { 13324ec66ceSGreg Roach $rela = Individual::getInstance($match[1], $this->tree); 134a25f0a04SGreg Roach if ($rela && ($SHOW_PRIVATE_RELATIONSHIPS || $rela->canShow($access_level))) { 135a25f0a04SGreg Roach $rec .= $match[0]; 136a25f0a04SGreg Roach } 137a25f0a04SGreg Roach } 138a25f0a04SGreg Roach 139a25f0a04SGreg Roach return $rec; 140a25f0a04SGreg Roach } 141a25f0a04SGreg Roach 14276692c8bSGreg Roach /** 14376692c8bSGreg Roach * Fetch data from the database 14476692c8bSGreg Roach * 14576692c8bSGreg Roach * @param string $xref 14676692c8bSGreg Roach * @param int $tree_id 14776692c8bSGreg Roach * 148e364afe4SGreg Roach * @return string|null 14976692c8bSGreg Roach */ 150e364afe4SGreg Roach protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string 151c1010edaSGreg Roach { 1522e5b4452SGreg Roach return DB::table('families') 1532e5b4452SGreg Roach ->where('f_id', '=', $xref) 1542e5b4452SGreg Roach ->where('f_file', '=', $tree_id) 1552e5b4452SGreg Roach ->value('f_gedcom'); 156a25f0a04SGreg Roach } 157a25f0a04SGreg Roach 158a25f0a04SGreg Roach /** 159a25f0a04SGreg Roach * Get the male (or first female) partner of the family 160a25f0a04SGreg Roach * 161e93111adSRico Sonntag * @param int|null $access_level 162b3f49e6cSGreg Roach * 163a25f0a04SGreg Roach * @return Individual|null 164a25f0a04SGreg Roach */ 16539ca88baSGreg Roach public function husband($access_level = null): ?Individual 166c1010edaSGreg Roach { 167b3f49e6cSGreg Roach $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS'); 168b3f49e6cSGreg Roach 169b3f49e6cSGreg Roach if ($this->husb && ($SHOW_PRIVATE_RELATIONSHIPS || $this->husb->canShowName($access_level))) { 170a25f0a04SGreg Roach return $this->husb; 171a25f0a04SGreg Roach } 172b2ce94c6SRico Sonntag 173b2ce94c6SRico Sonntag return null; 174a25f0a04SGreg Roach } 175a25f0a04SGreg Roach 176a25f0a04SGreg Roach /** 177a25f0a04SGreg Roach * Get the female (or second male) partner of the family 178a25f0a04SGreg Roach * 179e93111adSRico Sonntag * @param int|null $access_level 180b3f49e6cSGreg Roach * 181a25f0a04SGreg Roach * @return Individual|null 182a25f0a04SGreg Roach */ 18339ca88baSGreg Roach public function wife($access_level = null): ?Individual 184c1010edaSGreg Roach { 185b3f49e6cSGreg Roach $SHOW_PRIVATE_RELATIONSHIPS = $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS'); 186b3f49e6cSGreg Roach 187b3f49e6cSGreg Roach if ($this->wife && ($SHOW_PRIVATE_RELATIONSHIPS || $this->wife->canShowName($access_level))) { 188a25f0a04SGreg Roach return $this->wife; 189a25f0a04SGreg Roach } 190b2ce94c6SRico Sonntag 191b2ce94c6SRico Sonntag return null; 192a25f0a04SGreg Roach } 193a25f0a04SGreg Roach 19476692c8bSGreg Roach /** 19576692c8bSGreg Roach * Each object type may have its own special rules, and re-implement this function. 19676692c8bSGreg Roach * 19776692c8bSGreg Roach * @param int $access_level 19876692c8bSGreg Roach * 19976692c8bSGreg Roach * @return bool 20076692c8bSGreg Roach */ 20135584196SGreg Roach protected function canShowByType(int $access_level): bool 202c1010edaSGreg Roach { 203a25f0a04SGreg Roach // Hide a family if any member is private 2048d0ebef0SGreg Roach preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches); 205a25f0a04SGreg Roach foreach ($matches[1] as $match) { 20624ec66ceSGreg Roach $person = Individual::getInstance($match, $this->tree); 207a25f0a04SGreg Roach if ($person && !$person->canShow($access_level)) { 208a25f0a04SGreg Roach return false; 209a25f0a04SGreg Roach } 210a25f0a04SGreg Roach } 211a25f0a04SGreg Roach 212a25f0a04SGreg Roach return true; 213a25f0a04SGreg Roach } 214a25f0a04SGreg Roach 21576692c8bSGreg Roach /** 21676692c8bSGreg Roach * Can the name of this record be shown? 21776692c8bSGreg Roach * 21876692c8bSGreg Roach * @param int|null $access_level 21976692c8bSGreg Roach * 22076692c8bSGreg Roach * @return bool 22176692c8bSGreg Roach */ 22235584196SGreg Roach public function canShowName(int $access_level = null): bool 223c1010edaSGreg Roach { 224a25f0a04SGreg Roach // We can always see the name (Husband-name + Wife-name), however, 225a25f0a04SGreg Roach // the name will often be "private + private" 226a25f0a04SGreg Roach return true; 227a25f0a04SGreg Roach } 228a25f0a04SGreg Roach 229a25f0a04SGreg Roach /** 230a25f0a04SGreg Roach * Find the spouse of a person. 231a25f0a04SGreg Roach * 232a25f0a04SGreg Roach * @param Individual $person 23313e3123bSGreg Roach * @param int|null $access_level 234a25f0a04SGreg Roach * 235a25f0a04SGreg Roach * @return Individual|null 236a25f0a04SGreg Roach */ 237e364afe4SGreg Roach public function spouse(Individual $person, $access_level = null): ?Individual 238c1010edaSGreg Roach { 239a25f0a04SGreg Roach if ($person === $this->wife) { 24039ca88baSGreg Roach return $this->husband($access_level); 241a25f0a04SGreg Roach } 242b2ce94c6SRico Sonntag 24339ca88baSGreg Roach return $this->wife($access_level); 244a25f0a04SGreg Roach } 245a25f0a04SGreg Roach 246a25f0a04SGreg Roach /** 247a25f0a04SGreg Roach * Get the (zero, one or two) spouses from this family. 248a25f0a04SGreg Roach * 249cbc1590aSGreg Roach * @param int|null $access_level 250a25f0a04SGreg Roach * 25154c7f8dfSGreg Roach * @return Collection 252a25f0a04SGreg Roach */ 253820b62dfSGreg Roach public function spouses($access_level = null): Collection 254c1010edaSGreg Roach { 255820b62dfSGreg Roach $spouses = new Collection([ 25639ca88baSGreg Roach $this->husband($access_level), 25739ca88baSGreg Roach $this->wife($access_level), 25813abd6f3SGreg Roach ]); 259820b62dfSGreg Roach 260820b62dfSGreg Roach return $spouses->filter(); 261a25f0a04SGreg Roach } 262a25f0a04SGreg Roach 263a25f0a04SGreg Roach /** 264a25f0a04SGreg Roach * Get a list of this family’s children. 265a25f0a04SGreg Roach * 266cbc1590aSGreg Roach * @param int|null $access_level 267a25f0a04SGreg Roach * 26854c7f8dfSGreg Roach * @return Collection 269a25f0a04SGreg Roach */ 270820b62dfSGreg Roach public function children($access_level = null): Collection 271c1010edaSGreg Roach { 2724b9ff166SGreg Roach if ($access_level === null) { 2734b9ff166SGreg Roach $access_level = Auth::accessLevel($this->tree); 2744b9ff166SGreg Roach } 2754b9ff166SGreg Roach 276845c3ce6SGreg Roach $SHOW_PRIVATE_RELATIONSHIPS = (bool) $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS'); 277a25f0a04SGreg Roach 278820b62dfSGreg Roach $children = new Collection(); 279820b62dfSGreg Roach 2808d0ebef0SGreg Roach foreach ($this->facts(['CHIL'], false, $access_level, $SHOW_PRIVATE_RELATIONSHIPS) as $fact) { 281dc124885SGreg Roach $child = $fact->target(); 282820b62dfSGreg Roach 283e24444eeSGreg Roach if ($child instanceof Individual && ($SHOW_PRIVATE_RELATIONSHIPS || $child->canShowName($access_level))) { 284820b62dfSGreg Roach $children->push($child); 285a25f0a04SGreg Roach } 286a25f0a04SGreg Roach } 287a25f0a04SGreg Roach 288a25f0a04SGreg Roach return $children; 289a25f0a04SGreg Roach } 290a25f0a04SGreg Roach 291a25f0a04SGreg Roach /** 292a25f0a04SGreg Roach * Number of children - for the individual list 293a25f0a04SGreg Roach * 294cbc1590aSGreg Roach * @return int 295a25f0a04SGreg Roach */ 29639ca88baSGreg Roach public function numberOfChildren(): int 297c1010edaSGreg Roach { 298820b62dfSGreg Roach $nchi = $this->children()->count(); 299820b62dfSGreg Roach 3008d0ebef0SGreg Roach foreach ($this->facts(['NCHI']) as $fact) { 30184586c02SGreg Roach $nchi = max($nchi, (int) $fact->value()); 302a25f0a04SGreg Roach } 303a25f0a04SGreg Roach 304a25f0a04SGreg Roach return $nchi; 305a25f0a04SGreg Roach } 306a25f0a04SGreg Roach 307a25f0a04SGreg Roach /** 308a25f0a04SGreg Roach * get the marriage event 309a25f0a04SGreg Roach * 31066107289SGreg Roach * @return Fact|null 311a25f0a04SGreg Roach */ 312820b62dfSGreg Roach public function getMarriage(): ?Fact 313c1010edaSGreg Roach { 314820b62dfSGreg Roach return $this->facts(['MARR'])->first(); 315a25f0a04SGreg Roach } 316a25f0a04SGreg Roach 317a25f0a04SGreg Roach /** 318a25f0a04SGreg Roach * Get marriage date 319a25f0a04SGreg Roach * 320a25f0a04SGreg Roach * @return Date 321a25f0a04SGreg Roach */ 322820b62dfSGreg Roach public function getMarriageDate(): Date 323c1010edaSGreg Roach { 324a25f0a04SGreg Roach $marriage = $this->getMarriage(); 325a25f0a04SGreg Roach if ($marriage) { 3262decada7SGreg Roach return $marriage->date(); 327a25f0a04SGreg Roach } 328b2ce94c6SRico Sonntag 329b2ce94c6SRico Sonntag return new Date(''); 330a25f0a04SGreg Roach } 331a25f0a04SGreg Roach 332a25f0a04SGreg Roach /** 333a25f0a04SGreg Roach * Get the marriage year - displayed on lists of families 334a25f0a04SGreg Roach * 335cbc1590aSGreg Roach * @return int 336a25f0a04SGreg Roach */ 3378f53f488SRico Sonntag public function getMarriageYear(): int 338c1010edaSGreg Roach { 3394a83f5d7SGreg Roach return $this->getMarriageDate()->minimumDate()->year; 340a25f0a04SGreg Roach } 341a25f0a04SGreg Roach 342a25f0a04SGreg Roach /** 343a25f0a04SGreg Roach * Get the marriage place 344a25f0a04SGreg Roach * 345a25f0a04SGreg Roach * @return Place 346a25f0a04SGreg Roach */ 3478f53f488SRico Sonntag public function getMarriagePlace(): Place 348c1010edaSGreg Roach { 349a25f0a04SGreg Roach $marriage = $this->getMarriage(); 350a25f0a04SGreg Roach 3517abafad0SGreg Roach if ($marriage instanceof Fact) { 3524fb14fcbSGreg Roach return $marriage->place(); 353a25f0a04SGreg Roach } 354a25f0a04SGreg Roach 3557abafad0SGreg Roach return new Place('', $this->tree); 3567abafad0SGreg Roach } 3577abafad0SGreg Roach 358a25f0a04SGreg Roach /** 359a25f0a04SGreg Roach * Get a list of all marriage dates - for the family lists. 360a25f0a04SGreg Roach * 361a25f0a04SGreg Roach * @return Date[] 362a25f0a04SGreg Roach */ 3638f53f488SRico Sonntag public function getAllMarriageDates(): array 364c1010edaSGreg Roach { 3658d0ebef0SGreg Roach foreach (Gedcom::MARRIAGE_EVENTS as $event) { 3667abafad0SGreg Roach $array = $this->getAllEventDates([$event]); 3678af3e5c1SGreg Roach 36854c1ab5eSGreg Roach if ($array !== []) { 369a25f0a04SGreg Roach return $array; 370a25f0a04SGreg Roach } 371a25f0a04SGreg Roach } 372a25f0a04SGreg Roach 37313abd6f3SGreg Roach return []; 374a25f0a04SGreg Roach } 375a25f0a04SGreg Roach 376a25f0a04SGreg Roach /** 377a25f0a04SGreg Roach * Get a list of all marriage places - for the family lists. 378a25f0a04SGreg Roach * 3794080d558SGreg Roach * @return Place[] 380a25f0a04SGreg Roach */ 3818f53f488SRico Sonntag public function getAllMarriagePlaces(): array 382c1010edaSGreg Roach { 3838d0ebef0SGreg Roach foreach (Gedcom::MARRIAGE_EVENTS as $event) { 3846e83554dSGreg Roach $places = $this->getAllEventPlaces([$event]); 38554c1ab5eSGreg Roach if ($places !== []) { 3864080d558SGreg Roach return $places; 387a25f0a04SGreg Roach } 388a25f0a04SGreg Roach } 389a25f0a04SGreg Roach 39013abd6f3SGreg Roach return []; 391a25f0a04SGreg Roach } 392a25f0a04SGreg Roach 39376692c8bSGreg Roach /** 39476692c8bSGreg Roach * Derived classes should redefine this function, otherwise the object will have no name 39576692c8bSGreg Roach * 39676692c8bSGreg Roach * @return string[][] 39776692c8bSGreg Roach */ 3988f53f488SRico Sonntag public function getAllNames(): array 399c1010edaSGreg Roach { 4008f038c36SRico Sonntag if ($this->getAllNames === null) { 401a25f0a04SGreg Roach // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc. 402e88674d4SGreg Roach $husb_names = []; 403a25f0a04SGreg Roach if ($this->husb) { 4040b5fd0a6SGreg Roach $husb_names = array_filter($this->husb->getAllNames(), static function (array $x): bool { 4058d68cabeSGreg Roach return $x['type'] !== '_MARNM'; 4068d68cabeSGreg Roach }); 407e88674d4SGreg Roach } 408e88674d4SGreg Roach // If the individual only has married names, create a dummy birth name. 40954c1ab5eSGreg Roach if ($husb_names === []) { 410e88674d4SGreg Roach $husb_names[] = [ 411a25f0a04SGreg Roach 'type' => 'BIRT', 412a25f0a04SGreg Roach 'sort' => '@N.N.', 413ad1a1cd2SGreg Roach 'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'), 41413abd6f3SGreg Roach ]; 415a25f0a04SGreg Roach } 416a25f0a04SGreg Roach foreach ($husb_names as $n => $husb_name) { 417a25f0a04SGreg Roach $husb_names[$n]['script'] = I18N::textScript($husb_name['full']); 418a25f0a04SGreg Roach } 419e88674d4SGreg Roach 420e88674d4SGreg Roach $wife_names = []; 421a25f0a04SGreg Roach if ($this->wife) { 4220b5fd0a6SGreg Roach $wife_names = array_filter($this->wife->getAllNames(), static function (array $x): bool { 4238d68cabeSGreg Roach return $x['type'] !== '_MARNM'; 4248d68cabeSGreg Roach }); 425e88674d4SGreg Roach } 426e88674d4SGreg Roach // If the individual only has married names, create a dummy birth name. 42754c1ab5eSGreg Roach if ($wife_names === []) { 428e88674d4SGreg Roach $wife_names[] = [ 429a25f0a04SGreg Roach 'type' => 'BIRT', 430a25f0a04SGreg Roach 'sort' => '@N.N.', 431ad1a1cd2SGreg Roach 'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'), 43213abd6f3SGreg Roach ]; 433a25f0a04SGreg Roach } 434a25f0a04SGreg Roach foreach ($wife_names as $n => $wife_name) { 435a25f0a04SGreg Roach $wife_names[$n]['script'] = I18N::textScript($wife_name['full']); 436a25f0a04SGreg Roach } 437e88674d4SGreg Roach 438a25f0a04SGreg Roach // Add the matched names first 439a25f0a04SGreg Roach foreach ($husb_names as $husb_name) { 440a25f0a04SGreg Roach foreach ($wife_names as $wife_name) { 441e364afe4SGreg Roach if ($husb_name['script'] === $wife_name['script']) { 442bdb3725aSGreg Roach $this->getAllNames[] = [ 443a25f0a04SGreg Roach 'type' => $husb_name['type'], 444a25f0a04SGreg Roach 'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'], 445a25f0a04SGreg Roach 'full' => $husb_name['full'] . ' + ' . $wife_name['full'], 446a25f0a04SGreg Roach // No need for a fullNN entry - we do not currently store FAM names in the database 44713abd6f3SGreg Roach ]; 448a25f0a04SGreg Roach } 449a25f0a04SGreg Roach } 450a25f0a04SGreg Roach } 451e88674d4SGreg Roach 452a25f0a04SGreg Roach // Add the unmatched names second (there may be no matched names) 453a25f0a04SGreg Roach foreach ($husb_names as $husb_name) { 454a25f0a04SGreg Roach foreach ($wife_names as $wife_name) { 455e364afe4SGreg Roach if ($husb_name['script'] !== $wife_name['script']) { 456bdb3725aSGreg Roach $this->getAllNames[] = [ 457a25f0a04SGreg Roach 'type' => $husb_name['type'], 458a25f0a04SGreg Roach 'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'], 459a25f0a04SGreg Roach 'full' => $husb_name['full'] . ' + ' . $wife_name['full'], 460a25f0a04SGreg Roach // No need for a fullNN entry - we do not currently store FAM names in the database 46113abd6f3SGreg Roach ]; 462a25f0a04SGreg Roach } 463a25f0a04SGreg Roach } 464a25f0a04SGreg Roach } 465a25f0a04SGreg Roach } 466a25f0a04SGreg Roach 467bdb3725aSGreg Roach return $this->getAllNames; 468a25f0a04SGreg Roach } 469a25f0a04SGreg Roach 47076692c8bSGreg Roach /** 47176692c8bSGreg Roach * This function should be redefined in derived classes to show any major 47276692c8bSGreg Roach * identifying characteristics of this record. 47376692c8bSGreg Roach * 47476692c8bSGreg Roach * @return string 47576692c8bSGreg Roach */ 4768f53f488SRico Sonntag public function formatListDetails(): string 477c1010edaSGreg Roach { 478a25f0a04SGreg Roach return 4798d0ebef0SGreg Roach $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) . 4808d0ebef0SGreg Roach $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1); 481a25f0a04SGreg Roach } 482a25f0a04SGreg Roach} 483