xref: /webtrees/resources/views/modules/hourglass-chart/chart.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1cb0eb4a9SGreg Roach<?php
2cb0eb4a9SGreg Roach
3*10e06497SGreg Roachdeclare(strict_types=1);
4*10e06497SGreg Roach
5cb0eb4a9SGreg Roachuse Fisharebest\Webtrees\Family;
6cb0eb4a9SGreg Roachuse Fisharebest\Webtrees\Individual;
7cb0eb4a9SGreg Roachuse Fisharebest\Webtrees\View;
8cb0eb4a9SGreg Roachuse Illuminate\Support\Collection;
9cb0eb4a9SGreg Roach
10cb0eb4a9SGreg Roach/**
11cb0eb4a9SGreg Roach * @var int        $generations
12cb0eb4a9SGreg Roach * @var Individual $individual
1371378461SGreg Roach * @var bool       $spouses
14cb0eb4a9SGreg Roach */
15cb0eb4a9SGreg Roach
166c2179e2SGreg Roach$children = $individual->spouseFamilies()->map(static function (Family $family): Collection {
176c2179e2SGreg Roach    return $family->children();
186c2179e2SGreg Roach})->flatten();
19cb0eb4a9SGreg Roach
20cb0eb4a9SGreg Roach?>
21cb0eb4a9SGreg Roach
22cb0eb4a9SGreg Roach<div class="d-flex wt-chart-hourglass">
2371378461SGreg Roach    <?= view('modules/hourglass-chart/children', ['children' => $children, 'generations' => $generations - 1, 'spouses' => $spouses]) ?>
24cb0eb4a9SGreg Roach    <div class="align-self-center">
25cb0eb4a9SGreg Roach        <?= view('chart-box', ['individual' => $individual]) ?>
2671378461SGreg Roach        <?php if ($spouses) : ?>
27cb0eb4a9SGreg Roach            <?php foreach ($individual->spouseFamilies() as $family) : ?>
28cb0eb4a9SGreg Roach                <?= view('chart-box', ['individual' => $family->spouse($individual)]) ?>
29cb0eb4a9SGreg Roach            <?php endforeach ?>
30cb0eb4a9SGreg Roach        <?php endif ?>
31cb0eb4a9SGreg Roach    </div>
321afbbc50SGreg Roach    <?php if ($individual->childFamilies()->first() !== null) : ?>
331afbbc50SGreg Roach        <?= view('modules/hourglass-chart/parents', ['generations' => $generations - 1, 'family' => $individual->childFamilies()->first()]) ?>
34cb0eb4a9SGreg Roach    <?php endif ?>
3526684e68SGreg Roach</div>
3626684e68SGreg Roach
37cb0eb4a9SGreg Roach<?php View::push('javascript') ?>
3826684e68SGreg Roach<script>
39d4786c66SGreg Roach    $(".wt-chart-hourglass").on("click", ".hourglass-arrow[data-wt-chart-xref]", function () {
40d4786c66SGreg Roach        $(this.parentNode).load(this.dataset.wtChartXref);
4126684e68SGreg Roach
42cb0eb4a9SGreg Roach        return false;
4326684e68SGreg Roach    });
4426684e68SGreg Roach</script>
45cb0eb4a9SGreg Roach<?php View::endpush() ?>
46