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