13763c3f2SGreg Roach<?php 23763c3f2SGreg Roach/** 33763c3f2SGreg Roach * webtrees: online genealogy 48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 53763c3f2SGreg Roach * This program is free software: you can redistribute it and/or modify 63763c3f2SGreg Roach * it under the terms of the GNU General Public License as published by 73763c3f2SGreg Roach * the Free Software Foundation, either version 3 of the License, or 83763c3f2SGreg Roach * (at your option) any later version. 93763c3f2SGreg Roach * This program is distributed in the hope that it will be useful, 103763c3f2SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 113763c3f2SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 123763c3f2SGreg Roach * GNU General Public License for more details. 133763c3f2SGreg Roach * You should have received a copy of the GNU General Public License 143763c3f2SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 153763c3f2SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 17e7f56f2aSGreg Roach 1876692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1976692c8bSGreg Roach 20*907c1109SGreg Roachuse function array_merge; 2163276d8fSGreg Roachuse Fisharebest\Webtrees\Auth; 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Date; 230e62c4b8SGreg Roachuse Fisharebest\Webtrees\Fact; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family; 258d0ebef0SGreg Roachuse Fisharebest\Webtrees\Gedcom; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual; 282adcbd9aSGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService; 294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 3017c50b57SGreg Roachuse Illuminate\Support\Collection; 313763c3f2SGreg Roach 323763c3f2SGreg Roach/** 333763c3f2SGreg Roach * Class IndividualFactsTabModule 343763c3f2SGreg Roach */ 3537eb8894SGreg Roachclass IndividualFactsTabModule extends AbstractModule implements ModuleTabInterface 36c1010edaSGreg Roach{ 3749a243cbSGreg Roach use ModuleTabTrait; 3849a243cbSGreg Roach 392adcbd9aSGreg Roach /** @var ModuleService */ 404ca7e03cSGreg Roach private $module_service; 414ca7e03cSGreg Roach 422adcbd9aSGreg Roach /** @var ClipboardService */ 432adcbd9aSGreg Roach private $clipboard_service; 442adcbd9aSGreg Roach 454ca7e03cSGreg Roach /** 464ca7e03cSGreg Roach * UserWelcomeModule constructor. 474ca7e03cSGreg Roach * 484ca7e03cSGreg Roach * @param ModuleService $module_service 492adcbd9aSGreg Roach * @param ClipboardService $clipboard_service 504ca7e03cSGreg Roach */ 512adcbd9aSGreg Roach public function __construct(ModuleService $module_service, ClipboardService $clipboard_service) 525bdbe281SGreg Roach { 534ca7e03cSGreg Roach $this->module_service = $module_service; 542adcbd9aSGreg Roach $this->clipboard_service = $clipboard_service; 554ca7e03cSGreg Roach } 564ca7e03cSGreg Roach 574ca7e03cSGreg Roach /** 580cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 59961ec755SGreg Roach * 60961ec755SGreg Roach * @return string 61961ec755SGreg Roach */ 6249a243cbSGreg Roach public function title(): string 63c1010edaSGreg Roach { 64bbb76c12SGreg Roach /* I18N: Name of a module/tab on the individual page. */ 65bbb76c12SGreg Roach return I18N::translate('Facts and events'); 663763c3f2SGreg Roach } 673763c3f2SGreg Roach 68961ec755SGreg Roach /** 69961ec755SGreg Roach * A sentence describing what this module does. 70961ec755SGreg Roach * 71961ec755SGreg Roach * @return string 72961ec755SGreg Roach */ 7349a243cbSGreg Roach public function description(): string 74c1010edaSGreg Roach { 75bbb76c12SGreg Roach /* I18N: Description of the “Facts and events” module */ 76bbb76c12SGreg Roach return I18N::translate('A tab showing the facts and events of an individual.'); 773763c3f2SGreg Roach } 783763c3f2SGreg Roach 7949a243cbSGreg Roach /** 8049a243cbSGreg Roach * The default position for this tab. It can be changed in the control panel. 8149a243cbSGreg Roach * 8249a243cbSGreg Roach * @return int 8349a243cbSGreg Roach */ 84cbf4b7faSGreg Roach public function defaultTabOrder(): int 85cbf4b7faSGreg Roach { 86fb7a0427SGreg Roach return 1; 873763c3f2SGreg Roach } 883763c3f2SGreg Roach 893763c3f2SGreg Roach /** {@inheritdoc} */ 908f53f488SRico Sonntag public function isGrayedOut(Individual $individual): bool 91c1010edaSGreg Roach { 923763c3f2SGreg Roach return false; 933763c3f2SGreg Roach } 943763c3f2SGreg Roach 953763c3f2SGreg Roach /** {@inheritdoc} */ 969b34404bSGreg Roach public function getTabContent(Individual $individual): string 97c1010edaSGreg Roach { 98ee727175SGreg Roach // Only include events of close relatives that are between birth and death 99ee727175SGreg Roach $min_date = $individual->getEstimatedBirthDate(); 100ee727175SGreg Roach $max_date = $individual->getEstimatedDeathDate(); 101ee727175SGreg Roach 1028eaf8709SGreg Roach // Which facts and events are handled by other modules? 1038eaf8709SGreg Roach $sidebar_facts = $this->module_service 10487cca37cSGreg Roach ->findByComponent(ModuleSidebarInterface::class, $individual->tree(), Auth::user()) 1050b5fd0a6SGreg Roach ->map(static function (ModuleSidebarInterface $sidebar): Collection { 1068eaf8709SGreg Roach return $sidebar->supportedFacts(); 1078eaf8709SGreg Roach }); 1088eaf8709SGreg Roach 1098eaf8709SGreg Roach $tab_facts = $this->module_service 11087cca37cSGreg Roach ->findByComponent(ModuleTabInterface::class, $individual->tree(), Auth::user()) 1110b5fd0a6SGreg Roach ->map(static function (ModuleTabInterface $sidebar): Collection { 1128eaf8709SGreg Roach return $sidebar->supportedFacts(); 1138eaf8709SGreg Roach }); 1148eaf8709SGreg Roach 1158eaf8709SGreg Roach $exclude_facts = $sidebar_facts->merge($tab_facts)->flatten(); 1168eaf8709SGreg Roach 1178eaf8709SGreg Roach 1183763c3f2SGreg Roach // The individual’s own facts 11939ca88baSGreg Roach $indifacts = $individual->facts() 1200b5fd0a6SGreg Roach ->filter(static function (Fact $fact) use ($exclude_facts): bool { 12139ca88baSGreg Roach return !$exclude_facts->contains($fact->getTag()); 12239ca88baSGreg Roach }); 1233763c3f2SGreg Roach 1243763c3f2SGreg Roach // Add spouse-family facts 12539ca88baSGreg Roach foreach ($individual->spouseFamilies() as $family) { 12630158ae7SGreg Roach foreach ($family->facts() as $fact) { 1278eaf8709SGreg Roach if (!$exclude_facts->contains($fact->getTag()) && $fact->getTag() !== 'CHAN') { 12839ca88baSGreg Roach $indifacts->push($fact); 1293763c3f2SGreg Roach } 1303763c3f2SGreg Roach } 131ee727175SGreg Roach 13239ca88baSGreg Roach $spouse = $family->spouse($individual); 133ee727175SGreg Roach 134ee727175SGreg Roach if ($spouse instanceof Individual) { 1358b9cfadbSGreg Roach $spouse_facts = $this->spouseFacts($individual, $spouse, $min_date, $max_date); 13639ca88baSGreg Roach $indifacts = $indifacts->merge($spouse_facts); 1373763c3f2SGreg Roach } 1383763c3f2SGreg Roach 1398b9cfadbSGreg Roach $child_facts = $this->childFacts($individual, $family, '_CHIL', '', $min_date, $max_date); 14039ca88baSGreg Roach $indifacts = $indifacts->merge($child_facts); 1413763c3f2SGreg Roach } 142225e381fSGreg Roach 1438b9cfadbSGreg Roach $parent_facts = $this->parentFacts($individual, 1, $min_date, $max_date); 1448b9cfadbSGreg Roach $associate_facts = $this->associateFacts($individual); 1458b9cfadbSGreg Roach $historical_facts = $this->historicalFacts($individual); 146225e381fSGreg Roach 14739ca88baSGreg Roach $indifacts = $indifacts 14839ca88baSGreg Roach ->merge($parent_facts) 14939ca88baSGreg Roach ->merge($associate_facts) 15039ca88baSGreg Roach ->merge($historical_facts); 1513763c3f2SGreg Roach 152580a4d11SGreg Roach $indifacts = Fact::sortFacts($indifacts); 1533763c3f2SGreg Roach 154a8cd57e1SGreg Roach return view('modules/personal_facts/tab', [ 155225e381fSGreg Roach 'can_edit' => $individual->canEdit(), 1562adcbd9aSGreg Roach 'clipboard_facts' => $this->clipboard_service->pastableFacts($individual, $exclude_facts), 157ee727175SGreg Roach 'has_historical_facts' => !empty($historical_facts), 158225e381fSGreg Roach 'individual' => $individual, 159225e381fSGreg Roach 'facts' => $indifacts, 160225e381fSGreg Roach ]); 1613763c3f2SGreg Roach } 1623763c3f2SGreg Roach 163ee727175SGreg Roach /** 164ee727175SGreg Roach * Does a relative event occur within a date range (i.e. the individual's lifetime)? 165ee727175SGreg Roach * 166ee727175SGreg Roach * @param Fact $fact 167ee727175SGreg Roach * @param Date $min_date 168ee727175SGreg Roach * @param Date $max_date 169ee727175SGreg Roach * 170ee727175SGreg Roach * @return bool 171ee727175SGreg Roach */ 1728b9cfadbSGreg Roach private function includeFact(Fact $fact, Date $min_date, Date $max_date): bool 173b3b1d905SGreg Roach { 1742decada7SGreg Roach $fact_date = $fact->date(); 175ee727175SGreg Roach 176ee727175SGreg Roach return $fact_date->isOK() && Date::compare($min_date, $fact_date) <= 0 && Date::compare($fact_date, $max_date) <= 0; 177ee727175SGreg Roach } 178ee727175SGreg Roach 1793763c3f2SGreg Roach /** {@inheritdoc} */ 1808f53f488SRico Sonntag public function hasTabContent(Individual $individual): bool 181c1010edaSGreg Roach { 1823763c3f2SGreg Roach return true; 1833763c3f2SGreg Roach } 1843763c3f2SGreg Roach 1853763c3f2SGreg Roach /** {@inheritdoc} */ 1868f53f488SRico Sonntag public function canLoadAjax(): bool 187c1010edaSGreg Roach { 18815d603e7SGreg Roach return false; 1893763c3f2SGreg Roach } 1903763c3f2SGreg Roach 1913763c3f2SGreg Roach /** 1923763c3f2SGreg Roach * Spouse facts that are shown on an individual’s page. 1933763c3f2SGreg Roach * 1943763c3f2SGreg Roach * @param Individual $individual Show events that occured during the lifetime of this individual 1953763c3f2SGreg Roach * @param Individual $spouse Show events of this individual 196ee727175SGreg Roach * @param Date $min_date 197ee727175SGreg Roach * @param Date $max_date 1983763c3f2SGreg Roach * 1993763c3f2SGreg Roach * @return Fact[] 2003763c3f2SGreg Roach */ 2018b9cfadbSGreg Roach private function spouseFacts(Individual $individual, Individual $spouse, Date $min_date, Date $max_date): array 202c1010edaSGreg Roach { 203f4afa648SGreg Roach $SHOW_RELATIVES_EVENTS = $individual->tree()->getPreference('SHOW_RELATIVES_EVENTS'); 2043763c3f2SGreg Roach 20513abd6f3SGreg Roach $facts = []; 2063763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT_SPOU')) { 2078d0ebef0SGreg Roach foreach ($spouse->facts(Gedcom::DEATH_EVENTS) as $fact) { 2088b9cfadbSGreg Roach if ($this->includeFact($fact, $min_date, $max_date)) { 2093763c3f2SGreg Roach // Convert the event to a close relatives event. 210e364afe4SGreg Roach $rela_fact = clone $fact; 2113763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_SPOU'); 2123763c3f2SGreg Roach $facts[] = $rela_fact; 2133763c3f2SGreg Roach } 2143763c3f2SGreg Roach } 2153763c3f2SGreg Roach } 2163763c3f2SGreg Roach 2173763c3f2SGreg Roach return $facts; 2183763c3f2SGreg Roach } 2193763c3f2SGreg Roach 2203763c3f2SGreg Roach /** 2213763c3f2SGreg Roach * Get the events of children and grandchildren. 2223763c3f2SGreg Roach * 2233763c3f2SGreg Roach * @param Individual $person 2243763c3f2SGreg Roach * @param Family $family 2253763c3f2SGreg Roach * @param string $option 2263763c3f2SGreg Roach * @param string $relation 227ee727175SGreg Roach * @param Date $min_date 228ee727175SGreg Roach * @param Date $max_date 2293763c3f2SGreg Roach * 2303763c3f2SGreg Roach * @return Fact[] 2313763c3f2SGreg Roach */ 2328b9cfadbSGreg Roach private function childFacts(Individual $person, Family $family, $option, $relation, Date $min_date, Date $max_date): array 233c1010edaSGreg Roach { 234f4afa648SGreg Roach $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS'); 2353763c3f2SGreg Roach 23613abd6f3SGreg Roach $facts = []; 2373763c3f2SGreg Roach 2383763c3f2SGreg Roach // Deal with recursion. 2393763c3f2SGreg Roach switch ($option) { 2403763c3f2SGreg Roach case '_CHIL': 2413763c3f2SGreg Roach // Add grandchildren 24239ca88baSGreg Roach foreach ($family->children() as $child) { 24339ca88baSGreg Roach foreach ($child->spouseFamilies() as $cfamily) { 24439ca88baSGreg Roach switch ($child->sex()) { 2453763c3f2SGreg Roach case 'M': 2468b9cfadbSGreg Roach foreach ($this->childFacts($person, $cfamily, '_GCHI', 'son', $min_date, $max_date) as $fact) { 2473763c3f2SGreg Roach $facts[] = $fact; 2483763c3f2SGreg Roach } 2493763c3f2SGreg Roach break; 2503763c3f2SGreg Roach case 'F': 2518b9cfadbSGreg Roach foreach ($this->childFacts($person, $cfamily, '_GCHI', 'dau', $min_date, $max_date) as $fact) { 2523763c3f2SGreg Roach $facts[] = $fact; 2533763c3f2SGreg Roach } 2543763c3f2SGreg Roach break; 2553763c3f2SGreg Roach default: 2568b9cfadbSGreg Roach foreach ($this->childFacts($person, $cfamily, '_GCHI', 'chi', $min_date, $max_date) as $fact) { 2573763c3f2SGreg Roach $facts[] = $fact; 2583763c3f2SGreg Roach } 2593763c3f2SGreg Roach break; 2603763c3f2SGreg Roach } 2613763c3f2SGreg Roach } 2623763c3f2SGreg Roach } 2633763c3f2SGreg Roach break; 2643763c3f2SGreg Roach } 2653763c3f2SGreg Roach 2663763c3f2SGreg Roach // For each child in the family 26739ca88baSGreg Roach foreach ($family->children() as $child) { 26822d65e5aSGreg Roach if ($child->xref() === $person->xref()) { 2693763c3f2SGreg Roach // We are not our own sibling! 2703763c3f2SGreg Roach continue; 2713763c3f2SGreg Roach } 2723763c3f2SGreg Roach // add child’s birth 2733763c3f2SGreg Roach if (strpos($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { 2748d0ebef0SGreg Roach foreach ($child->facts(Gedcom::BIRTH_EVENTS) as $fact) { 2753763c3f2SGreg Roach // Always show _BIRT_CHIL, even if the dates are not known 27622d65e5aSGreg Roach if ($option === '_CHIL' || $this->includeFact($fact, $min_date, $max_date)) { 27722d65e5aSGreg Roach if ($option === '_GCHI' && $relation === 'dau') { 2783763c3f2SGreg Roach // Convert the event to a close relatives event. 279e364afe4SGreg Roach $rela_fact = clone $fact; 2803763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); 2813763c3f2SGreg Roach $facts[] = $rela_fact; 28222d65e5aSGreg Roach } elseif ($option === '_GCHI' && $relation === 'son') { 2833763c3f2SGreg Roach // Convert the event to a close relatives event. 284e364afe4SGreg Roach $rela_fact = clone $fact; 2853763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); 2863763c3f2SGreg Roach $facts[] = $rela_fact; 2873763c3f2SGreg Roach } else { 2883763c3f2SGreg Roach // Convert the event to a close relatives event. 289e364afe4SGreg Roach $rela_fact = clone $fact; 2903763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . $option); 2913763c3f2SGreg Roach $facts[] = $rela_fact; 2923763c3f2SGreg Roach } 2933763c3f2SGreg Roach } 2943763c3f2SGreg Roach } 2953763c3f2SGreg Roach } 2963763c3f2SGreg Roach // add child’s death 2973763c3f2SGreg Roach if (strpos($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { 2988d0ebef0SGreg Roach foreach ($child->facts(Gedcom::DEATH_EVENTS) as $fact) { 2998b9cfadbSGreg Roach if ($this->includeFact($fact, $min_date, $max_date)) { 30022d65e5aSGreg Roach if ($option === '_GCHI' && $relation === 'dau') { 3013763c3f2SGreg Roach // Convert the event to a close relatives event. 302e364afe4SGreg Roach $rela_fact = clone $fact; 3033763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); 3043763c3f2SGreg Roach $facts[] = $rela_fact; 30522d65e5aSGreg Roach } elseif ($option === '_GCHI' && $relation === 'son') { 3063763c3f2SGreg Roach // Convert the event to a close relatives event. 307e364afe4SGreg Roach $rela_fact = clone $fact; 3083763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); 3093763c3f2SGreg Roach $facts[] = $rela_fact; 3103763c3f2SGreg Roach } else { 3113763c3f2SGreg Roach // Convert the event to a close relatives event. 312e364afe4SGreg Roach $rela_fact = clone $fact; 3133763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . $option); 3143763c3f2SGreg Roach $facts[] = $rela_fact; 3153763c3f2SGreg Roach } 3163763c3f2SGreg Roach } 3173763c3f2SGreg Roach } 3183763c3f2SGreg Roach } 3193763c3f2SGreg Roach // add child’s marriage 3203763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) { 32139ca88baSGreg Roach foreach ($child->spouseFamilies() as $sfamily) { 3228d0ebef0SGreg Roach foreach ($sfamily->facts(['MARR']) as $fact) { 3238b9cfadbSGreg Roach if ($this->includeFact($fact, $min_date, $max_date)) { 32422d65e5aSGreg Roach if ($option === '_GCHI' && $relation === 'dau') { 3253763c3f2SGreg Roach // Convert the event to a close relatives event. 326e364afe4SGreg Roach $rela_fact = clone $fact; 3273763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); 3283763c3f2SGreg Roach $facts[] = $rela_fact; 32922d65e5aSGreg Roach } elseif ($option === '_GCHI' && $relation === 'son') { 3303763c3f2SGreg Roach // Convert the event to a close relatives event. 331e364afe4SGreg Roach $rela_fact = clone $fact; 3323763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); 3333763c3f2SGreg Roach $facts[] = $rela_fact; 3343763c3f2SGreg Roach } else { 3353763c3f2SGreg Roach // Convert the event to a close relatives event. 336e364afe4SGreg Roach $rela_fact = clone $fact; 3373763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . $option); 3383763c3f2SGreg Roach $facts[] = $rela_fact; 3393763c3f2SGreg Roach } 3403763c3f2SGreg Roach } 3413763c3f2SGreg Roach } 3423763c3f2SGreg Roach } 3433763c3f2SGreg Roach } 3443763c3f2SGreg Roach } 3453763c3f2SGreg Roach 3463763c3f2SGreg Roach return $facts; 3473763c3f2SGreg Roach } 3483763c3f2SGreg Roach 3493763c3f2SGreg Roach /** 3503763c3f2SGreg Roach * Get the events of parents and grandparents. 3513763c3f2SGreg Roach * 3523763c3f2SGreg Roach * @param Individual $person 353cbc1590aSGreg Roach * @param int $sosa 354ee727175SGreg Roach * @param Date $min_date 355ee727175SGreg Roach * @param Date $max_date 3563763c3f2SGreg Roach * 3573763c3f2SGreg Roach * @return Fact[] 3583763c3f2SGreg Roach */ 3598b9cfadbSGreg Roach private function parentFacts(Individual $person, $sosa, Date $min_date, Date $max_date): array 360c1010edaSGreg Roach { 361f4afa648SGreg Roach $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS'); 3623763c3f2SGreg Roach 36313abd6f3SGreg Roach $facts = []; 3643763c3f2SGreg Roach 3653763c3f2SGreg Roach if ($sosa == 1) { 36639ca88baSGreg Roach foreach ($person->childFamilies() as $family) { 3673763c3f2SGreg Roach // Add siblings 3688b9cfadbSGreg Roach foreach ($this->childFacts($person, $family, '_SIBL', '', $min_date, $max_date) as $fact) { 3693763c3f2SGreg Roach $facts[] = $fact; 3703763c3f2SGreg Roach } 37139ca88baSGreg Roach foreach ($family->spouses() as $spouse) { 37239ca88baSGreg Roach foreach ($spouse->spouseFamilies() as $sfamily) { 3733763c3f2SGreg Roach if ($family !== $sfamily) { 3743763c3f2SGreg Roach // Add half-siblings 3758b9cfadbSGreg Roach foreach ($this->childFacts($person, $sfamily, '_HSIB', '', $min_date, $max_date) as $fact) { 3763763c3f2SGreg Roach $facts[] = $fact; 3773763c3f2SGreg Roach } 3783763c3f2SGreg Roach } 3793763c3f2SGreg Roach } 3803763c3f2SGreg Roach // Add grandparents 38122d65e5aSGreg Roach foreach ($this->parentFacts($spouse, $spouse->sex() === 'F' ? 3 : 2, $min_date, $max_date) as $fact) { 3823763c3f2SGreg Roach $facts[] = $fact; 3833763c3f2SGreg Roach } 3843763c3f2SGreg Roach } 3853763c3f2SGreg Roach } 3863763c3f2SGreg Roach 3873763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_MARR_PARE')) { 3883763c3f2SGreg Roach // add father/mother marriages 38939ca88baSGreg Roach foreach ($person->childFamilies() as $sfamily) { 3908d0ebef0SGreg Roach foreach ($sfamily->facts(['MARR']) as $fact) { 3918b9cfadbSGreg Roach if ($this->includeFact($fact, $min_date, $max_date)) { 3923763c3f2SGreg Roach // marriage of parents (to each other) 393e364afe4SGreg Roach $rela_fact = clone $fact; 3943763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_FAMC'); 3953763c3f2SGreg Roach $facts[] = $rela_fact; 3963763c3f2SGreg Roach } 3973763c3f2SGreg Roach } 3983763c3f2SGreg Roach } 39939ca88baSGreg Roach foreach ($person->childStepFamilies() as $sfamily) { 4008d0ebef0SGreg Roach foreach ($sfamily->facts(['MARR']) as $fact) { 4018b9cfadbSGreg Roach if ($this->includeFact($fact, $min_date, $max_date)) { 4023763c3f2SGreg Roach // marriage of a parent (to another spouse) 4033763c3f2SGreg Roach // Convert the event to a close relatives event 404e364afe4SGreg Roach $rela_fact = clone $fact; 4053763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); 4063763c3f2SGreg Roach $facts[] = $rela_fact; 4073763c3f2SGreg Roach } 4083763c3f2SGreg Roach } 4093763c3f2SGreg Roach } 4103763c3f2SGreg Roach } 4113763c3f2SGreg Roach } 4123763c3f2SGreg Roach 41339ca88baSGreg Roach foreach ($person->childFamilies() as $family) { 41439ca88baSGreg Roach foreach ($family->spouses() as $parent) { 4153763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT' . ($sosa == 1 ? '_PARE' : '_GPAR'))) { 4168d0ebef0SGreg Roach foreach ($parent->facts(Gedcom::DEATH_EVENTS) as $fact) { 4178b9cfadbSGreg Roach if ($this->includeFact($fact, $min_date, $max_date)) { 4183763c3f2SGreg Roach switch ($sosa) { 4193763c3f2SGreg Roach case 1: 4203763c3f2SGreg Roach // Convert the event to a close relatives event. 421e364afe4SGreg Roach $rela_fact = clone $fact; 4223763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); 4233763c3f2SGreg Roach $facts[] = $rela_fact; 4243763c3f2SGreg Roach break; 4253763c3f2SGreg Roach case 2: 4263763c3f2SGreg Roach // Convert the event to a close relatives event 427e364afe4SGreg Roach $rela_fact = clone $fact; 4283763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GPA1'); 4293763c3f2SGreg Roach $facts[] = $rela_fact; 4303763c3f2SGreg Roach break; 4313763c3f2SGreg Roach case 3: 4323763c3f2SGreg Roach // Convert the event to a close relatives event 433e364afe4SGreg Roach $rela_fact = clone $fact; 4343763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GPA2'); 4353763c3f2SGreg Roach $facts[] = $rela_fact; 4363763c3f2SGreg Roach break; 4373763c3f2SGreg Roach } 4383763c3f2SGreg Roach } 4393763c3f2SGreg Roach } 4403763c3f2SGreg Roach } 4413763c3f2SGreg Roach } 4423763c3f2SGreg Roach } 4433763c3f2SGreg Roach 4443763c3f2SGreg Roach return $facts; 4453763c3f2SGreg Roach } 4463763c3f2SGreg Roach 4473763c3f2SGreg Roach /** 4483763c3f2SGreg Roach * Get any historical events. 4493763c3f2SGreg Roach * 45017c50b57SGreg Roach * @param Individual $individual 4513763c3f2SGreg Roach * 4523763c3f2SGreg Roach * @return Fact[] 4533763c3f2SGreg Roach */ 4544ca7e03cSGreg Roach private function historicalFacts(Individual $individual): array 455c1010edaSGreg Roach { 4564ca7e03cSGreg Roach return $this->module_service->findByInterface(ModuleHistoricEventsInterface::class) 4570b5fd0a6SGreg Roach ->map(static function (ModuleHistoricEventsInterface $module) use ($individual): Collection { 45817c50b57SGreg Roach return $module->historicEventsForIndividual($individual); 45917c50b57SGreg Roach }) 46017c50b57SGreg Roach ->flatten() 46117c50b57SGreg Roach ->all(); 4623763c3f2SGreg Roach } 4633763c3f2SGreg Roach 4643763c3f2SGreg Roach /** 4653763c3f2SGreg Roach * Get the events of associates. 4663763c3f2SGreg Roach * 4673763c3f2SGreg Roach * @param Individual $person 4683763c3f2SGreg Roach * 4693763c3f2SGreg Roach * @return Fact[] 4703763c3f2SGreg Roach */ 4718b9cfadbSGreg Roach private function associateFacts(Individual $person): array 472c1010edaSGreg Roach { 47313abd6f3SGreg Roach $facts = []; 4743763c3f2SGreg Roach 475ee727175SGreg Roach /** @var Individual[] $associates */ 476*907c1109SGreg Roach $asso1 = $person->linkedIndividuals('ASSO'); 477*907c1109SGreg Roach $asso2 = $person->linkedIndividuals('_ASSO'); 478*907c1109SGreg Roach $asso3 = $person->linkedFamilies('ASSO'); 479*907c1109SGreg Roach $asso4 = $person->linkedFamilies('_ASSO'); 480*907c1109SGreg Roach 481*907c1109SGreg Roach $associates = $asso1->merge($asso2)->merge($asso3)->merge($asso4); 482*907c1109SGreg Roach 4833763c3f2SGreg Roach foreach ($associates as $associate) { 48430158ae7SGreg Roach foreach ($associate->facts() as $fact) { 485*907c1109SGreg Roach if (preg_match('/\n\d _?ASSO @' . $person->xref() . '@/', $fact->gedcom())) { 4863763c3f2SGreg Roach // Extract the important details from the fact 4873763c3f2SGreg Roach $factrec = '1 ' . $fact->getTag(); 488138ca96cSGreg Roach if (preg_match('/\n2 DATE .*/', $fact->gedcom(), $match)) { 4893763c3f2SGreg Roach $factrec .= $match[0]; 4903763c3f2SGreg Roach } 491138ca96cSGreg Roach if (preg_match('/\n2 PLAC .*/', $fact->gedcom(), $match)) { 4923763c3f2SGreg Roach $factrec .= $match[0]; 4933763c3f2SGreg Roach } 4943763c3f2SGreg Roach if ($associate instanceof Family) { 49539ca88baSGreg Roach foreach ($associate->spouses() as $spouse) { 496c0935879SGreg Roach $factrec .= "\n2 _ASSO @" . $spouse->xref() . '@'; 4973763c3f2SGreg Roach } 4983763c3f2SGreg Roach } else { 499c0935879SGreg Roach $factrec .= "\n2 _ASSO @" . $associate->xref() . '@'; 5003763c3f2SGreg Roach } 5013763c3f2SGreg Roach $facts[] = new Fact($factrec, $associate, 'asso'); 5023763c3f2SGreg Roach } 5033763c3f2SGreg Roach } 5043763c3f2SGreg Roach } 5053763c3f2SGreg Roach 5063763c3f2SGreg Roach return $facts; 5073763c3f2SGreg Roach } 5088eaf8709SGreg Roach 5098eaf8709SGreg Roach /** 5108eaf8709SGreg Roach * This module handles the following facts - so don't show them on the "Facts and events" tab. 5118eaf8709SGreg Roach * 51254c7f8dfSGreg Roach * @return Collection 51354c7f8dfSGreg Roach * @return string[] 5148eaf8709SGreg Roach */ 5158eaf8709SGreg Roach public function supportedFacts(): Collection 5168eaf8709SGreg Roach { 5178eaf8709SGreg Roach // We don't actually displaye these facts, but they are displayed 5188eaf8709SGreg Roach // outside the tabs/sidebar systems. This just forces them to be excluded here. 5198eaf8709SGreg Roach return new Collection(['NAME', 'SEX']); 5208eaf8709SGreg Roach } 5213763c3f2SGreg Roach} 522