record(); // To whom is this record an associate? if ($parent instanceof Individual) { // On an individual page, we just show links to the person $associates = [$parent]; } elseif ($parent instanceof Family) { // On a family page, we show links to both spouses $associates = $parent->spouses(); } else { // On other pages, it does not make sense to show associates return ''; } preg_match_all('/\n2 (_?ASSO) @(' . Gedcom::REGEX_XREF . ')@((\n[3-9].*)*)/', $fact->gedcom(), $amatches, PREG_SET_ORDER); $html = ''; // For each ASSO record foreach ($amatches as $amatch) { $person = Registry::individualFactory()->make($amatch[2], $fact->record()->tree()); if ($person instanceof Individual && $person->canShowName()) { // Is there a "RELA" tag if (preg_match('/\n([23]) RELA (.+)/', $amatch[3], $rmatch) === 1) { if ($rmatch[1] === '2') { $rela_tag = $fact->record()->tag() . ':' . $amatch[1] . ':RELA'; } else { $rela_tag = $fact->tag() . ':' . $amatch[1] . ':RELA'; } // Use the supplied relationship as a label $label = Registry::elementFactory()->make($rela_tag)->value($rmatch[2], $parent->tree()); } elseif (preg_match('/^1 _?ASSO/', $fact->gedcom()) === 1) { // Use a default label $label = Registry::elementFactory()->make($fact->tag())->label(); } else { // Use a default label $label = Registry::elementFactory()->make($fact->tag() . ':_ASSO')->label(); } if ($person !== $parent && $person->getBirthDate()->isOK() && $fact->date()->isOK()) { $age = new Age($person->getBirthDate(), $fact->date()); switch ($person->sex()) { case 'M': $age_text = ' ' . I18N::translateContext('Male', '(aged %s)', (string) $age); break; case 'F': $age_text = ' ' . I18N::translateContext('Female', '(aged %s)', (string) $age); break; default: $age_text = ' ' . I18N::translate('(aged %s)', (string) $age); break; } } else { $age_text = ''; } $values = ['' . $person->fullName() . '' . $age_text]; $module = Registry::container()->get(ModuleService::class) ->findByComponent(ModuleChartInterface::class, $person->tree(), Auth::user()) ->first(static function (ModuleInterface $module) { return $module instanceof RelationshipsChartModule; }); if ($module instanceof RelationshipsChartModule) { foreach ($associates as $associate) { $relationship_name = Registry::container()->get(RelationshipService::class)->getCloseRelationshipName($associate, $person); if ($relationship_name === '') { $relationship_name = I18N::translate('Relationship'); } if ($parent instanceof Family) { // For family ASSO records (e.g. MARR), identify the spouse with a sex icon $relationship_name .= '' . view('icons/sex', ['sex' => $associate->sex()]) . ''; } $values[] = '' . $relationship_name . ''; } } $label = '' . $label . ''; $value = '' . implode(' — ', $values) . ''; $asso = I18N::translate('%1$s: %2$s', $label, $value); } elseif ($amatch[2] === 'VOID') { $label = '' . I18N::translate('Associate') . ''; $value = I18N::translate('Not recorded'); $asso = I18N::translate('%1$s: %2$s', $label, $value); } elseif (Auth::isEditor($fact->record()->tree())) { $label = '' . I18N::translate('Associate') . ''; $value = '@' . e($amatch[2]) . '@'; $asso = I18N::translate('%1$s: %2$s', $label, $value); } else { $asso = ''; } $html .= '
' . $asso . '
'; } echo $html;