1b315f3e1SGreg Roach<?php 2b315f3e1SGreg Roach 3b315f3e1SGreg Roachuse Fisharebest\Webtrees\Age; 4b315f3e1SGreg Roachuse Fisharebest\Webtrees\Auth; 5b315f3e1SGreg Roachuse Fisharebest\Webtrees\Fact; 6b315f3e1SGreg Roachuse Fisharebest\Webtrees\Family; 7b315f3e1SGreg Roachuse Fisharebest\Webtrees\Gedcom; 8b315f3e1SGreg Roachuse Fisharebest\Webtrees\I18N; 9b315f3e1SGreg Roachuse Fisharebest\Webtrees\Individual; 10b315f3e1SGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 11b315f3e1SGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 12b315f3e1SGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule; 13b315f3e1SGreg Roachuse Fisharebest\Webtrees\Registry; 14b315f3e1SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 15b315f3e1SGreg Roachuse Fisharebest\Webtrees\Services\RelationshipService; 16b315f3e1SGreg Roach 17b315f3e1SGreg Roach/** 18b315f3e1SGreg Roach * @var Fact $fact 19b315f3e1SGreg Roach */ 20b315f3e1SGreg Roach 21b315f3e1SGreg Roach$parent = $fact->record(); 22b315f3e1SGreg Roach// To whom is this record an associate? 23b315f3e1SGreg Roachif ($parent instanceof Individual) { 24b315f3e1SGreg Roach // On an individual page, we just show links to the person 25b315f3e1SGreg Roach $associates = [$parent]; 26b315f3e1SGreg Roach} elseif ($parent instanceof Family) { 27b315f3e1SGreg Roach // On a family page, we show links to both spouses 28b315f3e1SGreg Roach $associates = $parent->spouses(); 29b315f3e1SGreg Roach} else { 30b315f3e1SGreg Roach // On other pages, it does not make sense to show associates 31b315f3e1SGreg Roach return ''; 32b315f3e1SGreg Roach} 33b315f3e1SGreg Roach 34b315f3e1SGreg Roachpreg_match_all('/\n2 (_?ASSO) @(' . Gedcom::REGEX_XREF . ')@((\n[3-9].*)*)/', $fact->gedcom(), $amatches, PREG_SET_ORDER); 35b315f3e1SGreg Roach 36b315f3e1SGreg Roach$html = ''; 37b315f3e1SGreg Roach// For each ASSO record 38b315f3e1SGreg Roachforeach ($amatches as $amatch) { 39b315f3e1SGreg Roach $person = Registry::individualFactory()->make($amatch[2], $fact->record()->tree()); 40b315f3e1SGreg Roach if ($person && $person->canShowName()) { 41b315f3e1SGreg Roach // Is there a "RELA" tag 42b315f3e1SGreg Roach if (preg_match('/\n([23]) RELA (.+)/', $amatch[3], $rmatch)) { 43b315f3e1SGreg Roach if ($rmatch[1] === '2') { 44b315f3e1SGreg Roach $rela_tag = $fact->record()->tag() . ':' . $amatch[1] . ':RELA'; 45b315f3e1SGreg Roach } else { 46b315f3e1SGreg Roach $rela_tag = $fact->tag() . ':' . $amatch[1] . ':RELA'; 47b315f3e1SGreg Roach } 48b315f3e1SGreg Roach // Use the supplied relationship as a label 49b315f3e1SGreg Roach $label = Registry::elementFactory()->make($rela_tag)->value($rmatch[2], $parent->tree()); 50b315f3e1SGreg Roach } elseif (preg_match('/^1 _?ASSO/', $fact->gedcom())) { 51b315f3e1SGreg Roach // Use a default label 52b315f3e1SGreg Roach $label = Registry::elementFactory()->make($fact->tag())->label(); 53b315f3e1SGreg Roach } else { 54b315f3e1SGreg Roach // Use a default label 55b315f3e1SGreg Roach $label = Registry::elementFactory()->make($fact->tag() . ':_ASSO')->label(); 56b315f3e1SGreg Roach } 57b315f3e1SGreg Roach 58f6ffd5b7SGreg Roach if ($person !== $parent && $person->getBirthDate()->isOK() && $fact->date()->isOK()) { 59b315f3e1SGreg Roach $age = new Age($person->getBirthDate(), $fact->date()); 60b315f3e1SGreg Roach switch ($person->sex()) { 61b315f3e1SGreg Roach case 'M': 62b315f3e1SGreg Roach $age_text = ' ' . I18N::translateContext('Male', '(aged %s)', (string) $age); 63b315f3e1SGreg Roach break; 64b315f3e1SGreg Roach case 'F': 65b315f3e1SGreg Roach $age_text = ' ' . I18N::translateContext('Female', '(aged %s)', (string) $age); 66b315f3e1SGreg Roach break; 67b315f3e1SGreg Roach default: 68b315f3e1SGreg Roach $age_text = ' ' . I18N::translate('(aged %s)', (string) $age); 69b315f3e1SGreg Roach break; 70b315f3e1SGreg Roach } 71b315f3e1SGreg Roach } else { 72b315f3e1SGreg Roach $age_text = ''; 73b315f3e1SGreg Roach } 74b315f3e1SGreg Roach 75b315f3e1SGreg Roach $values = ['<a href="' . e($person->url()) . '">' . $person->fullName() . '</a>' . $age_text]; 76b315f3e1SGreg Roach 77b315f3e1SGreg Roach $module = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $person->tree(), Auth::user())->first(static function (ModuleInterface $module) { 78b315f3e1SGreg Roach return $module instanceof RelationshipsChartModule; 79b315f3e1SGreg Roach }); 80b315f3e1SGreg Roach 81b315f3e1SGreg Roach if ($module instanceof RelationshipsChartModule) { 82b315f3e1SGreg Roach foreach ($associates as $associate) { 83b315f3e1SGreg Roach $relationship_name = app(RelationshipService::class)->getCloseRelationshipName($associate, $person); 84b315f3e1SGreg Roach if ($relationship_name === '') { 85b315f3e1SGreg Roach $relationship_name = I18N::translate('Relationship'); 86b315f3e1SGreg Roach } 87b315f3e1SGreg Roach 88b315f3e1SGreg Roach if ($parent instanceof Family) { 89b315f3e1SGreg Roach // For family ASSO records (e.g. MARR), identify the spouse with a sex icon 90b315f3e1SGreg Roach $relationship_name .= '<small>' . view('icons/sex', ['sex' => $associate->sex()]) . '</small>'; 91b315f3e1SGreg Roach } 92b315f3e1SGreg Roach 93b315f3e1SGreg Roach $values[] = '<a href="' . $module->chartUrl($associate, ['xref2' => $person->xref()]) . '" rel="nofollow">' . $relationship_name . '</a>'; 94b315f3e1SGreg Roach } 95b315f3e1SGreg Roach } 9606c87791SGreg Roach $label = '<span class="label">' . $label . '</span>'; 9706c87791SGreg Roach $value = '<span class="field" dir="auto">' . implode(' — ', $values) . '</span>'; 9806c87791SGreg Roach 9906c87791SGreg Roach $asso = I18N::translate('%1$s: %2$s', $label, $value); 100*701f5d18SGreg Roach } elseif ($amatch[2] === 'VOID') { 10106c87791SGreg Roach $label = '<span class="label">' . I18N::translate('Associate') . '</span>'; 102*701f5d18SGreg Roach $value = I18N::translate('Not recorded'); 103*701f5d18SGreg Roach $asso = I18N::translate('%1$s: %2$s', $label, $value); 104*701f5d18SGreg Roach } elseif (Auth::isEditor($fact->record()->tree())) { 105*701f5d18SGreg Roach $label = '<span class="label">' . I18N::translate('Associate') . '</span>'; 106*701f5d18SGreg Roach $value = '<span class="error">@' . e($amatch[2]) . '@</span>'; 10764654c87SGreg Roach $asso = I18N::translate('%1$s: %2$s', $label, $value); 108b315f3e1SGreg Roach } else { 109b315f3e1SGreg Roach $asso = ''; 110b315f3e1SGreg Roach } 111b315f3e1SGreg Roach $html .= '<div class="fact_ASSO">' . $asso . '</div>'; 112b315f3e1SGreg Roach} 113b315f3e1SGreg Roach 114b315f3e1SGreg Roachecho $html; 115