1b315f3e1SGreg Roach<?php 2b315f3e1SGreg Roach 310e06497SGreg Roachdeclare(strict_types=1); 410e06497SGreg Roach 5b315f3e1SGreg Roachuse Fisharebest\Webtrees\Auth; 6b315f3e1SGreg Roachuse Fisharebest\Webtrees\Elements\UnknownElement; 7b315f3e1SGreg Roachuse Fisharebest\Webtrees\Elements\XrefAssociate; 8b315f3e1SGreg Roachuse Fisharebest\Webtrees\Fact; 9b315f3e1SGreg Roachuse Fisharebest\Webtrees\Family; 10b315f3e1SGreg Roachuse Fisharebest\Webtrees\Gedcom; 11b315f3e1SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 12b315f3e1SGreg Roachuse Fisharebest\Webtrees\I18N; 13b315f3e1SGreg Roachuse Fisharebest\Webtrees\Individual; 14b315f3e1SGreg Roachuse Fisharebest\Webtrees\Media; 15b315f3e1SGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 16b315f3e1SGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 17b315f3e1SGreg Roachuse Fisharebest\Webtrees\Module\RelationshipsChartModule; 18b315f3e1SGreg Roachuse Fisharebest\Webtrees\Registry; 19b315f3e1SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 20b315f3e1SGreg Roachuse Fisharebest\Webtrees\Services\RelationshipService; 21b315f3e1SGreg Roach 22b315f3e1SGreg Roach/** 23b315f3e1SGreg Roach * @var Fact $fact 24b315f3e1SGreg Roach * @var GedcomRecord $record 25b315f3e1SGreg Roach */ 26b315f3e1SGreg Roach 27b315f3e1SGreg Roach$parent = $fact->record(); 28b315f3e1SGreg Roach$tree = $parent->tree(); 29b315f3e1SGreg Roach[, $tag] = explode(':', $fact->tag()); 30b315f3e1SGreg Roach$label = $fact->label(); 31b315f3e1SGreg Roach$value = $fact->value(); 32b315f3e1SGreg Roach$type = $fact->attribute('TYPE'); 33b315f3e1SGreg Roach$id = $fact->id(); 34b315f3e1SGreg Roach 35b315f3e1SGreg Roach$element = Registry::elementFactory()->make($fact->tag()); 36b315f3e1SGreg Roach 37b315f3e1SGreg Roach// New or deleted facts need different styling 38b315f3e1SGreg Roach$styles = []; 39b315f3e1SGreg Roachif ($fact->isPendingAddition()) { 40b315f3e1SGreg Roach $styles[] = 'wt-new'; 41b315f3e1SGreg Roach} 42b315f3e1SGreg Roachif ($fact->isPendingDeletion()) { 43b315f3e1SGreg Roach $styles[] = 'wt-old'; 44b315f3e1SGreg Roach} 45b315f3e1SGreg Roach 46b315f3e1SGreg Roach// Event of close relative 47b315f3e1SGreg Roachif ($tag === 'EVEN' && $value === 'CLOSE_RELATIVE') { 48b315f3e1SGreg Roach $value = ''; 49b315f3e1SGreg Roach $styles[] = 'wt-relation-fact collapse'; 50b315f3e1SGreg Roach} 51b315f3e1SGreg Roach 52b315f3e1SGreg Roach// Event of close associates 53b315f3e1SGreg Roachif ($id === 'asso') { 54b315f3e1SGreg Roach $styles[] = 'wt-associate-fact collapse'; 55b315f3e1SGreg Roach} 56b315f3e1SGreg Roach 57b315f3e1SGreg Roachif ($element instanceof UnknownElement && $tree->getPreference('HIDE_GEDCOM_ERRORS') === '0') { 58b315f3e1SGreg Roach $styles[] = 'd-none'; 59b315f3e1SGreg Roach} 60b315f3e1SGreg Roach 61b315f3e1SGreg Roach 62b315f3e1SGreg Roach// historical facts 63b315f3e1SGreg Roachif ($id === 'histo') { 64b315f3e1SGreg Roach $styles[] = 'wt-historic-fact collapse'; 65b315f3e1SGreg Roach} 66b315f3e1SGreg Roach 67b315f3e1SGreg Roach// Use marriage type as the label. e.g. "Civil partnership" 68b315f3e1SGreg Roachif ($tag === 'MARR') { 69b315f3e1SGreg Roach $label = $fact->label(); 70b315f3e1SGreg Roach $type = ''; 71b315f3e1SGreg Roach} 72b315f3e1SGreg Roach 73b315f3e1SGreg Roach?> 74b315f3e1SGreg Roach<tr class="<?= implode(' ', $styles) ?>"> 75b315f3e1SGreg Roach <th scope="row"> 765d2c6313SGreg Roach <div class="wt-fact-label ut"><?= $label?></div> 77b315f3e1SGreg Roach 78b315f3e1SGreg Roach <?php if ($id !== 'histo' && $id !== 'asso' && $fact->canEdit() && !in_array($tag, ['HUSB', 'WIFE', 'CHIL', 'FAMC', 'FAMS'], true)) : ?> 79b315f3e1SGreg Roach <?= view('fact-edit-links', ['fact' => $fact, 'url' => $record->url()]) ?> 80b315f3e1SGreg Roach <?php endif ?> 81b315f3e1SGreg Roach 82bd29d468SGreg Roach <?php if ($tree->getPreference('SHOW_FACT_ICONS') === '1') : ?> 83b315f3e1SGreg Roach <span class="wt-fact-icon wt-fact-icon-<?= e($tag) ?>" title="<?= strip_tags($label) ?>"></span> 84b315f3e1SGreg Roach <?php endif ?> 85b315f3e1SGreg Roach </th> 86b315f3e1SGreg Roach 87b315f3e1SGreg Roach <td> 88b315f3e1SGreg Roach <?php if ($fact->target() instanceof Media) : ?> 898c19bf42SGreg Roach <div class="d-flex flex-wrap"> 90b315f3e1SGreg Roach <?php foreach ($fact->target()->mediaFiles() as $media_file) : ?> 918c19bf42SGreg Roach <div class="me-1 mb-1"> 92b315f3e1SGreg Roach <?= $media_file->displayImage(100, 100, 'contain', []) ?> 938c19bf42SGreg Roach </div> 94b315f3e1SGreg Roach <?php endforeach ?> 95b315f3e1SGreg Roach </div> 96b315f3e1SGreg Roach 97b315f3e1SGreg Roach <a href="<?= e($fact->target()->url()) ?>"><?= $fact->target()->fullName() ?></a> 98b315f3e1SGreg Roach 99b315f3e1SGreg Roach <?php foreach ($fact->target()->facts(['NOTE']) as $note) : ?> 100b315f3e1SGreg Roach <?= view('fact-gedcom-fields', ['gedcom' => $note->gedcom(), 'parent' => $fact->target()->tag(), 'tree' => $fact->record()->tree()]) ?> 101b315f3e1SGreg Roach <?php endforeach ?> 102b315f3e1SGreg Roach <?php else : ?> 103b315f3e1SGreg Roach <div class="wt-fact-main-attributes"> 104b315f3e1SGreg Roach <?php if ($parent !== $record) : ?> 105b315f3e1SGreg Roach <div class="wt-fact-record"> 106b315f3e1SGreg Roach <?php if ($parent instanceof Family) : ?> 107b315f3e1SGreg Roach <?php foreach ($parent->spouses()->filter(static fn ($individual): bool => $individual !== $record) as $spouse) : ?> 108b315f3e1SGreg Roach <a href="<?= e($spouse->url()) ?>"><?= $spouse->fullName() ?></a> — 109b315f3e1SGreg Roach <?php endforeach ?> 110b315f3e1SGreg Roach <a href="<?= e($parent->url()) ?>"><?= I18N::translate('View this family') ?></a> 111b315f3e1SGreg Roach <?php elseif ($parent instanceof Individual) : ?> 112b315f3e1SGreg Roach <a href="<?= e($parent->url()) ?>"><?= $parent->fullName() ?></a> 113b315f3e1SGreg Roach <?php endif ?> 114b315f3e1SGreg Roach </div> 115b315f3e1SGreg Roach <?php endif ?> 116b315f3e1SGreg Roach 117b315f3e1SGreg Roach <div class="wt-fact-value"> 118b315f3e1SGreg Roach <?= $element->value($value, $tree) ?> 119b315f3e1SGreg Roach <?php if ($element instanceof XrefAssociate && $fact->target() instanceof Individual) : ?> 120b315f3e1SGreg Roach <?php 121d35568b4SGreg Roach $module = Registry::container()->get(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 122b315f3e1SGreg Roach ->first(static fn (ModuleInterface $module): bool => $module instanceof RelationshipsChartModule) 123b315f3e1SGreg Roach ?> 124b315f3e1SGreg Roach 125b61651baSGreg Roach <?php if ($module instanceof RelationshipsChartModule && $record instanceof Individual) : ?> 126b315f3e1SGreg Roach — <a href="<?= $module->chartUrl($fact->target(), ['xref2' => $record->xref()]) ?>" rel="nofollow"> 127*9d203c3dSGreg Roach <?= Registry::container()->get(RelationshipService::class)->getCloseRelationshipName($record, $fact->target()) ?> 128b315f3e1SGreg Roach </a> 129b315f3e1SGreg Roach <?php endif ?> 130b315f3e1SGreg Roach <?php endif ?> 131b315f3e1SGreg Roach </div> 132b315f3e1SGreg Roach 133b315f3e1SGreg Roach <!-- Type of this fact/event (allow user-translations) --> 134b315f3e1SGreg Roach <?php if ($type !== '' && $tag !== 'EVEN' && $tag !== 'FACT') : ?> 135b315f3e1SGreg Roach <div class="wt-fact-type"> 136b315f3e1SGreg Roach <?= Registry::elementFactory()->make($fact->tag() . ':TYPE')->labelValue(I18N::translate($type), $tree) ?> 137b315f3e1SGreg Roach </div> 138b315f3e1SGreg Roach <?php endif ?> 139b315f3e1SGreg Roach 140b315f3e1SGreg Roach <?= view('fact-date', ['cal_link' => 'true', 'fact' => $fact, 'record' => $record, 'time' => true]) ?> 141b315f3e1SGreg Roach <?= view('fact-place', ['fact' => $fact, 'record' => $record]) ?> 142b315f3e1SGreg Roach </div> 143b315f3e1SGreg Roach 144b315f3e1SGreg Roach <div class="wt-fact-other-attributes mt-2"> 1459926a509SGreg Roach <?php preg_match_all('/\n2 (' . Gedcom::REGEX_TAG . ')( .*)?((\n[3-9].*)*)/', $fact->gedcom(), $matches, PREG_SET_ORDER) ?> 146b315f3e1SGreg Roach <?php foreach ($matches as $match) : ?> 1479926a509SGreg Roach <?php if (!in_array($match[1], ['DATE', 'AGE', 'HUSB', 'WIFE', 'PLAC', 'ASSO', '_ASSO', 'STAT', 'TEMP', 'TYPE', 'CONT', 'NOTE', 'OBJE', 'SOUR'], true)) : ?> 148b315f3e1SGreg Roach <?= view('fact-gedcom-fields', ['gedcom' => $match[0], 'parent' => $fact->tag() . ':' . $match[1], 'tree' => $tree]) ?> 149b315f3e1SGreg Roach <?php endif ?> 150b315f3e1SGreg Roach <?php endforeach; ?> 151b315f3e1SGreg Roach </div> 152b315f3e1SGreg Roach 153b315f3e1SGreg Roach <?php if ($id !== 'asso') : ?> 154b315f3e1SGreg Roach <?= view('fact-associates', ['fact' => $fact]) ?> 155b315f3e1SGreg Roach <?php endif ?> 156b315f3e1SGreg Roach 157b315f3e1SGreg Roach <?= view('fact-sources', ['fact' => $fact]) ?> 158b315f3e1SGreg Roach <?= view('fact-notes', ['fact' => $fact]) ?> 159b315f3e1SGreg Roach <?= view('fact-media', ['fact' => $fact]) ?> 160b315f3e1SGreg Roach <?php endif ?> 161b315f3e1SGreg Roach </td> 162b315f3e1SGreg Roach</tr> 163