xref: /webtrees/app/Module/IndividualFactsTabModule.php (revision cbf4b7fa194b4e336add2747abfccb05fbb0f4da)
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
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Date;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Fact;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family;
233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\Functions;
248d0ebef0SGreg Roachuse Fisharebest\Webtrees\Gedcom;
250e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual;
270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Module;
280e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
293763c3f2SGreg Roach
303763c3f2SGreg Roach/**
313763c3f2SGreg Roach * Class IndividualFactsTabModule
323763c3f2SGreg Roach */
3349a243cbSGreg Roachclass IndividualFactsTabModule extends AbstractModule implements ModuleInterface, ModuleTabInterface
34c1010edaSGreg Roach{
3549a243cbSGreg Roach    use ModuleTabTrait;
3649a243cbSGreg Roach
373763c3f2SGreg Roach    /** {@inheritdoc} */
3849a243cbSGreg Roach    public function title(): string
39c1010edaSGreg Roach    {
40bbb76c12SGreg Roach        /* I18N: Name of a module/tab on the individual page. */
41bbb76c12SGreg Roach        return I18N::translate('Facts and events');
423763c3f2SGreg Roach    }
433763c3f2SGreg Roach
443763c3f2SGreg Roach    /** {@inheritdoc} */
4549a243cbSGreg Roach    public function description(): string
46c1010edaSGreg Roach    {
47bbb76c12SGreg Roach        /* I18N: Description of the “Facts and events” module */
48bbb76c12SGreg Roach        return I18N::translate('A tab showing the facts and events of an individual.');
493763c3f2SGreg Roach    }
503763c3f2SGreg Roach
5149a243cbSGreg Roach    /**
5249a243cbSGreg Roach     * The default position for this tab.  It can be changed in the control panel.
5349a243cbSGreg Roach     *
5449a243cbSGreg Roach     * @return int
5549a243cbSGreg Roach     */
56*cbf4b7faSGreg Roach    public function defaultTabOrder(): int
57*cbf4b7faSGreg Roach    {
5849a243cbSGreg Roach        return 20;
593763c3f2SGreg Roach    }
603763c3f2SGreg Roach
613763c3f2SGreg Roach    /** {@inheritdoc} */
628f53f488SRico Sonntag    public function isGrayedOut(Individual $individual): bool
63c1010edaSGreg Roach    {
643763c3f2SGreg Roach        return false;
653763c3f2SGreg Roach    }
663763c3f2SGreg Roach
673763c3f2SGreg Roach    /** {@inheritdoc} */
689b34404bSGreg Roach    public function getTabContent(Individual $individual): string
69c1010edaSGreg Roach    {
70ee727175SGreg Roach        // Only include events of close relatives that are between birth and death
71ee727175SGreg Roach        $min_date = $individual->getEstimatedBirthDate();
72ee727175SGreg Roach        $max_date = $individual->getEstimatedDeathDate();
73ee727175SGreg Roach
7413abd6f3SGreg Roach        $indifacts = [];
753763c3f2SGreg Roach        // The individual’s own facts
7630158ae7SGreg Roach        foreach ($individual->facts() as $fact) {
773763c3f2SGreg Roach            switch ($fact->getTag()) {
783763c3f2SGreg Roach                case 'SEX':
793763c3f2SGreg Roach                case 'NAME':
803763c3f2SGreg Roach                case 'SOUR':
813763c3f2SGreg Roach                case 'OBJE':
823763c3f2SGreg Roach                case 'NOTE':
833763c3f2SGreg Roach                case 'FAMC':
843763c3f2SGreg Roach                case 'FAMS':
853763c3f2SGreg Roach                    break;
8649a243cbSGreg Roach
873763c3f2SGreg Roach                default:
8849a243cbSGreg Roach                    $use_extra_info_module = Module::activeSidebars($individual->tree())
8949a243cbSGreg Roach                        ->filter(function (ModuleInterface $module): bool {
9049a243cbSGreg Roach                            return $module instanceof ExtraInformationModule;
9149a243cbSGreg Roach                        })->isNotEmpty();
9249a243cbSGreg Roach
9349a243cbSGreg Roach                    if (!$use_extra_info_module || !ExtraInformationModule::showFact($fact)) {
943763c3f2SGreg Roach                        $indifacts[] = $fact;
953763c3f2SGreg Roach                    }
963763c3f2SGreg Roach                    break;
973763c3f2SGreg Roach            }
983763c3f2SGreg Roach        }
993763c3f2SGreg Roach
1003763c3f2SGreg Roach        // Add spouse-family facts
101225e381fSGreg Roach        foreach ($individual->getSpouseFamilies() as $family) {
10230158ae7SGreg Roach            foreach ($family->facts() as $fact) {
1033763c3f2SGreg Roach                switch ($fact->getTag()) {
1043763c3f2SGreg Roach                    case 'SOUR':
1053763c3f2SGreg Roach                    case 'NOTE':
1063763c3f2SGreg Roach                    case 'OBJE':
1073763c3f2SGreg Roach                    case 'CHAN':
1083763c3f2SGreg Roach                    case '_UID':
1093763c3f2SGreg Roach                    case 'RIN':
1103763c3f2SGreg Roach                    case 'HUSB':
1113763c3f2SGreg Roach                    case 'WIFE':
1123763c3f2SGreg Roach                    case 'CHIL':
1133763c3f2SGreg Roach                        break;
1143763c3f2SGreg Roach                    default:
1153763c3f2SGreg Roach                        $indifacts[] = $fact;
1163763c3f2SGreg Roach                        break;
1173763c3f2SGreg Roach                }
1183763c3f2SGreg Roach            }
119ee727175SGreg Roach
120225e381fSGreg Roach            $spouse = $family->getSpouse($individual);
121ee727175SGreg Roach
122ee727175SGreg Roach            if ($spouse instanceof Individual) {
123ee727175SGreg Roach                $spouse_facts = self::spouseFacts($individual, $spouse, $min_date, $max_date);
124ee727175SGreg Roach                $indifacts    = array_merge($indifacts, $spouse_facts);
1253763c3f2SGreg Roach            }
1263763c3f2SGreg Roach
127ee727175SGreg Roach            $child_facts = self::childFacts($individual, $family, '_CHIL', '', $min_date, $max_date);
128ee727175SGreg Roach            $indifacts   = array_merge($indifacts, $child_facts);
1293763c3f2SGreg Roach        }
130225e381fSGreg Roach
131ee727175SGreg Roach        $parent_facts     = self::parentFacts($individual, 1, $min_date, $max_date);
132ee727175SGreg Roach        $associate_facts  = self::associateFacts($individual);
133ee727175SGreg Roach        $historical_facts = self::historicalFacts($individual, $min_date, $max_date);
134225e381fSGreg Roach
135ee727175SGreg Roach        $indifacts = array_merge($indifacts, $parent_facts, $associate_facts, $historical_facts);
1363763c3f2SGreg Roach
1373d7a8a4cSGreg Roach        Functions::sortFacts($indifacts);
1383763c3f2SGreg Roach
139a8cd57e1SGreg Roach        return view('modules/personal_facts/tab', [
140225e381fSGreg Roach            'can_edit'             => $individual->canEdit(),
141ee727175SGreg Roach            'has_historical_facts' => !empty($historical_facts),
142225e381fSGreg Roach            'individual'           => $individual,
143225e381fSGreg Roach            'facts'                => $indifacts,
144225e381fSGreg Roach        ]);
1453763c3f2SGreg Roach    }
1463763c3f2SGreg Roach
147ee727175SGreg Roach    /**
148ee727175SGreg Roach     * Does a relative event occur within a date range (i.e. the individual's lifetime)?
149ee727175SGreg Roach     *
150ee727175SGreg Roach     * @param Fact $fact
151ee727175SGreg Roach     * @param Date $min_date
152ee727175SGreg Roach     * @param Date $max_date
153ee727175SGreg Roach     *
154ee727175SGreg Roach     * @return bool
155ee727175SGreg Roach     */
156b3b1d905SGreg Roach    private static function includeFact(Fact $fact, Date $min_date, Date $max_date): bool
157b3b1d905SGreg Roach    {
1582decada7SGreg Roach        $fact_date = $fact->date();
159ee727175SGreg Roach
160ee727175SGreg Roach        return $fact_date->isOK() && Date::compare($min_date, $fact_date) <= 0 && Date::compare($fact_date, $max_date) <= 0;
161ee727175SGreg Roach    }
162ee727175SGreg Roach
1633763c3f2SGreg Roach    /** {@inheritdoc} */
1648f53f488SRico Sonntag    public function hasTabContent(Individual $individual): bool
165c1010edaSGreg Roach    {
1663763c3f2SGreg Roach        return true;
1673763c3f2SGreg Roach    }
1683763c3f2SGreg Roach
1693763c3f2SGreg Roach    /** {@inheritdoc} */
1708f53f488SRico Sonntag    public function canLoadAjax(): bool
171c1010edaSGreg Roach    {
17215d603e7SGreg Roach        return false;
1733763c3f2SGreg Roach    }
1743763c3f2SGreg Roach
1753763c3f2SGreg Roach    /**
1763763c3f2SGreg Roach     * Spouse facts that are shown on an individual’s page.
1773763c3f2SGreg Roach     *
1783763c3f2SGreg Roach     * @param Individual $individual Show events that occured during the lifetime of this individual
1793763c3f2SGreg Roach     * @param Individual $spouse     Show events of this individual
180ee727175SGreg Roach     * @param Date       $min_date
181ee727175SGreg Roach     * @param Date       $max_date
1823763c3f2SGreg Roach     *
1833763c3f2SGreg Roach     * @return Fact[]
1843763c3f2SGreg Roach     */
185ee727175SGreg Roach    private static function spouseFacts(Individual $individual, Individual $spouse, Date $min_date, Date $max_date): array
186c1010edaSGreg Roach    {
187f4afa648SGreg Roach        $SHOW_RELATIVES_EVENTS = $individual->tree()->getPreference('SHOW_RELATIVES_EVENTS');
1883763c3f2SGreg Roach
18913abd6f3SGreg Roach        $facts = [];
1903763c3f2SGreg Roach        if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT_SPOU')) {
1918d0ebef0SGreg Roach            foreach ($spouse->facts(Gedcom::DEATH_EVENTS) as $fact) {
192ee727175SGreg Roach                if (self::includeFact($fact, $min_date, $max_date)) {
1933763c3f2SGreg Roach                    // Convert the event to a close relatives event.
1943763c3f2SGreg Roach                    $rela_fact = clone($fact);
1953763c3f2SGreg Roach                    $rela_fact->setTag('_' . $fact->getTag() . '_SPOU');
1963763c3f2SGreg Roach                    $facts[] = $rela_fact;
1973763c3f2SGreg Roach                }
1983763c3f2SGreg Roach            }
1993763c3f2SGreg Roach        }
2003763c3f2SGreg Roach
2013763c3f2SGreg Roach        return $facts;
2023763c3f2SGreg Roach    }
2033763c3f2SGreg Roach
2043763c3f2SGreg Roach    /**
2053763c3f2SGreg Roach     * Get the events of children and grandchildren.
2063763c3f2SGreg Roach     *
2073763c3f2SGreg Roach     * @param Individual $person
2083763c3f2SGreg Roach     * @param Family     $family
2093763c3f2SGreg Roach     * @param string     $option
2103763c3f2SGreg Roach     * @param string     $relation
211ee727175SGreg Roach     * @param Date       $min_date
212ee727175SGreg Roach     * @param Date       $max_date
2133763c3f2SGreg Roach     *
2143763c3f2SGreg Roach     * @return Fact[]
2153763c3f2SGreg Roach     */
216ee727175SGreg Roach    private static function childFacts(Individual $person, Family $family, $option, $relation, Date $min_date, Date $max_date): array
217c1010edaSGreg Roach    {
218f4afa648SGreg Roach        $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS');
2193763c3f2SGreg Roach
22013abd6f3SGreg Roach        $facts = [];
2213763c3f2SGreg Roach
2223763c3f2SGreg Roach        // Deal with recursion.
2233763c3f2SGreg Roach        switch ($option) {
2243763c3f2SGreg Roach            case '_CHIL':
2253763c3f2SGreg Roach                // Add grandchildren
2263763c3f2SGreg Roach                foreach ($family->getChildren() as $child) {
2273763c3f2SGreg Roach                    foreach ($child->getSpouseFamilies() as $cfamily) {
2283763c3f2SGreg Roach                        switch ($child->getSex()) {
2293763c3f2SGreg Roach                            case 'M':
230ee727175SGreg Roach                                foreach (self::childFacts($person, $cfamily, '_GCHI', 'son', $min_date, $max_date) as $fact) {
2313763c3f2SGreg Roach                                    $facts[] = $fact;
2323763c3f2SGreg Roach                                }
2333763c3f2SGreg Roach                                break;
2343763c3f2SGreg Roach                            case 'F':
235ee727175SGreg Roach                                foreach (self::childFacts($person, $cfamily, '_GCHI', 'dau', $min_date, $max_date) as $fact) {
2363763c3f2SGreg Roach                                    $facts[] = $fact;
2373763c3f2SGreg Roach                                }
2383763c3f2SGreg Roach                                break;
2393763c3f2SGreg Roach                            default:
240ee727175SGreg Roach                                foreach (self::childFacts($person, $cfamily, '_GCHI', 'chi', $min_date, $max_date) as $fact) {
2413763c3f2SGreg Roach                                    $facts[] = $fact;
2423763c3f2SGreg Roach                                }
2433763c3f2SGreg Roach                                break;
2443763c3f2SGreg Roach                        }
2453763c3f2SGreg Roach                    }
2463763c3f2SGreg Roach                }
2473763c3f2SGreg Roach                break;
2483763c3f2SGreg Roach        }
2493763c3f2SGreg Roach
2503763c3f2SGreg Roach        // For each child in the family
2513763c3f2SGreg Roach        foreach ($family->getChildren() as $child) {
252c0935879SGreg Roach            if ($child->xref() == $person->xref()) {
2533763c3f2SGreg Roach                // We are not our own sibling!
2543763c3f2SGreg Roach                continue;
2553763c3f2SGreg Roach            }
2563763c3f2SGreg Roach            // add child’s birth
2573763c3f2SGreg Roach            if (strpos($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option)) !== false) {
2588d0ebef0SGreg Roach                foreach ($child->facts(Gedcom::BIRTH_EVENTS) as $fact) {
2593763c3f2SGreg Roach                    // Always show _BIRT_CHIL, even if the dates are not known
260ee727175SGreg Roach                    if ($option == '_CHIL' || self::includeFact($fact, $min_date, $max_date)) {
2613763c3f2SGreg Roach                        if ($option == '_GCHI' && $relation == 'dau') {
2623763c3f2SGreg Roach                            // Convert the event to a close relatives event.
2633763c3f2SGreg Roach                            $rela_fact = clone($fact);
2643763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH1');
2653763c3f2SGreg Roach                            $facts[] = $rela_fact;
2663763c3f2SGreg Roach                        } elseif ($option == '_GCHI' && $relation == 'son') {
2673763c3f2SGreg Roach                            // Convert the event to a close relatives event.
2683763c3f2SGreg Roach                            $rela_fact = clone($fact);
2693763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH2');
2703763c3f2SGreg Roach                            $facts[] = $rela_fact;
2713763c3f2SGreg Roach                        } else {
2723763c3f2SGreg Roach                            // Convert the event to a close relatives event.
2733763c3f2SGreg Roach                            $rela_fact = clone($fact);
2743763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . $option);
2753763c3f2SGreg Roach                            $facts[] = $rela_fact;
2763763c3f2SGreg Roach                        }
2773763c3f2SGreg Roach                    }
2783763c3f2SGreg Roach                }
2793763c3f2SGreg Roach            }
2803763c3f2SGreg Roach            // add child’s death
2813763c3f2SGreg Roach            if (strpos($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option)) !== false) {
2828d0ebef0SGreg Roach                foreach ($child->facts(Gedcom::DEATH_EVENTS) as $fact) {
283ee727175SGreg Roach                    if (self::includeFact($fact, $min_date, $max_date)) {
2843763c3f2SGreg Roach                        if ($option == '_GCHI' && $relation == 'dau') {
2853763c3f2SGreg Roach                            // Convert the event to a close relatives event.
2863763c3f2SGreg Roach                            $rela_fact = clone($fact);
2873763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH1');
2883763c3f2SGreg Roach                            $facts[] = $rela_fact;
2893763c3f2SGreg Roach                        } elseif ($option == '_GCHI' && $relation == 'son') {
2903763c3f2SGreg Roach                            // Convert the event to a close relatives event.
2913763c3f2SGreg Roach                            $rela_fact = clone($fact);
2923763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . '_GCH2');
2933763c3f2SGreg Roach                            $facts[] = $rela_fact;
2943763c3f2SGreg Roach                        } else {
2953763c3f2SGreg Roach                            // Convert the event to a close relatives event.
2963763c3f2SGreg Roach                            $rela_fact = clone($fact);
2973763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . $option);
2983763c3f2SGreg Roach                            $facts[] = $rela_fact;
2993763c3f2SGreg Roach                        }
3003763c3f2SGreg Roach                    }
3013763c3f2SGreg Roach                }
3023763c3f2SGreg Roach            }
3033763c3f2SGreg Roach            // add child’s marriage
3043763c3f2SGreg Roach            if (strstr($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) {
3053763c3f2SGreg Roach                foreach ($child->getSpouseFamilies() as $sfamily) {
3068d0ebef0SGreg Roach                    foreach ($sfamily->facts(['MARR']) as $fact) {
307ee727175SGreg Roach                        if (self::includeFact($fact, $min_date, $max_date)) {
3083763c3f2SGreg Roach                            if ($option == '_GCHI' && $relation == 'dau') {
3093763c3f2SGreg Roach                                // Convert the event to a close relatives event.
3103763c3f2SGreg Roach                                $rela_fact = clone($fact);
3113763c3f2SGreg Roach                                $rela_fact->setTag('_' . $fact->getTag() . '_GCH1');
3123763c3f2SGreg Roach                                $facts[] = $rela_fact;
3133763c3f2SGreg Roach                            } elseif ($option == '_GCHI' && $relation == 'son') {
3143763c3f2SGreg Roach                                // Convert the event to a close relatives event.
3153763c3f2SGreg Roach                                $rela_fact = clone($fact);
3163763c3f2SGreg Roach                                $rela_fact->setTag('_' . $fact->getTag() . '_GCH2');
3173763c3f2SGreg Roach                                $facts[] = $rela_fact;
3183763c3f2SGreg Roach                            } else {
3193763c3f2SGreg Roach                                // Convert the event to a close relatives event.
3203763c3f2SGreg Roach                                $rela_fact = clone($fact);
3213763c3f2SGreg Roach                                $rela_fact->setTag('_' . $fact->getTag() . $option);
3223763c3f2SGreg Roach                                $facts[] = $rela_fact;
3233763c3f2SGreg Roach                            }
3243763c3f2SGreg Roach                        }
3253763c3f2SGreg Roach                    }
3263763c3f2SGreg Roach                }
3273763c3f2SGreg Roach            }
3283763c3f2SGreg Roach        }
3293763c3f2SGreg Roach
3303763c3f2SGreg Roach        return $facts;
3313763c3f2SGreg Roach    }
3323763c3f2SGreg Roach
3333763c3f2SGreg Roach    /**
3343763c3f2SGreg Roach     * Get the events of parents and grandparents.
3353763c3f2SGreg Roach     *
3363763c3f2SGreg Roach     * @param Individual $person
337cbc1590aSGreg Roach     * @param int        $sosa
338ee727175SGreg Roach     * @param Date       $min_date
339ee727175SGreg Roach     * @param Date       $max_date
3403763c3f2SGreg Roach     *
3413763c3f2SGreg Roach     * @return Fact[]
3423763c3f2SGreg Roach     */
343ee727175SGreg Roach    private static function parentFacts(Individual $person, $sosa, Date $min_date, Date $max_date): array
344c1010edaSGreg Roach    {
345f4afa648SGreg Roach        $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS');
3463763c3f2SGreg Roach
34713abd6f3SGreg Roach        $facts = [];
3483763c3f2SGreg Roach
3493763c3f2SGreg Roach        if ($sosa == 1) {
3503763c3f2SGreg Roach            foreach ($person->getChildFamilies() as $family) {
3513763c3f2SGreg Roach                // Add siblings
352ee727175SGreg Roach                foreach (self::childFacts($person, $family, '_SIBL', '', $min_date, $max_date) as $fact) {
3533763c3f2SGreg Roach                    $facts[] = $fact;
3543763c3f2SGreg Roach                }
3553763c3f2SGreg Roach                foreach ($family->getSpouses() as $spouse) {
3563763c3f2SGreg Roach                    foreach ($spouse->getSpouseFamilies() as $sfamily) {
3573763c3f2SGreg Roach                        if ($family !== $sfamily) {
3583763c3f2SGreg Roach                            // Add half-siblings
359ee727175SGreg Roach                            foreach (self::childFacts($person, $sfamily, '_HSIB', '', $min_date, $max_date) as $fact) {
3603763c3f2SGreg Roach                                $facts[] = $fact;
3613763c3f2SGreg Roach                            }
3623763c3f2SGreg Roach                        }
3633763c3f2SGreg Roach                    }
3643763c3f2SGreg Roach                    // Add grandparents
365ee727175SGreg Roach                    foreach (self::parentFacts($spouse, $spouse->getSex() == 'F' ? 3 : 2, $min_date, $max_date) as $fact) {
3663763c3f2SGreg Roach                        $facts[] = $fact;
3673763c3f2SGreg Roach                    }
3683763c3f2SGreg Roach                }
3693763c3f2SGreg Roach            }
3703763c3f2SGreg Roach
3713763c3f2SGreg Roach            if (strstr($SHOW_RELATIVES_EVENTS, '_MARR_PARE')) {
3723763c3f2SGreg Roach                // add father/mother marriages
3733763c3f2SGreg Roach                foreach ($person->getChildFamilies() as $sfamily) {
3748d0ebef0SGreg Roach                    foreach ($sfamily->facts(['MARR']) as $fact) {
375ee727175SGreg Roach                        if (self::includeFact($fact, $min_date, $max_date)) {
3763763c3f2SGreg Roach                            // marriage of parents (to each other)
3773763c3f2SGreg Roach                            $rela_fact = clone($fact);
3783763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . '_FAMC');
3793763c3f2SGreg Roach                            $facts[] = $rela_fact;
3803763c3f2SGreg Roach                        }
3813763c3f2SGreg Roach                    }
3823763c3f2SGreg Roach                }
3833763c3f2SGreg Roach                foreach ($person->getChildStepFamilies() as $sfamily) {
3848d0ebef0SGreg Roach                    foreach ($sfamily->facts(['MARR']) as $fact) {
385ee727175SGreg Roach                        if (self::includeFact($fact, $min_date, $max_date)) {
3863763c3f2SGreg Roach                            // marriage of a parent (to another spouse)
3873763c3f2SGreg Roach                            // Convert the event to a close relatives event
3883763c3f2SGreg Roach                            $rela_fact = clone($fact);
3893763c3f2SGreg Roach                            $rela_fact->setTag('_' . $fact->getTag() . '_PARE');
3903763c3f2SGreg Roach                            $facts[] = $rela_fact;
3913763c3f2SGreg Roach                        }
3923763c3f2SGreg Roach                    }
3933763c3f2SGreg Roach                }
3943763c3f2SGreg Roach            }
3953763c3f2SGreg Roach        }
3963763c3f2SGreg Roach
3973763c3f2SGreg Roach        foreach ($person->getChildFamilies() as $family) {
3983763c3f2SGreg Roach            foreach ($family->getSpouses() as $parent) {
3993763c3f2SGreg Roach                if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT' . ($sosa == 1 ? '_PARE' : '_GPAR'))) {
4008d0ebef0SGreg Roach                    foreach ($parent->facts(Gedcom::DEATH_EVENTS) as $fact) {
401ee727175SGreg Roach                        if (self::includeFact($fact, $min_date, $max_date)) {
4023763c3f2SGreg Roach                            switch ($sosa) {
4033763c3f2SGreg Roach                                case 1:
4043763c3f2SGreg Roach                                    // Convert the event to a close relatives event.
4053763c3f2SGreg Roach                                    $rela_fact = clone($fact);
4063763c3f2SGreg Roach                                    $rela_fact->setTag('_' . $fact->getTag() . '_PARE');
4073763c3f2SGreg Roach                                    $facts[] = $rela_fact;
4083763c3f2SGreg Roach                                    break;
4093763c3f2SGreg Roach                                case 2:
4103763c3f2SGreg Roach                                    // Convert the event to a close relatives event
4113763c3f2SGreg Roach                                    $rela_fact = clone($fact);
4123763c3f2SGreg Roach                                    $rela_fact->setTag('_' . $fact->getTag() . '_GPA1');
4133763c3f2SGreg Roach                                    $facts[] = $rela_fact;
4143763c3f2SGreg Roach                                    break;
4153763c3f2SGreg Roach                                case 3:
4163763c3f2SGreg Roach                                    // Convert the event to a close relatives event
4173763c3f2SGreg Roach                                    $rela_fact = clone($fact);
4183763c3f2SGreg Roach                                    $rela_fact->setTag('_' . $fact->getTag() . '_GPA2');
4193763c3f2SGreg Roach                                    $facts[] = $rela_fact;
4203763c3f2SGreg Roach                                    break;
4213763c3f2SGreg Roach                            }
4223763c3f2SGreg Roach                        }
4233763c3f2SGreg Roach                    }
4243763c3f2SGreg Roach                }
4253763c3f2SGreg Roach            }
4263763c3f2SGreg Roach        }
4273763c3f2SGreg Roach
4283763c3f2SGreg Roach        return $facts;
4293763c3f2SGreg Roach    }
4303763c3f2SGreg Roach
4313763c3f2SGreg Roach    /**
4323763c3f2SGreg Roach     * Get any historical events.
4333763c3f2SGreg Roach     *
4343763c3f2SGreg Roach     * @param Individual $person
435ee727175SGreg Roach     * @param Date       $min_date
436ee727175SGreg Roach     * @param Date       $max_date
4373763c3f2SGreg Roach     *
4383763c3f2SGreg Roach     * @return Fact[]
4393763c3f2SGreg Roach     */
440ee727175SGreg Roach    private static function historicalFacts(Individual $person, Date $min_date, Date $max_date): array
441c1010edaSGreg Roach    {
44213abd6f3SGreg Roach        $facts = [];
4433763c3f2SGreg Roach
4443763c3f2SGreg Roach        if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) {
44513abd6f3SGreg Roach            $histo = [];
4463763c3f2SGreg Roach            require Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php';
4473763c3f2SGreg Roach            foreach ($histo as $hist) {
4483763c3f2SGreg Roach                $fact = new Fact($hist, $person, 'histo');
449ee727175SGreg Roach
450ee727175SGreg Roach                if (self::includeFact($fact, $min_date, $max_date)) {
4513763c3f2SGreg Roach                    $facts[] = $fact;
4523763c3f2SGreg Roach                }
4533763c3f2SGreg Roach            }
4543763c3f2SGreg Roach        }
4553763c3f2SGreg Roach
4563763c3f2SGreg Roach        return $facts;
4573763c3f2SGreg Roach    }
4583763c3f2SGreg Roach
4593763c3f2SGreg Roach    /**
4603763c3f2SGreg Roach     * Get the events of associates.
4613763c3f2SGreg Roach     *
4623763c3f2SGreg Roach     * @param Individual $person
4633763c3f2SGreg Roach     *
4643763c3f2SGreg Roach     * @return Fact[]
4653763c3f2SGreg Roach     */
4668f53f488SRico Sonntag    private static function associateFacts(Individual $person): array
467c1010edaSGreg Roach    {
46813abd6f3SGreg Roach        $facts = [];
4693763c3f2SGreg Roach
470ee727175SGreg Roach        /** @var Individual[] $associates */
4713763c3f2SGreg Roach        $associates = array_merge(
4723763c3f2SGreg Roach            $person->linkedIndividuals('ASSO'),
4733763c3f2SGreg Roach            $person->linkedIndividuals('_ASSO'),
4743763c3f2SGreg Roach            $person->linkedFamilies('ASSO'),
4753763c3f2SGreg Roach            $person->linkedFamilies('_ASSO')
4763763c3f2SGreg Roach        );
4773763c3f2SGreg Roach        foreach ($associates as $associate) {
47830158ae7SGreg Roach            foreach ($associate->facts() as $fact) {
4793425616eSGreg Roach                $arec = $fact->attribute('_ASSO');
4803763c3f2SGreg Roach                if (!$arec) {
4813425616eSGreg Roach                    $arec = $fact->attribute('ASSO');
4823763c3f2SGreg Roach                }
483c0935879SGreg Roach                if ($arec && trim($arec, '@') === $person->xref()) {
4843763c3f2SGreg Roach                    // Extract the important details from the fact
4853763c3f2SGreg Roach                    $factrec = '1 ' . $fact->getTag();
486138ca96cSGreg Roach                    if (preg_match('/\n2 DATE .*/', $fact->gedcom(), $match)) {
4873763c3f2SGreg Roach                        $factrec .= $match[0];
4883763c3f2SGreg Roach                    }
489138ca96cSGreg Roach                    if (preg_match('/\n2 PLAC .*/', $fact->gedcom(), $match)) {
4903763c3f2SGreg Roach                        $factrec .= $match[0];
4913763c3f2SGreg Roach                    }
4923763c3f2SGreg Roach                    if ($associate instanceof Family) {
4933763c3f2SGreg Roach                        foreach ($associate->getSpouses() as $spouse) {
494c0935879SGreg Roach                            $factrec .= "\n2 _ASSO @" . $spouse->xref() . '@';
4953763c3f2SGreg Roach                        }
4963763c3f2SGreg Roach                    } else {
497c0935879SGreg Roach                        $factrec .= "\n2 _ASSO @" . $associate->xref() . '@';
4983763c3f2SGreg Roach                    }
4993763c3f2SGreg Roach                    $facts[] = new Fact($factrec, $associate, 'asso');
5003763c3f2SGreg Roach                }
5013763c3f2SGreg Roach            }
5023763c3f2SGreg Roach        }
5033763c3f2SGreg Roach
5043763c3f2SGreg Roach        return $facts;
5053763c3f2SGreg Roach    }
5063763c3f2SGreg Roach}
507