1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://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 3533c746f1SGreg Roach // The husband (or first spouse for same-sex couples) 36eec9de3fSGreg Roach private ?Individual $husb = null; 37a25f0a04SGreg Roach 3833c746f1SGreg Roach // The wife (or second spouse for same-sex couples) 39eec9de3fSGreg Roach private ?Individual $wife = null; 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 /** 66c156e8f5SGreg Roach * A closure which will compare families by marriage date. 67c156e8f5SGreg Roach * 68c6921a17SGreg Roach * @return Closure(Family,Family):int 69c156e8f5SGreg Roach */ 70c156e8f5SGreg Roach public static function marriageDateComparator(): Closure 71c156e8f5SGreg Roach { 726c2179e2SGreg Roach return static function (Family $x, Family $y): int { 73c156e8f5SGreg Roach return Date::compare($x->getMarriageDate(), $y->getMarriageDate()); 74c156e8f5SGreg Roach }; 75c156e8f5SGreg Roach } 76c156e8f5SGreg Roach 77c156e8f5SGreg Roach /** 7876692c8bSGreg Roach * Generate a private version of this record 7976692c8bSGreg Roach * 8076692c8bSGreg Roach * @param int $access_level 8176692c8bSGreg Roach * 8276692c8bSGreg Roach * @return string 8376692c8bSGreg Roach */ 843c90ed31SGreg Roach protected function createPrivateGedcomRecord(int $access_level): string 85c1010edaSGreg Roach { 86d9e083e7SGreg Roach if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') { 87d9e083e7SGreg Roach $access_level = Auth::PRIV_HIDE; 88d9e083e7SGreg Roach } 89a25f0a04SGreg Roach 90a25f0a04SGreg Roach $rec = '0 @' . $this->xref . '@ FAM'; 91a25f0a04SGreg Roach // Just show the 1 CHIL/HUSB/WIFE tag, not any subtags, which may contain private data 928d0ebef0SGreg Roach preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches, PREG_SET_ORDER); 93a25f0a04SGreg Roach foreach ($matches as $match) { 946b9cb339SGreg Roach $rela = Registry::individualFactory()->make($match[1], $this->tree); 95d9e083e7SGreg Roach if ($rela instanceof Individual && $rela->canShow($access_level)) { 96a25f0a04SGreg Roach $rec .= $match[0]; 97a25f0a04SGreg Roach } 98a25f0a04SGreg Roach } 99a25f0a04SGreg Roach 100a25f0a04SGreg Roach return $rec; 101a25f0a04SGreg Roach } 102a25f0a04SGreg Roach 10376692c8bSGreg Roach /** 104a25f0a04SGreg Roach * Get the male (or first female) partner of the family 105a25f0a04SGreg Roach * 106e93111adSRico Sonntag * @param int|null $access_level 107b3f49e6cSGreg Roach * 108a25f0a04SGreg Roach * @return Individual|null 109a25f0a04SGreg Roach */ 110*2c6f1bd5SGreg Roach public function husband(int|null $access_level = null): ?Individual 111c1010edaSGreg Roach { 112d9e083e7SGreg Roach if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') { 113d9e083e7SGreg Roach $access_level = Auth::PRIV_HIDE; 114d9e083e7SGreg Roach } 115b3f49e6cSGreg Roach 116d9e083e7SGreg Roach if ($this->husb instanceof Individual && $this->husb->canShowName($access_level)) { 117a25f0a04SGreg Roach return $this->husb; 118a25f0a04SGreg Roach } 119b2ce94c6SRico Sonntag 120b2ce94c6SRico Sonntag return null; 121a25f0a04SGreg Roach } 122a25f0a04SGreg Roach 123a25f0a04SGreg Roach /** 124a25f0a04SGreg Roach * Get the female (or second male) partner of the family 125a25f0a04SGreg Roach * 126e93111adSRico Sonntag * @param int|null $access_level 127b3f49e6cSGreg Roach * 128a25f0a04SGreg Roach * @return Individual|null 129a25f0a04SGreg Roach */ 130*2c6f1bd5SGreg Roach public function wife(int|null $access_level = null): ?Individual 131c1010edaSGreg Roach { 132d9e083e7SGreg Roach if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') { 133d9e083e7SGreg Roach $access_level = Auth::PRIV_HIDE; 134d9e083e7SGreg Roach } 135b3f49e6cSGreg Roach 136d9e083e7SGreg Roach if ($this->wife instanceof Individual && $this->wife->canShowName($access_level)) { 137a25f0a04SGreg Roach return $this->wife; 138a25f0a04SGreg Roach } 139b2ce94c6SRico Sonntag 140b2ce94c6SRico Sonntag return null; 141a25f0a04SGreg Roach } 142a25f0a04SGreg Roach 14376692c8bSGreg Roach /** 14476692c8bSGreg Roach * Each object type may have its own special rules, and re-implement this function. 14576692c8bSGreg Roach * 14676692c8bSGreg Roach * @param int $access_level 14776692c8bSGreg Roach * 14876692c8bSGreg Roach * @return bool 14976692c8bSGreg Roach */ 15035584196SGreg Roach protected function canShowByType(int $access_level): bool 151c1010edaSGreg Roach { 152a25f0a04SGreg Roach // Hide a family if any member is private 1538d0ebef0SGreg Roach preg_match_all('/\n1 (?:CHIL|HUSB|WIFE) @(' . Gedcom::REGEX_XREF . ')@/', $this->gedcom, $matches); 154a25f0a04SGreg Roach foreach ($matches[1] as $match) { 1556b9cb339SGreg Roach $person = Registry::individualFactory()->make($match, $this->tree); 156a25f0a04SGreg Roach if ($person && !$person->canShow($access_level)) { 157a25f0a04SGreg Roach return false; 158a25f0a04SGreg Roach } 159a25f0a04SGreg Roach } 160a25f0a04SGreg Roach 161a25f0a04SGreg Roach return true; 162a25f0a04SGreg Roach } 163a25f0a04SGreg Roach 16476692c8bSGreg Roach /** 16576692c8bSGreg Roach * Can the name of this record be shown? 16676692c8bSGreg Roach * 16776692c8bSGreg Roach * @param int|null $access_level 16876692c8bSGreg Roach * 16976692c8bSGreg Roach * @return bool 17076692c8bSGreg Roach */ 171*2c6f1bd5SGreg Roach public function canShowName(int|null $access_level = null): bool 172c1010edaSGreg Roach { 173a25f0a04SGreg Roach // We can always see the name (Husband-name + Wife-name), however, 174a25f0a04SGreg Roach // the name will often be "private + private" 175a25f0a04SGreg Roach return true; 176a25f0a04SGreg Roach } 177a25f0a04SGreg Roach 178a25f0a04SGreg Roach /** 179a25f0a04SGreg Roach * Find the spouse of a person. 180a25f0a04SGreg Roach * 181a25f0a04SGreg Roach * @param Individual $person 18213e3123bSGreg Roach * @param int|null $access_level 183a25f0a04SGreg Roach * 184a25f0a04SGreg Roach * @return Individual|null 185a25f0a04SGreg Roach */ 186*2c6f1bd5SGreg Roach public function spouse(Individual $person, int|null $access_level = null): ?Individual 187c1010edaSGreg Roach { 188a25f0a04SGreg Roach if ($person === $this->wife) { 18939ca88baSGreg Roach return $this->husband($access_level); 190a25f0a04SGreg Roach } 191b2ce94c6SRico Sonntag 19239ca88baSGreg Roach return $this->wife($access_level); 193a25f0a04SGreg Roach } 194a25f0a04SGreg Roach 195a25f0a04SGreg Roach /** 196a25f0a04SGreg Roach * Get the (zero, one or two) spouses from this family. 197a25f0a04SGreg Roach * 198cbc1590aSGreg Roach * @param int|null $access_level 199a25f0a04SGreg Roach * 20036779af1SGreg Roach * @return Collection<int,Individual> 201a25f0a04SGreg Roach */ 202*2c6f1bd5SGreg Roach public function spouses(int|null $access_level = null): Collection 203c1010edaSGreg Roach { 204820b62dfSGreg Roach $spouses = new Collection([ 20539ca88baSGreg Roach $this->husband($access_level), 20639ca88baSGreg Roach $this->wife($access_level), 20713abd6f3SGreg Roach ]); 208820b62dfSGreg Roach 209820b62dfSGreg Roach return $spouses->filter(); 210a25f0a04SGreg Roach } 211a25f0a04SGreg Roach 212a25f0a04SGreg Roach /** 213a25f0a04SGreg Roach * Get a list of this family’s children. 214a25f0a04SGreg Roach * 215cbc1590aSGreg Roach * @param int|null $access_level 216a25f0a04SGreg Roach * 21736779af1SGreg Roach * @return Collection<int,Individual> 218a25f0a04SGreg Roach */ 219*2c6f1bd5SGreg Roach public function children(int|null $access_level = null): Collection 220c1010edaSGreg Roach { 2213529c469SGreg Roach $access_level ??= Auth::accessLevel($this->tree); 2224b9ff166SGreg Roach 223d9e083e7SGreg Roach if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') { 224d9e083e7SGreg Roach $access_level = Auth::PRIV_HIDE; 225d9e083e7SGreg Roach } 226a25f0a04SGreg Roach 227820b62dfSGreg Roach $children = new Collection(); 228820b62dfSGreg Roach 229d9e083e7SGreg Roach foreach ($this->facts(['CHIL'], false, $access_level) as $fact) { 230dc124885SGreg Roach $child = $fact->target(); 231820b62dfSGreg Roach 232d9e083e7SGreg Roach if ($child instanceof Individual && $child->canShowName($access_level)) { 233820b62dfSGreg Roach $children->push($child); 234a25f0a04SGreg Roach } 235a25f0a04SGreg Roach } 236a25f0a04SGreg Roach 237a25f0a04SGreg Roach return $children; 238a25f0a04SGreg Roach } 239a25f0a04SGreg Roach 240a25f0a04SGreg Roach /** 241a25f0a04SGreg Roach * Number of children - for the individual list 242a25f0a04SGreg Roach * 243cbc1590aSGreg Roach * @return int 244a25f0a04SGreg Roach */ 24539ca88baSGreg Roach public function numberOfChildren(): int 246c1010edaSGreg Roach { 247820b62dfSGreg Roach $nchi = $this->children()->count(); 248820b62dfSGreg Roach 2498d0ebef0SGreg Roach foreach ($this->facts(['NCHI']) as $fact) { 25084586c02SGreg Roach $nchi = max($nchi, (int) $fact->value()); 251a25f0a04SGreg Roach } 252a25f0a04SGreg Roach 253a25f0a04SGreg Roach return $nchi; 254a25f0a04SGreg Roach } 255a25f0a04SGreg Roach 256a25f0a04SGreg Roach /** 257a25f0a04SGreg Roach * get the marriage event 258a25f0a04SGreg Roach * 25966107289SGreg Roach * @return Fact|null 260a25f0a04SGreg Roach */ 261820b62dfSGreg Roach public function getMarriage(): ?Fact 262c1010edaSGreg Roach { 263820b62dfSGreg Roach return $this->facts(['MARR'])->first(); 264a25f0a04SGreg Roach } 265a25f0a04SGreg Roach 266a25f0a04SGreg Roach /** 267a25f0a04SGreg Roach * Get marriage date 268a25f0a04SGreg Roach * 269a25f0a04SGreg Roach * @return Date 270a25f0a04SGreg Roach */ 271820b62dfSGreg Roach public function getMarriageDate(): Date 272c1010edaSGreg Roach { 273a25f0a04SGreg Roach $marriage = $this->getMarriage(); 274b6ec1ccfSGreg Roach if ($marriage instanceof Fact) { 2752decada7SGreg Roach return $marriage->date(); 276a25f0a04SGreg Roach } 277b2ce94c6SRico Sonntag 278b2ce94c6SRico Sonntag return new Date(''); 279a25f0a04SGreg Roach } 280a25f0a04SGreg Roach 281a25f0a04SGreg Roach /** 282a25f0a04SGreg Roach * Get the marriage year - displayed on lists of families 283a25f0a04SGreg Roach * 284cbc1590aSGreg Roach * @return int 285a25f0a04SGreg Roach */ 2868f53f488SRico Sonntag public function getMarriageYear(): int 287c1010edaSGreg Roach { 2884a83f5d7SGreg Roach return $this->getMarriageDate()->minimumDate()->year; 289a25f0a04SGreg Roach } 290a25f0a04SGreg Roach 291a25f0a04SGreg Roach /** 292a25f0a04SGreg Roach * Get the marriage place 293a25f0a04SGreg Roach * 294a25f0a04SGreg Roach * @return Place 295a25f0a04SGreg Roach */ 2968f53f488SRico Sonntag public function getMarriagePlace(): Place 297c1010edaSGreg Roach { 298a25f0a04SGreg Roach $marriage = $this->getMarriage(); 299a25f0a04SGreg Roach 3007abafad0SGreg Roach if ($marriage instanceof Fact) { 3014fb14fcbSGreg Roach return $marriage->place(); 302a25f0a04SGreg Roach } 303a25f0a04SGreg Roach 3047abafad0SGreg Roach return new Place('', $this->tree); 3057abafad0SGreg Roach } 3067abafad0SGreg Roach 307a25f0a04SGreg Roach /** 308a25f0a04SGreg Roach * Get a list of all marriage dates - for the family lists. 309a25f0a04SGreg Roach * 31009482a55SGreg Roach * @return array<Date> 311a25f0a04SGreg Roach */ 3128f53f488SRico Sonntag public function getAllMarriageDates(): array 313c1010edaSGreg Roach { 3148d0ebef0SGreg Roach foreach (Gedcom::MARRIAGE_EVENTS as $event) { 3157abafad0SGreg Roach $array = $this->getAllEventDates([$event]); 3168af3e5c1SGreg Roach 31754c1ab5eSGreg Roach if ($array !== []) { 318a25f0a04SGreg Roach return $array; 319a25f0a04SGreg Roach } 320a25f0a04SGreg Roach } 321a25f0a04SGreg Roach 32213abd6f3SGreg Roach return []; 323a25f0a04SGreg Roach } 324a25f0a04SGreg Roach 325a25f0a04SGreg Roach /** 326a25f0a04SGreg Roach * Get a list of all marriage places - for the family lists. 327a25f0a04SGreg Roach * 32809482a55SGreg Roach * @return array<Place> 329a25f0a04SGreg Roach */ 3308f53f488SRico Sonntag public function getAllMarriagePlaces(): array 331c1010edaSGreg Roach { 3328d0ebef0SGreg Roach foreach (Gedcom::MARRIAGE_EVENTS as $event) { 3336e83554dSGreg Roach $places = $this->getAllEventPlaces([$event]); 33454c1ab5eSGreg Roach if ($places !== []) { 3354080d558SGreg Roach return $places; 336a25f0a04SGreg Roach } 337a25f0a04SGreg Roach } 338a25f0a04SGreg Roach 33913abd6f3SGreg Roach return []; 340a25f0a04SGreg Roach } 341a25f0a04SGreg Roach 34276692c8bSGreg Roach /** 34376692c8bSGreg Roach * Derived classes should redefine this function, otherwise the object will have no name 34476692c8bSGreg Roach * 345870ec5a3SGreg Roach * @return array<int,array<string,string>> 34676692c8bSGreg Roach */ 3478f53f488SRico Sonntag public function getAllNames(): array 348c1010edaSGreg Roach { 3499599771eSGreg Roach if ($this->getAllNames === []) { 350a25f0a04SGreg Roach // Check the script used by each name, so we can match cyrillic with cyrillic, greek with greek, etc. 351e88674d4SGreg Roach $husb_names = []; 352b6ec1ccfSGreg Roach if ($this->husb instanceof Individual) { 3530b5fd0a6SGreg Roach $husb_names = array_filter($this->husb->getAllNames(), static function (array $x): bool { 3548d68cabeSGreg Roach return $x['type'] !== '_MARNM'; 3558d68cabeSGreg Roach }); 356e88674d4SGreg Roach } 3571f244d77SGreg Roach // If the individual only has married names, create a fake birth name. 35854c1ab5eSGreg Roach if ($husb_names === []) { 359e88674d4SGreg Roach $husb_names[] = [ 360a25f0a04SGreg Roach 'type' => 'BIRT', 3618fb4e87cSGreg Roach 'sort' => Individual::NOMEN_NESCIO, 362ad1a1cd2SGreg Roach 'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'), 36313abd6f3SGreg Roach ]; 364a25f0a04SGreg Roach } 365a25f0a04SGreg Roach foreach ($husb_names as $n => $husb_name) { 366a25f0a04SGreg Roach $husb_names[$n]['script'] = I18N::textScript($husb_name['full']); 367a25f0a04SGreg Roach } 368e88674d4SGreg Roach 369e88674d4SGreg Roach $wife_names = []; 370b6ec1ccfSGreg Roach if ($this->wife instanceof Individual) { 3710b5fd0a6SGreg Roach $wife_names = array_filter($this->wife->getAllNames(), static function (array $x): bool { 3728d68cabeSGreg Roach return $x['type'] !== '_MARNM'; 3738d68cabeSGreg Roach }); 374e88674d4SGreg Roach } 3751f244d77SGreg Roach // If the individual only has married names, create a fake birth name. 37654c1ab5eSGreg Roach if ($wife_names === []) { 377e88674d4SGreg Roach $wife_names[] = [ 378a25f0a04SGreg Roach 'type' => 'BIRT', 3798fb4e87cSGreg Roach 'sort' => Individual::NOMEN_NESCIO, 380ad1a1cd2SGreg Roach 'full' => I18N::translateContext('Unknown given name', '…') . ' ' . I18N::translateContext('Unknown surname', '…'), 38113abd6f3SGreg Roach ]; 382a25f0a04SGreg Roach } 383a25f0a04SGreg Roach foreach ($wife_names as $n => $wife_name) { 384a25f0a04SGreg Roach $wife_names[$n]['script'] = I18N::textScript($wife_name['full']); 385a25f0a04SGreg Roach } 386e88674d4SGreg Roach 387a25f0a04SGreg Roach // Add the matched names first 388a25f0a04SGreg Roach foreach ($husb_names as $husb_name) { 389a25f0a04SGreg Roach foreach ($wife_names as $wife_name) { 390e364afe4SGreg Roach if ($husb_name['script'] === $wife_name['script']) { 391bdb3725aSGreg Roach $this->getAllNames[] = [ 392a25f0a04SGreg Roach 'type' => $husb_name['type'], 393a25f0a04SGreg Roach 'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'], 394a25f0a04SGreg Roach 'full' => $husb_name['full'] . ' + ' . $wife_name['full'], 395a25f0a04SGreg Roach // No need for a fullNN entry - we do not currently store FAM names in the database 39613abd6f3SGreg Roach ]; 397a25f0a04SGreg Roach } 398a25f0a04SGreg Roach } 399a25f0a04SGreg Roach } 400e88674d4SGreg Roach 401a25f0a04SGreg Roach // Add the unmatched names second (there may be no matched names) 402a25f0a04SGreg Roach foreach ($husb_names as $husb_name) { 403a25f0a04SGreg Roach foreach ($wife_names as $wife_name) { 404e364afe4SGreg Roach if ($husb_name['script'] !== $wife_name['script']) { 405bdb3725aSGreg Roach $this->getAllNames[] = [ 406a25f0a04SGreg Roach 'type' => $husb_name['type'], 407a25f0a04SGreg Roach 'sort' => $husb_name['sort'] . ' + ' . $wife_name['sort'], 408a25f0a04SGreg Roach 'full' => $husb_name['full'] . ' + ' . $wife_name['full'], 409a25f0a04SGreg Roach // No need for a fullNN entry - we do not currently store FAM names in the database 41013abd6f3SGreg Roach ]; 411a25f0a04SGreg Roach } 412a25f0a04SGreg Roach } 413a25f0a04SGreg Roach } 414a25f0a04SGreg Roach } 415a25f0a04SGreg Roach 416bdb3725aSGreg Roach return $this->getAllNames; 417a25f0a04SGreg Roach } 418a25f0a04SGreg Roach 41976692c8bSGreg Roach /** 42076692c8bSGreg Roach * This function should be redefined in derived classes to show any major 42176692c8bSGreg Roach * identifying characteristics of this record. 42276692c8bSGreg Roach * 42376692c8bSGreg Roach * @return string 42476692c8bSGreg Roach */ 4258f53f488SRico Sonntag public function formatListDetails(): string 426c1010edaSGreg Roach { 427a25f0a04SGreg Roach return 4288d0ebef0SGreg Roach $this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) . 4298d0ebef0SGreg Roach $this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1); 430a25f0a04SGreg Roach } 4318091bfd1SGreg Roach 4328091bfd1SGreg Roach /** 4338091bfd1SGreg Roach * Lock the database row, to prevent concurrent edits. 4348091bfd1SGreg Roach */ 4358091bfd1SGreg Roach public function lock(): void 4368091bfd1SGreg Roach { 4378091bfd1SGreg Roach DB::table('families') 4388091bfd1SGreg Roach ->where('f_file', '=', $this->tree->id()) 4398091bfd1SGreg Roach ->where('f_id', '=', $this->xref()) 4408091bfd1SGreg Roach ->lockForUpdate() 4418091bfd1SGreg Roach ->get(); 4428091bfd1SGreg Roach } 443a25f0a04SGreg Roach} 444