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