xref: /webtrees/resources/views/chart-box.phtml (revision 39ca88ba08cefcfcaf891abfcf748f9c808eb326)
1<?php
2declare(strict_types=1);
3
4use Fisharebest\Webtrees\Auth;
5use Fisharebest\Webtrees\Fact;
6use Fisharebest\Webtrees\Functions\Functions;
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('chart', $individual->tree(), Auth::user())->map(function (ModuleChartInterface $module) use ($individual): ?Menu {
31    return $module->chartBoxMenu($individual);
32})->filter();
33
34foreach ($individual->spouseFamilies() as $family) {
35    $menus[] = 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        'ADDR',
50        'ALIA',
51        'ASSO',
52        'CHAN',
53        'CHIL',
54        'EMAIL',
55        'FAMC',
56        'FAMS',
57        'HUSB',
58        'NAME',
59        'NOTE',
60        'OBJE',
61        'PHON',
62        'RESI',
63        'RESN',
64        'SEX',
65        'SOUR',
66        'SSN',
67        'SUBM',
68        'TITL',
69        'URL',
70        'WIFE',
71        'WWW',
72        '_EMAIL',
73        '_TODO',
74        '_UID',
75        '_WT_OBJE_SORT',
76    ];
77
78
79/** @var Collection|Fact[] $all_facts */
80$all_facts = $individual->facts();
81foreach ($individual->spouseFamilies() as $family) {
82    foreach ($family->facts() as $fact) {
83        $all_facts->push($fact);
84    }
85}
86Functions::sortFacts($all_facts);
87
88$all_facts = $all_facts->filter(function (Fact $fact) use ($exclude): bool {
89    return !in_array($fact->getTag(), $exclude);
90});
91
92
93$id = Uuid::uuid4()->toString();
94
95/**
96 * @var Individual $individual
97 */
98?>
99<div class="wt-chart-box wt-chart-box-<?= strtolower($individual->sex()) ?>" style="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    <div class="wt-chart-box-extra d-print-none float-right ml-1">
107        <div class="dropdown position-static wt-chart-box-zoom">
108            <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-zoom-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
109                <div ><?= view('icons/zoom-in') ?></div>
110                <div class="d-none"><?= view('icons/zoom-out') ?></div>
111                <span class="sr-only"><?= I18N::translate('Links') ?></span>
112            </a>
113
114            <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 ?>">
115                <?php foreach ($all_facts as $fact): ?>
116                    <?= $fact->summary() ?>
117                <?php endforeach ?>
118            </div>
119        </div>
120
121        <div class="dropdown position-static wt-chart-box-links">
122            <a class="wt-chart-box-icon" href="#" role="button" id="chart-box-menu-<?= $id ?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
123                <i class="icon-pedigree" title="<?= I18N::translate('Links') ?>"></i>
124                <span class="sr-only"><?= I18N::translate('Links') ?></span>
125            </a>
126
127            <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 ?>">
128                <?php foreach ($menus as $menu): ?>
129                    <?= $menu->getMenuAsList() ?>
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->firstFact($birttag);
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->firstFact($tag);
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->firstFact($deattag);
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->firstFact($tag);
186                if ($event instanceof Fact) {
187                    echo $event->summary();
188                }
189            }
190            ?>
191        </div>
192    </div>
193</div>
194