13763c3f2SGreg Roach<?php 23763c3f2SGreg Roach/** 33763c3f2SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 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 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Date; 210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Fact; 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family; 233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\Functions; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Module; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site; 283763c3f2SGreg Roach 293763c3f2SGreg Roach/** 303763c3f2SGreg Roach * Class IndividualFactsTabModule 313763c3f2SGreg Roach */ 32c1010edaSGreg Roachclass IndividualFactsTabModule extends AbstractModule implements ModuleTabInterface 33c1010edaSGreg Roach{ 343763c3f2SGreg Roach /** {@inheritdoc} */ 358f53f488SRico Sonntag public function getTitle(): string 36c1010edaSGreg Roach { 37bbb76c12SGreg Roach /* I18N: Name of a module/tab on the individual page. */ 38bbb76c12SGreg Roach return I18N::translate('Facts and events'); 393763c3f2SGreg Roach } 403763c3f2SGreg Roach 413763c3f2SGreg Roach /** {@inheritdoc} */ 428f53f488SRico Sonntag public function getDescription(): string 43c1010edaSGreg Roach { 44bbb76c12SGreg Roach /* I18N: Description of the “Facts and events” module */ 45bbb76c12SGreg Roach return I18N::translate('A tab showing the facts and events of an individual.'); 463763c3f2SGreg Roach } 473763c3f2SGreg Roach 483763c3f2SGreg Roach /** {@inheritdoc} */ 498f53f488SRico Sonntag public function defaultTabOrder(): int 50c1010edaSGreg Roach { 513763c3f2SGreg Roach return 10; 523763c3f2SGreg Roach } 533763c3f2SGreg Roach 543763c3f2SGreg Roach /** {@inheritdoc} */ 558f53f488SRico Sonntag public function isGrayedOut(Individual $individual): bool 56c1010edaSGreg Roach { 573763c3f2SGreg Roach return false; 583763c3f2SGreg Roach } 593763c3f2SGreg Roach 603763c3f2SGreg Roach /** {@inheritdoc} */ 619b34404bSGreg Roach public function getTabContent(Individual $individual): string 62c1010edaSGreg Roach { 63*ee727175SGreg Roach // Only include events of close relatives that are between birth and death 64*ee727175SGreg Roach $min_date = $individual->getEstimatedBirthDate(); 65*ee727175SGreg Roach $max_date = $individual->getEstimatedDeathDate(); 66*ee727175SGreg Roach 6713abd6f3SGreg Roach $indifacts = []; 683763c3f2SGreg Roach // The individual’s own facts 69225e381fSGreg Roach foreach ($individual->getFacts() as $fact) { 703763c3f2SGreg Roach switch ($fact->getTag()) { 713763c3f2SGreg Roach case 'SEX': 723763c3f2SGreg Roach case 'NAME': 733763c3f2SGreg Roach case 'SOUR': 743763c3f2SGreg Roach case 'OBJE': 753763c3f2SGreg Roach case 'NOTE': 763763c3f2SGreg Roach case 'FAMC': 773763c3f2SGreg Roach case 'FAMS': 783763c3f2SGreg Roach break; 793763c3f2SGreg Roach default: 80225e381fSGreg Roach if (!array_key_exists('extra_info', Module::getActiveSidebars($individual->getTree())) || !ExtraInformationModule::showFact($fact)) { 813763c3f2SGreg Roach $indifacts[] = $fact; 823763c3f2SGreg Roach } 833763c3f2SGreg Roach break; 843763c3f2SGreg Roach } 853763c3f2SGreg Roach } 863763c3f2SGreg Roach 873763c3f2SGreg Roach // Add spouse-family facts 88225e381fSGreg Roach foreach ($individual->getSpouseFamilies() as $family) { 893763c3f2SGreg Roach foreach ($family->getFacts() as $fact) { 903763c3f2SGreg Roach switch ($fact->getTag()) { 913763c3f2SGreg Roach case 'SOUR': 923763c3f2SGreg Roach case 'NOTE': 933763c3f2SGreg Roach case 'OBJE': 943763c3f2SGreg Roach case 'CHAN': 953763c3f2SGreg Roach case '_UID': 963763c3f2SGreg Roach case 'RIN': 973763c3f2SGreg Roach case 'HUSB': 983763c3f2SGreg Roach case 'WIFE': 993763c3f2SGreg Roach case 'CHIL': 1003763c3f2SGreg Roach break; 1013763c3f2SGreg Roach default: 1023763c3f2SGreg Roach $indifacts[] = $fact; 1033763c3f2SGreg Roach break; 1043763c3f2SGreg Roach } 1053763c3f2SGreg Roach } 106*ee727175SGreg Roach 107225e381fSGreg Roach $spouse = $family->getSpouse($individual); 108*ee727175SGreg Roach 109*ee727175SGreg Roach if ($spouse instanceof Individual) { 110*ee727175SGreg Roach $spouse_facts = self::spouseFacts($individual, $spouse, $min_date, $max_date); 111*ee727175SGreg Roach $indifacts = array_merge($indifacts, $spouse_facts); 1123763c3f2SGreg Roach } 1133763c3f2SGreg Roach 114*ee727175SGreg Roach $child_facts = self::childFacts($individual, $family, '_CHIL', '', $min_date, $max_date); 115*ee727175SGreg Roach $indifacts = array_merge($indifacts, $child_facts); 1163763c3f2SGreg Roach } 117225e381fSGreg Roach 118*ee727175SGreg Roach $parent_facts = self::parentFacts($individual, 1, $min_date, $max_date); 119*ee727175SGreg Roach $associate_facts = self::associateFacts($individual); 120*ee727175SGreg Roach $historical_facts = self::historicalFacts($individual, $min_date, $max_date); 121225e381fSGreg Roach 122*ee727175SGreg Roach $indifacts = array_merge($indifacts, $parent_facts, $associate_facts, $historical_facts); 1233763c3f2SGreg Roach 1243d7a8a4cSGreg Roach Functions::sortFacts($indifacts); 1253763c3f2SGreg Roach 126a8cd57e1SGreg Roach return view('modules/personal_facts/tab', [ 127225e381fSGreg Roach 'can_edit' => $individual->canEdit(), 128*ee727175SGreg Roach 'has_historical_facts' => !empty($historical_facts), 129225e381fSGreg Roach 'individual' => $individual, 130225e381fSGreg Roach 'facts' => $indifacts, 131225e381fSGreg Roach ]); 1323763c3f2SGreg Roach } 1333763c3f2SGreg Roach 134*ee727175SGreg Roach /** 135*ee727175SGreg Roach * Does a relative event occur within a date range (i.e. the individual's lifetime)? 136*ee727175SGreg Roach * 137*ee727175SGreg Roach * @param Fact $fact 138*ee727175SGreg Roach * @param Date $min_date 139*ee727175SGreg Roach * @param Date $max_date 140*ee727175SGreg Roach * 141*ee727175SGreg Roach * @return bool 142*ee727175SGreg Roach */ 143*ee727175SGreg Roach private static function includeFact(Fact $fact, Date $min_date, Date $max_date): bool { 144*ee727175SGreg Roach $fact_date = $fact->getDate(); 145*ee727175SGreg Roach 146*ee727175SGreg Roach return $fact_date->isOK() && Date::compare($min_date, $fact_date) <= 0 && Date::compare($fact_date, $max_date) <= 0; 147*ee727175SGreg Roach } 148*ee727175SGreg Roach 1493763c3f2SGreg Roach /** {@inheritdoc} */ 1508f53f488SRico Sonntag public function hasTabContent(Individual $individual): bool 151c1010edaSGreg Roach { 1523763c3f2SGreg Roach return true; 1533763c3f2SGreg Roach } 1543763c3f2SGreg Roach 1553763c3f2SGreg Roach /** {@inheritdoc} */ 1568f53f488SRico Sonntag public function canLoadAjax(): bool 157c1010edaSGreg Roach { 15815d603e7SGreg Roach return false; 1593763c3f2SGreg Roach } 1603763c3f2SGreg Roach 1613763c3f2SGreg Roach /** 1623763c3f2SGreg Roach * Spouse facts that are shown on an individual’s page. 1633763c3f2SGreg Roach * 1643763c3f2SGreg Roach * @param Individual $individual Show events that occured during the lifetime of this individual 1653763c3f2SGreg Roach * @param Individual $spouse Show events of this individual 166*ee727175SGreg Roach * @param Date $min_date 167*ee727175SGreg Roach * @param Date $max_date 1683763c3f2SGreg Roach * 1693763c3f2SGreg Roach * @return Fact[] 1703763c3f2SGreg Roach */ 171*ee727175SGreg Roach private static function spouseFacts(Individual $individual, Individual $spouse, Date $min_date, Date $max_date): array 172c1010edaSGreg Roach { 1733763c3f2SGreg Roach $SHOW_RELATIVES_EVENTS = $individual->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); 1743763c3f2SGreg Roach 17513abd6f3SGreg Roach $facts = []; 1763763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT_SPOU')) { 1773763c3f2SGreg Roach foreach ($spouse->getFacts(WT_EVENTS_DEAT) as $fact) { 178*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 1793763c3f2SGreg Roach // Convert the event to a close relatives event. 1803763c3f2SGreg Roach $rela_fact = clone($fact); 1813763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_SPOU'); 1823763c3f2SGreg Roach $facts[] = $rela_fact; 1833763c3f2SGreg Roach } 1843763c3f2SGreg Roach } 1853763c3f2SGreg Roach } 1863763c3f2SGreg Roach 1873763c3f2SGreg Roach return $facts; 1883763c3f2SGreg Roach } 1893763c3f2SGreg Roach 1903763c3f2SGreg Roach /** 1913763c3f2SGreg Roach * Get the events of children and grandchildren. 1923763c3f2SGreg Roach * 1933763c3f2SGreg Roach * @param Individual $person 1943763c3f2SGreg Roach * @param Family $family 1953763c3f2SGreg Roach * @param string $option 1963763c3f2SGreg Roach * @param string $relation 197*ee727175SGreg Roach * @param Date $min_date 198*ee727175SGreg Roach * @param Date $max_date 1993763c3f2SGreg Roach * 2003763c3f2SGreg Roach * @return Fact[] 2013763c3f2SGreg Roach */ 202*ee727175SGreg Roach private static function childFacts(Individual $person, Family $family, $option, $relation, Date $min_date, Date $max_date): array 203c1010edaSGreg Roach { 2043763c3f2SGreg Roach $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); 2053763c3f2SGreg Roach 20613abd6f3SGreg Roach $facts = []; 2073763c3f2SGreg Roach 2083763c3f2SGreg Roach // Deal with recursion. 2093763c3f2SGreg Roach switch ($option) { 2103763c3f2SGreg Roach case '_CHIL': 2113763c3f2SGreg Roach // Add grandchildren 2123763c3f2SGreg Roach foreach ($family->getChildren() as $child) { 2133763c3f2SGreg Roach foreach ($child->getSpouseFamilies() as $cfamily) { 2143763c3f2SGreg Roach switch ($child->getSex()) { 2153763c3f2SGreg Roach case 'M': 216*ee727175SGreg Roach foreach (self::childFacts($person, $cfamily, '_GCHI', 'son', $min_date, $max_date) as $fact) { 2173763c3f2SGreg Roach $facts[] = $fact; 2183763c3f2SGreg Roach } 2193763c3f2SGreg Roach break; 2203763c3f2SGreg Roach case 'F': 221*ee727175SGreg Roach foreach (self::childFacts($person, $cfamily, '_GCHI', 'dau', $min_date, $max_date) as $fact) { 2223763c3f2SGreg Roach $facts[] = $fact; 2233763c3f2SGreg Roach } 2243763c3f2SGreg Roach break; 2253763c3f2SGreg Roach default: 226*ee727175SGreg Roach foreach (self::childFacts($person, $cfamily, '_GCHI', 'chi', $min_date, $max_date) as $fact) { 2273763c3f2SGreg Roach $facts[] = $fact; 2283763c3f2SGreg Roach } 2293763c3f2SGreg Roach break; 2303763c3f2SGreg Roach } 2313763c3f2SGreg Roach } 2323763c3f2SGreg Roach } 2333763c3f2SGreg Roach break; 2343763c3f2SGreg Roach } 2353763c3f2SGreg Roach 2363763c3f2SGreg Roach // For each child in the family 2373763c3f2SGreg Roach foreach ($family->getChildren() as $child) { 2383763c3f2SGreg Roach if ($child->getXref() == $person->getXref()) { 2393763c3f2SGreg Roach // We are not our own sibling! 2403763c3f2SGreg Roach continue; 2413763c3f2SGreg Roach } 2423763c3f2SGreg Roach // add child’s birth 2433763c3f2SGreg Roach if (strpos($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { 2443763c3f2SGreg Roach foreach ($child->getFacts(WT_EVENTS_BIRT) as $fact) { 2453763c3f2SGreg Roach // Always show _BIRT_CHIL, even if the dates are not known 246*ee727175SGreg Roach if ($option == '_CHIL' || self::includeFact($fact, $min_date, $max_date)) { 2473763c3f2SGreg Roach if ($option == '_GCHI' && $relation == 'dau') { 2483763c3f2SGreg Roach // Convert the event to a close relatives event. 2493763c3f2SGreg Roach $rela_fact = clone($fact); 2503763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); 2513763c3f2SGreg Roach $facts[] = $rela_fact; 2523763c3f2SGreg Roach } elseif ($option == '_GCHI' && $relation == 'son') { 2533763c3f2SGreg Roach // Convert the event to a close relatives event. 2543763c3f2SGreg Roach $rela_fact = clone($fact); 2553763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); 2563763c3f2SGreg Roach $facts[] = $rela_fact; 2573763c3f2SGreg Roach } else { 2583763c3f2SGreg Roach // Convert the event to a close relatives event. 2593763c3f2SGreg Roach $rela_fact = clone($fact); 2603763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . $option); 2613763c3f2SGreg Roach $facts[] = $rela_fact; 2623763c3f2SGreg Roach } 2633763c3f2SGreg Roach } 2643763c3f2SGreg Roach } 2653763c3f2SGreg Roach } 2663763c3f2SGreg Roach // add child’s death 2673763c3f2SGreg Roach if (strpos($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { 2683763c3f2SGreg Roach foreach ($child->getFacts(WT_EVENTS_DEAT) as $fact) { 269*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 2703763c3f2SGreg Roach if ($option == '_GCHI' && $relation == 'dau') { 2713763c3f2SGreg Roach // Convert the event to a close relatives event. 2723763c3f2SGreg Roach $rela_fact = clone($fact); 2733763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); 2743763c3f2SGreg Roach $facts[] = $rela_fact; 2753763c3f2SGreg Roach } elseif ($option == '_GCHI' && $relation == 'son') { 2763763c3f2SGreg Roach // Convert the event to a close relatives event. 2773763c3f2SGreg Roach $rela_fact = clone($fact); 2783763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); 2793763c3f2SGreg Roach $facts[] = $rela_fact; 2803763c3f2SGreg Roach } else { 2813763c3f2SGreg Roach // Convert the event to a close relatives event. 2823763c3f2SGreg Roach $rela_fact = clone($fact); 2833763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . $option); 2843763c3f2SGreg Roach $facts[] = $rela_fact; 2853763c3f2SGreg Roach } 2863763c3f2SGreg Roach } 2873763c3f2SGreg Roach } 2883763c3f2SGreg Roach } 2893763c3f2SGreg Roach // add child’s marriage 2903763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) { 2913763c3f2SGreg Roach foreach ($child->getSpouseFamilies() as $sfamily) { 292*ee727175SGreg Roach foreach ($sfamily->getFacts('MARR') as $fact) { 293*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 2943763c3f2SGreg Roach if ($option == '_GCHI' && $relation == 'dau') { 2953763c3f2SGreg Roach // Convert the event to a close relatives event. 2963763c3f2SGreg Roach $rela_fact = clone($fact); 2973763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); 2983763c3f2SGreg Roach $facts[] = $rela_fact; 2993763c3f2SGreg Roach } elseif ($option == '_GCHI' && $relation == 'son') { 3003763c3f2SGreg Roach // Convert the event to a close relatives event. 3013763c3f2SGreg Roach $rela_fact = clone($fact); 3023763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); 3033763c3f2SGreg Roach $facts[] = $rela_fact; 3043763c3f2SGreg Roach } else { 3053763c3f2SGreg Roach // Convert the event to a close relatives event. 3063763c3f2SGreg Roach $rela_fact = clone($fact); 3073763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . $option); 3083763c3f2SGreg Roach $facts[] = $rela_fact; 3093763c3f2SGreg Roach } 3103763c3f2SGreg Roach } 3113763c3f2SGreg Roach } 3123763c3f2SGreg Roach } 3133763c3f2SGreg Roach } 3143763c3f2SGreg Roach } 3153763c3f2SGreg Roach 3163763c3f2SGreg Roach return $facts; 3173763c3f2SGreg Roach } 3183763c3f2SGreg Roach 3193763c3f2SGreg Roach /** 3203763c3f2SGreg Roach * Get the events of parents and grandparents. 3213763c3f2SGreg Roach * 3223763c3f2SGreg Roach * @param Individual $person 323cbc1590aSGreg Roach * @param int $sosa 324*ee727175SGreg Roach * @param Date $min_date 325*ee727175SGreg Roach * @param Date $max_date 3263763c3f2SGreg Roach * 3273763c3f2SGreg Roach * @return Fact[] 3283763c3f2SGreg Roach */ 329*ee727175SGreg Roach private static function parentFacts(Individual $person, $sosa, Date $min_date, Date $max_date): array 330c1010edaSGreg Roach { 3313763c3f2SGreg Roach $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); 3323763c3f2SGreg Roach 33313abd6f3SGreg Roach $facts = []; 3343763c3f2SGreg Roach 3353763c3f2SGreg Roach if ($sosa == 1) { 3363763c3f2SGreg Roach foreach ($person->getChildFamilies() as $family) { 3373763c3f2SGreg Roach // Add siblings 338*ee727175SGreg Roach foreach (self::childFacts($person, $family, '_SIBL', '', $min_date, $max_date) as $fact) { 3393763c3f2SGreg Roach $facts[] = $fact; 3403763c3f2SGreg Roach } 3413763c3f2SGreg Roach foreach ($family->getSpouses() as $spouse) { 3423763c3f2SGreg Roach foreach ($spouse->getSpouseFamilies() as $sfamily) { 3433763c3f2SGreg Roach if ($family !== $sfamily) { 3443763c3f2SGreg Roach // Add half-siblings 345*ee727175SGreg Roach foreach (self::childFacts($person, $sfamily, '_HSIB', '', $min_date, $max_date) as $fact) { 3463763c3f2SGreg Roach $facts[] = $fact; 3473763c3f2SGreg Roach } 3483763c3f2SGreg Roach } 3493763c3f2SGreg Roach } 3503763c3f2SGreg Roach // Add grandparents 351*ee727175SGreg Roach foreach (self::parentFacts($spouse, $spouse->getSex() == 'F' ? 3 : 2, $min_date, $max_date) as $fact) { 3523763c3f2SGreg Roach $facts[] = $fact; 3533763c3f2SGreg Roach } 3543763c3f2SGreg Roach } 3553763c3f2SGreg Roach } 3563763c3f2SGreg Roach 3573763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_MARR_PARE')) { 3583763c3f2SGreg Roach // add father/mother marriages 3593763c3f2SGreg Roach foreach ($person->getChildFamilies() as $sfamily) { 360*ee727175SGreg Roach foreach ($sfamily->getFacts('MARR') as $fact) { 361*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 3623763c3f2SGreg Roach // marriage of parents (to each other) 3633763c3f2SGreg Roach $rela_fact = clone($fact); 3643763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_FAMC'); 3653763c3f2SGreg Roach $facts[] = $rela_fact; 3663763c3f2SGreg Roach } 3673763c3f2SGreg Roach } 3683763c3f2SGreg Roach } 3693763c3f2SGreg Roach foreach ($person->getChildStepFamilies() as $sfamily) { 370*ee727175SGreg Roach foreach ($sfamily->getFacts('MARR') as $fact) { 371*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 3723763c3f2SGreg Roach // marriage of a parent (to another spouse) 3733763c3f2SGreg Roach // Convert the event to a close relatives event 3743763c3f2SGreg Roach $rela_fact = clone($fact); 3753763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); 3763763c3f2SGreg Roach $facts[] = $rela_fact; 3773763c3f2SGreg Roach } 3783763c3f2SGreg Roach } 3793763c3f2SGreg Roach } 3803763c3f2SGreg Roach } 3813763c3f2SGreg Roach } 3823763c3f2SGreg Roach 3833763c3f2SGreg Roach foreach ($person->getChildFamilies() as $family) { 3843763c3f2SGreg Roach foreach ($family->getSpouses() as $parent) { 3853763c3f2SGreg Roach if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT' . ($sosa == 1 ? '_PARE' : '_GPAR'))) { 3863763c3f2SGreg Roach foreach ($parent->getFacts(WT_EVENTS_DEAT) as $fact) { 387*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 3883763c3f2SGreg Roach switch ($sosa) { 3893763c3f2SGreg Roach case 1: 3903763c3f2SGreg Roach // Convert the event to a close relatives event. 3913763c3f2SGreg Roach $rela_fact = clone($fact); 3923763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); 3933763c3f2SGreg Roach $facts[] = $rela_fact; 3943763c3f2SGreg Roach break; 3953763c3f2SGreg Roach case 2: 3963763c3f2SGreg Roach // Convert the event to a close relatives event 3973763c3f2SGreg Roach $rela_fact = clone($fact); 3983763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GPA1'); 3993763c3f2SGreg Roach $facts[] = $rela_fact; 4003763c3f2SGreg Roach break; 4013763c3f2SGreg Roach case 3: 4023763c3f2SGreg Roach // Convert the event to a close relatives event 4033763c3f2SGreg Roach $rela_fact = clone($fact); 4043763c3f2SGreg Roach $rela_fact->setTag('_' . $fact->getTag() . '_GPA2'); 4053763c3f2SGreg Roach $facts[] = $rela_fact; 4063763c3f2SGreg Roach break; 4073763c3f2SGreg Roach } 4083763c3f2SGreg Roach } 4093763c3f2SGreg Roach } 4103763c3f2SGreg Roach } 4113763c3f2SGreg Roach } 4123763c3f2SGreg Roach } 4133763c3f2SGreg Roach 4143763c3f2SGreg Roach return $facts; 4153763c3f2SGreg Roach } 4163763c3f2SGreg Roach 4173763c3f2SGreg Roach /** 4183763c3f2SGreg Roach * Get any historical events. 4193763c3f2SGreg Roach * 4203763c3f2SGreg Roach * @param Individual $person 421*ee727175SGreg Roach * @param Date $min_date 422*ee727175SGreg Roach * @param Date $max_date 4233763c3f2SGreg Roach * 4243763c3f2SGreg Roach * @return Fact[] 4253763c3f2SGreg Roach */ 426*ee727175SGreg Roach private static function historicalFacts(Individual $person, Date $min_date, Date $max_date): array 427c1010edaSGreg Roach { 4283763c3f2SGreg Roach $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); 4293763c3f2SGreg Roach 43013abd6f3SGreg Roach $facts = []; 4313763c3f2SGreg Roach 4323763c3f2SGreg Roach if ($SHOW_RELATIVES_EVENTS) { 4333763c3f2SGreg Roach if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) { 43413abd6f3SGreg Roach $histo = []; 4353763c3f2SGreg Roach require Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php'; 4363763c3f2SGreg Roach foreach ($histo as $hist) { 4373763c3f2SGreg Roach $fact = new Fact($hist, $person, 'histo'); 438*ee727175SGreg Roach 439*ee727175SGreg Roach if (self::includeFact($fact, $min_date, $max_date)) { 4403763c3f2SGreg Roach $facts[] = $fact; 4413763c3f2SGreg Roach } 4423763c3f2SGreg Roach } 4433763c3f2SGreg Roach } 4443763c3f2SGreg Roach } 4453763c3f2SGreg Roach 4463763c3f2SGreg Roach return $facts; 4473763c3f2SGreg Roach } 4483763c3f2SGreg Roach 4493763c3f2SGreg Roach /** 4503763c3f2SGreg Roach * Get the events of associates. 4513763c3f2SGreg Roach * 4523763c3f2SGreg Roach * @param Individual $person 4533763c3f2SGreg Roach * 4543763c3f2SGreg Roach * @return Fact[] 4553763c3f2SGreg Roach */ 4568f53f488SRico Sonntag private static function associateFacts(Individual $person): array 457c1010edaSGreg Roach { 45813abd6f3SGreg Roach $facts = []; 4593763c3f2SGreg Roach 460*ee727175SGreg Roach /** @var Individual[] $associates */ 4613763c3f2SGreg Roach $associates = array_merge( 4623763c3f2SGreg Roach $person->linkedIndividuals('ASSO'), 4633763c3f2SGreg Roach $person->linkedIndividuals('_ASSO'), 4643763c3f2SGreg Roach $person->linkedFamilies('ASSO'), 4653763c3f2SGreg Roach $person->linkedFamilies('_ASSO') 4663763c3f2SGreg Roach ); 4673763c3f2SGreg Roach foreach ($associates as $associate) { 4683763c3f2SGreg Roach foreach ($associate->getFacts() as $fact) { 4693763c3f2SGreg Roach $arec = $fact->getAttribute('_ASSO'); 4703763c3f2SGreg Roach if (!$arec) { 4713763c3f2SGreg Roach $arec = $fact->getAttribute('ASSO'); 4723763c3f2SGreg Roach } 4733763c3f2SGreg Roach if ($arec && trim($arec, '@') === $person->getXref()) { 4743763c3f2SGreg Roach // Extract the important details from the fact 4753763c3f2SGreg Roach $factrec = '1 ' . $fact->getTag(); 4763763c3f2SGreg Roach if (preg_match('/\n2 DATE .*/', $fact->getGedcom(), $match)) { 4773763c3f2SGreg Roach $factrec .= $match[0]; 4783763c3f2SGreg Roach } 4793763c3f2SGreg Roach if (preg_match('/\n2 PLAC .*/', $fact->getGedcom(), $match)) { 4803763c3f2SGreg Roach $factrec .= $match[0]; 4813763c3f2SGreg Roach } 4823763c3f2SGreg Roach if ($associate instanceof Family) { 4833763c3f2SGreg Roach foreach ($associate->getSpouses() as $spouse) { 4843763c3f2SGreg Roach $factrec .= "\n2 _ASSO @" . $spouse->getXref() . '@'; 4853763c3f2SGreg Roach } 4863763c3f2SGreg Roach } else { 4873763c3f2SGreg Roach $factrec .= "\n2 _ASSO @" . $associate->getXref() . '@'; 4883763c3f2SGreg Roach } 4893763c3f2SGreg Roach $facts[] = new Fact($factrec, $associate, 'asso'); 4903763c3f2SGreg Roach } 4913763c3f2SGreg Roach } 4923763c3f2SGreg Roach } 4933763c3f2SGreg Roach 4943763c3f2SGreg Roach return $facts; 4953763c3f2SGreg Roach } 4963763c3f2SGreg Roach} 497