summaryrefslogtreecommitdiff
path: root/resources/views/individual-name.phtml
blob: 3a2cc6778b453d2e4d533bf6dbd809c1069a3133 (plain)
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
<?php

use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Functions\FunctionsPrint;
use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
use Fisharebest\Webtrees\GedcomCode\GedcomCodeName;
use Fisharebest\Webtrees\GedcomTag;
use Fisharebest\Webtrees\Http\RequestHandlers\CopyFact;
use Fisharebest\Webtrees\Http\RequestHandlers\DeleteFact;
use Fisharebest\Webtrees\Http\RequestHandlers\EditName;
use Fisharebest\Webtrees\I18N;

/**
 * @var Fact $fact
 */

$individual = $fact->record();
$tree       = $individual->tree();

// Create a fake record, so we can extract the formatted NAME value from it.
$fake_individual = Registry::individualFactory()->new(
    'xref',
    "0 @xref@ INDI\n1 DEAT Y\n" . $fact->gedcom(),
    null,
    $tree
);
$fake_individual->setPrimaryName(0); // Make sure we use the name from "1 NAME"

$container_class = '';

if ($fact->isPendingDeletion()) {
    $container_class = 'wt-old';
} elseif ($fact->isPendingAddition()) {
    $container_class = 'wt-new';
}

?>
<div class="card <?= $container_class ?>">
    <div class="card-header" role="tab" id="name-header-<?= $fact->id() ?>">
        <a data-toggle="collapse" href="#name-content-<?= $fact->id() ?>" aria-expanded="false" aria-controls="name-content-<?= $fact->id() ?>">
            <?= view('icons/expand') ?>
            <?= view('icons/collapse') ?>
            <span class="label"><?= I18N::translate('Name') ?></span>
            <?= $fake_individual->fullName() ?>
            <?php if ($fact->attribute('TYPE') !== '') : ?>
                —
                <?= GedcomCodeName::getValue($fact->attribute('TYPE'), $fact->record()) ?>
            <?php endif ?>
        </a>
    </div>

    <div id="name-content-<?= $fact->id() ?>" class="card-body collapse" data-parent="#individual-names" aria-labelledby="name-header-<?= $fact->id() ?>">
        <dl class="row mb-0">
            <dt class="col-md-4 col-lg-3"><?= I18N::translate('Name') ?></dt>
            <dd class="col-md-8 col-lg-9"><span dir="auto"><?= e($fact->value()) ?></span></dd>

            <?php preg_match_all('/\n2 (\w+) (.+)/', $fact->gedcom(), $matches, PREG_SET_ORDER) ?>
            <?php foreach ($matches as $key => $match) : ?>
                <?php [, $tag, $value] = $match ?>
                <?php if ($tag !== 'SOUR' && $tag !== 'NOTE') : ?>
                    <dt class="col-md-4 col-lg-3">
                        <?= GedcomTag::getLabel($tag) ?>
                    </dt>
                    <dd class="col-md-8 col-lg-9">
                        <?php if ($tag === 'TYPE') : ?>
                            <?= GedcomCodeName::getValue(e($value), $individual) ?>
                        <?php else: ?>
                            <span dir="auto"><?= e($value) ?></span>
                        <?php endif ?>
                    </dd>
                <?php endif ?>
            <?php endforeach ?>
        </dl>

        <?= FunctionsPrintFacts::printFactSources($tree, $fact->gedcom(), 2) ?>
        <?= FunctionsPrint::printFactNotes($tree, $fact->gedcom(), 2) ?>

        <?php if ($fact->canEdit()) : ?>
            <div class="d-flex">
                <a class="btn btn-link ml-auto" href="<?= e(route(EditName::class, ['xref' => $individual->xref(), 'fact_id' => $fact->id(), 'tree' => $individual->tree()->name()])) ?>" title="<?= I18N::translate('Edit the name') ?>">
                    <?= view('icons/edit') ?>
                    <span class="sr-only"><?= I18N::translate('Edit the name') ?></span>
                </a>

                <a class="btn btn-link" href="#" data-post-url="<?= e(route(CopyFact::class, ['tree' => $fact->record()->tree()->name(), 'xref' => $fact->record()->xref(), 'fact_id' => $fact->id()])) ?>" title="<?= I18N::translate('Copy') ?>">
                    <?= view('icons/copy') ?>
                    <span class="sr-only"><?= I18N::translate('Copy') ?></span>
                </a>

                <a class="btn btn-link" href="#"
                   data-confirm="<?= I18N::translate('Are you sure you want to delete this fact?') ?>"
                   data-post-url="<?= e(route(DeleteFact::class, ['tree' => $individual->tree()->name(), 'xref' => $individual->xref(), 'fact_id' => $fact->id()])) ?>"
                   title="<?= I18N::translate('Delete this name') ?>">
                    <?= view('icons/delete') ?>
                    <span class="sr-only"><?= I18N::translate('Delete this name') ?></span>
                </a>
            </div>
        <?php endif ?>
    </div>
</div>