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