xref: /webtrees/resources/views/fact.phtml (revision e47dc774cba11c817773e1490719632c810d988e)
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 flex-wrap">
88                <?php foreach ($fact->target()->mediaFiles() as $media_file) : ?>
89                    <div class="me-1 mb-1">
90                        <?= $media_file->displayImage(100, 100, 'contain', []) ?>
91                    </div>
92                <?php endforeach ?>
93            </div>
94
95            <a href="<?= e($fact->target()->url()) ?>"><?= $fact->target()->fullName() ?></a>
96
97            <?php foreach ($fact->target()->facts(['NOTE']) as $note) : ?>
98                <?= view('fact-gedcom-fields', ['gedcom' => $note->gedcom(), 'parent' => $fact->target()->tag(), 'tree' => $fact->record()->tree()]) ?>
99            <?php endforeach ?>
100        <?php else : ?>
101            <div class="wt-fact-main-attributes">
102                <?php if ($parent !== $record) : ?>
103                    <div class="wt-fact-record">
104                        <?php if ($parent instanceof Family) : ?>
105                            <?php foreach ($parent->spouses()->filter(static fn ($individual): bool => $individual !== $record) as $spouse) : ?>
106                                <a href="<?= e($spouse->url()) ?>"><?= $spouse->fullName() ?></a> —
107                            <?php endforeach ?>
108                            <a href="<?= e($parent->url()) ?>"><?= I18N::translate('View this family') ?></a>
109                        <?php elseif ($parent instanceof Individual) : ?>
110                            <a href="<?= e($parent->url()) ?>"><?= $parent->fullName() ?></a>
111                        <?php endif ?>
112                    </div>
113                <?php endif ?>
114
115                <div class="wt-fact-value">
116                    <?= $element->value($value, $tree) ?>
117                    <?php if ($element instanceof XrefAssociate && $fact->target() instanceof Individual) : ?>
118                        <?php
119                        $module = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user())
120                            ->first(static fn (ModuleInterface $module):bool => $module instanceof RelationshipsChartModule)
121                        ?>
122
123                        <?php if ($module instanceof RelationshipsChartModule && $record instanceof Individual) : ?>
124                            — <a href="<?= $module->chartUrl($fact->target(), ['xref2' => $record->xref()]) ?>" rel="nofollow">
125                                <?= app(RelationshipService::class)->getCloseRelationshipName($fact->target(), $record) ?>
126                            </a>
127                        <?php endif ?>
128                    <?php endif ?>
129                </div>
130
131                <!-- Type of this fact/event (allow user-translations) -->
132                <?php if ($type !== '' && $tag !== 'EVEN' && $tag !== 'FACT') : ?>
133                    <div class="wt-fact-type">
134                        <?= Registry::elementFactory()->make($fact->tag() . ':TYPE')->labelValue(I18N::translate($type), $tree) ?>
135                    </div>
136                <?php endif ?>
137
138                <?= view('fact-date', ['cal_link' => 'true', 'fact' => $fact, 'record' => $record, 'time' => true]) ?>
139                <?= view('fact-place', ['fact' => $fact, 'record' => $record]) ?>
140            </div>
141
142            <div class="wt-fact-other-attributes mt-2">
143                <?php preg_match_all('/\n2 (' . Gedcom::REGEX_TAG . ')( .*)?((\n[3-9].*)*)/', $fact->gedcom(), $matches, PREG_SET_ORDER) ?>
144                <?php foreach ($matches as $match) : ?>
145                    <?php if (!in_array($match[1], ['DATE', 'AGE', 'HUSB', 'WIFE', 'PLAC', 'ASSO', '_ASSO', 'STAT', 'TEMP', 'TYPE', 'CONT', 'NOTE', 'OBJE', 'SOUR'], true)) : ?>
146                        <?= view('fact-gedcom-fields', ['gedcom' => $match[0], 'parent' => $fact->tag() . ':' . $match[1], 'tree' => $tree]) ?>
147                    <?php endif ?>
148                <?php endforeach; ?>
149            </div>
150
151            <?php if ($id !== 'asso') : ?>
152                <?= view('fact-associates', ['fact' => $fact]) ?>
153            <?php endif ?>
154
155            <?= view('fact-sources', ['fact' => $fact]) ?>
156            <?= view('fact-notes', ['fact' => $fact]) ?>
157            <?= view('fact-media', ['fact' => $fact]) ?>
158        <?php endif ?>
159    </td>
160</tr>
161