xref: /webtrees/resources/views/chart-box.phtml (revision 40106a7319c9d89830bdc5f3fafd09abcca8cc6f)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Auth;
6use Fisharebest\Webtrees\Fact;
7use Fisharebest\Webtrees\Gedcom;
8use Fisharebest\Webtrees\I18N;
9use Fisharebest\Webtrees\Individual;
10use Fisharebest\Webtrees\Menu;
11use Fisharebest\Webtrees\Module\ModuleChartInterface;
12use Fisharebest\Webtrees\Services\ModuleService;
13use Illuminate\Support\Collection;
14use Ramsey\Uuid\Uuid;
15
16/**
17 * @var Individual|null   $individual
18 * @var ModuleService     $module_service
19 * @var Collection|Menu[] $menus
20 */
21
22if ($individual === null) {
23    echo '<div class="wt-chart-box"></div>';
24
25    return;
26}
27
28$module_service = app(ModuleService::class);
29
30$menus = $module_service->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user())->map(static function (ModuleChartInterface $module) use ($individual): ?Menu {
31    return $module->chartBoxMenu($individual);
32})->filter();
33
34foreach ($individual->spouseFamilies() as $family) {
35    $menus->push(new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()));
36    $spouse  = $family->spouse($individual);
37    if ($spouse && $spouse->canShow()) {
38        $menus->push(new Menu($spouse->fullName(), $spouse->url()));
39    }
40    foreach ($family->children() as $child) {
41        if ($child->canShow()) {
42            $menus->push(new Menu($child->fullName(), $child->url()));
43        }
44    }
45}
46
47// Do not show these facts in the expanded chart boxes.
48$exclude = [
49    'FAM:CHAN',
50    'FAM:CHIL',
51    'FAM:HUSB',
52    'FAM:NOTE',
53    'FAM:OBJE',
54    'FAM:RESN',
55    'FAM:SOUR',
56    'FAM:WIFE',
57    'INDI:ADDR',
58    'INDI:ALIA',
59    'INDI:ASSO',
60    'INDI:CHAN',
61    'INDI:EMAIL',
62    'INDI:FAMC',
63    'INDI:FAMS',
64    'INDI:NAME',
65    'INDI:NOTE',
66    'INDI:OBJE',
67    'INDI:PHON',
68    'INDI:RESI',
69    'INDI:RESN',
70    'INDI:SEX',
71    'INDI:SOUR',
72    'INDI:SSN',
73    'INDI:SUBM',
74    'INDI:TITL',
75    'INDI:URL',
76    'INDI:WWW',
77    'INDI:_EMAIL',
78    'INDI:_TODO',
79    'INDI:_UID',
80];
81
82/** @var Collection|Fact[] $all_facts */
83$all_facts = $individual->facts();
84foreach ($individual->spouseFamilies() as $family) {
85    foreach ($family->facts() as $fact) {
86        $all_facts->push($fact);
87    }
88}
89
90$all_facts = $all_facts->filter(static function (Fact $fact) use ($exclude): bool {
91    return !in_array($fact->tag(), $exclude, true);
92});
93
94$all_facts = Fact::sortFacts($all_facts);
95
96$id = Uuid::uuid4()->toString();
97?>
98
99<div class="wt-chart-box wt-chart-box-<?= strtolower($individual->sex()) ?> <?= $individual->isPendingAddition() ? 'wt-new' : '' ?> <?= $individual->isPendingDeletion() ? 'wt-old' : '' ?> overflow-hidden" data-xref="<?= e($individual->xref()) ?>" data-tree="<?= e($individual->tree()->name()) ?>">
100    <?php if ($individual->canShow() && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) : ?>
101        <div class="wt-chart-box-thumbnail float-left mr-1">
102            <?= $individual->displayImage(40, 50, 'crop', ['class' => 'wt-chart-box-thumbnail']) ?>
103        </div>
104    <?php endif ?>
105
106    <?php if ($individual->canShow()) : ?>
107        <div class="wt-chart-box-extra d-print-none float-right ml-1">
108            <div class="dropdown position-static wt-chart-box-zoom">
109                <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
110                    <div ><?= view('icons/zoom-in') ?></div>
111                    <div class="d-none"><?= view('icons/zoom-out') ?></div>
112                    <span class="sr-only"><?= I18N::translate('Links') ?></span>
113                </a>
114
115                <div class="dropdown-menu dropdown-menu-right wt-chart-box-dropdown wt-chart-box-zoom-dropdown" style="position: inherit" aria-labelledby="#chart-box-zoom-<?= $id ?>">
116                    <?php foreach ($all_facts as $fact) : ?>
117                        <?= $fact->summary() ?>
118                    <?php endforeach ?>
119                </div>
120            </div>
121
122            <div class="dropdown position-static wt-chart-box-links">
123                <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
124                    <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i>
125                    <span class="sr-only"><?= I18N::translate('Links') ?></span>
126                </a>
127
128                <div class="dropdown-menu dropdown-menu-right wt-chart-box-dropdown wt-chart-box-links-dropdown" style="position: inherit" aria-labelledby="#chart-box-menu-<?= $id ?>">
129                    <?php foreach ($menus as $menu) : ?>
130                        <a class="dropdown-item p-1 <?= e($menu->getClass()) ?>" href="<?= e($menu->getLink()) ?>">
131                            <?= $menu->getLabel() ?>
132                        </a>
133                    <?php endforeach ?>
134                </div>
135            </div>
136        </div>
137    <?php endif ?>
138
139    <div class="wt-chart-box-name">
140        <?php if ($individual->canShow()) : ?>
141            <a href="<?= e($individual->url()) ?>"><?= $individual->fullName() ?></a>
142        <?php else : ?>
143            <?= $individual->fullName() ?>
144        <?php endif ?>
145    </div>
146
147    <div class="wt-chart-box-name wt-chart-box-name-alt">
148        <?= $individual->alternateName() ?>
149    </div>
150
151    <div class="wt-chart-box-lifespan">
152        <?= $individual->lifespan() ?>
153    </div>
154
155    <div class="wt-chart-box-facts">
156        <div class="wt-chart-box-fact small">
157            <?php
158            $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY);
159            // Show BIRT or equivalent event
160
161            foreach (Gedcom::BIRTH_EVENTS as $birttag) {
162                if (!in_array($birttag, $opt_tags, true)) {
163                    $event = $individual->facts([$birttag])->first();
164                    if ($event instanceof Fact) {
165                        echo $event->summary();
166                        break;
167                    }
168                }
169            }
170            // Show optional events (before death)
171            foreach ($opt_tags as $key => $tag) {
172                if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) {
173                    $event = $individual->facts([$tag])->first();
174                    if ($event instanceof Fact) {
175                        echo $event->summary();
176                        unset($opt_tags[$key]);
177                    }
178                }
179            }
180            // Show DEAT or equivalent event
181            foreach (Gedcom::DEATH_EVENTS as $deattag) {
182                $event = $individual->facts([$deattag])->first();
183                if ($event instanceof Fact) {
184                    echo $event->summary();
185                    if (in_array($deattag, $opt_tags, true)) {
186                        unset($opt_tags[array_search($deattag, $opt_tags, true)]);
187                    }
188                    break;
189                }
190            }
191            // Show remaining optional events (after death)
192            foreach ($opt_tags as $tag) {
193                $event = $individual->facts([$tag])->first();
194                if ($event instanceof Fact) {
195                    echo $event->summary();
196                }
197            }
198            ?>
199        </div>
200    </div>
201</div>
202