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