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