xref: /webtrees/app/Module/HourglassChartModule.php (revision cab242e7d7a773b0a6dab130048696e26fd6612c)
1168ff6f3Sric2016<?php
2168ff6f3Sric2016/**
3168ff6f3Sric2016 * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5168ff6f3Sric2016 * This program is free software: you can redistribute it and/or modify
6168ff6f3Sric2016 * it under the terms of the GNU General Public License as published by
7168ff6f3Sric2016 * the Free Software Foundation, either version 3 of the License, or
8168ff6f3Sric2016 * (at your option) any later version.
9168ff6f3Sric2016 * This program is distributed in the hope that it will be useful,
10168ff6f3Sric2016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11168ff6f3Sric2016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12168ff6f3Sric2016 * GNU General Public License for more details.
13168ff6f3Sric2016 * You should have received a copy of the GNU General Public License
14168ff6f3Sric2016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15168ff6f3Sric2016 */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
17e7f56f2aSGreg Roach
18168ff6f3Sric2016namespace Fisharebest\Webtrees\Module;
19168ff6f3Sric2016
2026684e68SGreg Roachuse Fisharebest\Webtrees\Auth;
21e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface;
2226684e68SGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrint;
23168ff6f3Sric2016use Fisharebest\Webtrees\I18N;
24168ff6f3Sric2016use Fisharebest\Webtrees\Individual;
25e46b0479SScrutinizer Auto-Fixeruse Fisharebest\Webtrees\Menu;
2626684e68SGreg Roachuse Fisharebest\Webtrees\Tree;
2726684e68SGreg Roachuse Symfony\Component\HttpFoundation\Request;
2826684e68SGreg Roachuse Symfony\Component\HttpFoundation\Response;
29168ff6f3Sric2016
30168ff6f3Sric2016/**
31168ff6f3Sric2016 * Class HourglassChartModule
32168ff6f3Sric2016 */
3337eb8894SGreg Roachclass HourglassChartModule extends AbstractModule implements ModuleChartInterface
34c1010edaSGreg Roach{
3549a243cbSGreg Roach    use ModuleChartTrait;
3649a243cbSGreg Roach
3726684e68SGreg Roach    // Defaults
3826684e68SGreg Roach    private const DEFAULT_GENERATIONS         = '3';
3926684e68SGreg Roach    private const DEFAULT_MAXIMUM_GENERATIONS = '9';
4026684e68SGreg Roach
4126684e68SGreg Roach    // Limits
42e759aebbSGreg Roach    private const MAXIMUM_GENERATIONS = 10;
4326684e68SGreg Roach    private const MINIMUM_GENERATIONS = 2;
4426684e68SGreg Roach
45168ff6f3Sric2016    /**
46168ff6f3Sric2016     * How should this module be labelled on tabs, menus, etc.?
47168ff6f3Sric2016     *
48168ff6f3Sric2016     * @return string
49168ff6f3Sric2016     */
5049a243cbSGreg Roach    public function title(): string
51c1010edaSGreg Roach    {
52bbb76c12SGreg Roach        /* I18N: Name of a module/chart */
53bbb76c12SGreg Roach        return I18N::translate('Hourglass chart');
54168ff6f3Sric2016    }
55168ff6f3Sric2016
56168ff6f3Sric2016    /**
57168ff6f3Sric2016     * A sentence describing what this module does.
58168ff6f3Sric2016     *
59168ff6f3Sric2016     * @return string
60168ff6f3Sric2016     */
6149a243cbSGreg Roach    public function description(): string
62c1010edaSGreg Roach    {
63bbb76c12SGreg Roach        /* I18N: Description of the “HourglassChart” module */
64bbb76c12SGreg Roach        return I18N::translate('An hourglass chart of an individual’s ancestors and descendants.');
65168ff6f3Sric2016    }
66168ff6f3Sric2016
67168ff6f3Sric2016    /**
68377a2979SGreg Roach     * CSS class for the URL.
69377a2979SGreg Roach     *
70377a2979SGreg Roach     * @return string
71377a2979SGreg Roach     */
72377a2979SGreg Roach    public function chartMenuClass(): string
73377a2979SGreg Roach    {
74377a2979SGreg Roach        return 'menu-chart-hourglass';
75377a2979SGreg Roach    }
76377a2979SGreg Roach
77377a2979SGreg Roach    /**
784eb71cfaSGreg Roach     * Return a menu item for this chart - for use in individual boxes.
794eb71cfaSGreg Roach     *
8060bc3e3fSGreg Roach     * @param Individual $individual
8160bc3e3fSGreg Roach     *
824eb71cfaSGreg Roach     * @return Menu|null
834eb71cfaSGreg Roach     */
84377a2979SGreg Roach    public function chartBoxMenu(Individual $individual): ?Menu
85c1010edaSGreg Roach    {
86e6562982SGreg Roach        return $this->chartMenu($individual);
87e6562982SGreg Roach    }
88e6562982SGreg Roach
89e6562982SGreg Roach    /**
9026684e68SGreg Roach     * A form to request the chart parameters.
91e6562982SGreg Roach     *
9226684e68SGreg Roach     * @param Request       $request
9326684e68SGreg Roach     * @param Tree          $tree
94e5a6b4d4SGreg Roach     * @param UserInterface $user
95e6562982SGreg Roach     *
9626684e68SGreg Roach     * @return Response
97e6562982SGreg Roach     */
98e5a6b4d4SGreg Roach    public function getChartAction(Request $request, Tree $tree, UserInterface $user): Response
99e6562982SGreg Roach    {
1009b5537c3SGreg Roach        $ajax       = (bool) $request->get('ajax');
10126684e68SGreg Roach        $xref       = $request->get('xref', '');
10226684e68SGreg Roach        $individual = Individual::getInstance($xref, $tree);
10326684e68SGreg Roach
10426684e68SGreg Roach        Auth::checkIndividualAccess($individual);
1059867b2f0SGreg Roach        Auth::checkComponentAccess($this, 'chart', $tree, $user);
10626684e68SGreg Roach
107e759aebbSGreg Roach        $generations = (int) $request->get('generations', self::DEFAULT_GENERATIONS);
10826684e68SGreg Roach
109e759aebbSGreg Roach        $generations = min($generations, self::MAXIMUM_GENERATIONS);
11026684e68SGreg Roach        $generations = max($generations, self::MINIMUM_GENERATIONS);
11126684e68SGreg Roach
11226684e68SGreg Roach        $show_spouse = (bool) $request->get('show_spouse');
11326684e68SGreg Roach
1149b5537c3SGreg Roach        if ($ajax) {
11526684e68SGreg Roach            return $this->chart($individual, $generations, $show_spouse);
11626684e68SGreg Roach        }
11726684e68SGreg Roach
11826684e68SGreg Roach        $ajax_url = $this->chartUrl($individual, [
1199b5537c3SGreg Roach            'ajax' => true,
12026684e68SGreg Roach        ]);
12126684e68SGreg Roach
1229b5537c3SGreg Roach        return $this->viewResponse('modules/hourglass-chart/page', [
12326684e68SGreg Roach            'ajax_url'            => $ajax_url,
12426684e68SGreg Roach            'generations'         => $generations,
12526684e68SGreg Roach            'individual'          => $individual,
126e759aebbSGreg Roach            'maximum_generations' => self::MAXIMUM_GENERATIONS,
12726684e68SGreg Roach            'minimum_generations' => self::MINIMUM_GENERATIONS,
12826684e68SGreg Roach            'module_name'         => $this->name(),
12926684e68SGreg Roach            'show_spouse'         => $show_spouse,
13026684e68SGreg Roach            'title'               => $this->chartTitle($individual),
13126684e68SGreg Roach        ]);
13226684e68SGreg Roach    }
13326684e68SGreg Roach
13426684e68SGreg Roach    /**
13526684e68SGreg Roach     * Generate the initial generations of the chart
13626684e68SGreg Roach     *
137e5a6b4d4SGreg Roach     * @param Individual $individual
138e5a6b4d4SGreg Roach     * @param int        $generations
139e5a6b4d4SGreg Roach     * @param bool       $show_spouse
14026684e68SGreg Roach     *
14126684e68SGreg Roach     * @return Response
14226684e68SGreg Roach     */
14326684e68SGreg Roach    protected function chart(Individual $individual, int $generations, bool $show_spouse): Response
14426684e68SGreg Roach    {
14526684e68SGreg Roach        ob_start();
14626684e68SGreg Roach        $this->printDescendency($individual, 1, $generations, $show_spouse, true);
14726684e68SGreg Roach        $descendants = ob_get_clean();
14826684e68SGreg Roach
14926684e68SGreg Roach        ob_start();
15026684e68SGreg Roach        $this->printPersonPedigree($individual, 1, $generations, $show_spouse);
15126684e68SGreg Roach        $ancestors = ob_get_clean();
15226684e68SGreg Roach
15326684e68SGreg Roach        return new Response(view('modules/hourglass-chart/chart', [
15426684e68SGreg Roach            'descendants' => $descendants,
15526684e68SGreg Roach            'ancestors'   => $ancestors,
156*cab242e7SGreg Roach            'bhalfheight' => (int) (app(ModuleThemeInterface::class)->parameter('chart-box-y') / 2),
15726684e68SGreg Roach            'module_name' => $this->name(),
15826684e68SGreg Roach        ]));
15926684e68SGreg Roach    }
16026684e68SGreg Roach
16126684e68SGreg Roach    /**
16226684e68SGreg Roach     * @param Request $request
16326684e68SGreg Roach     * @param Tree    $tree
16426684e68SGreg Roach     *
16526684e68SGreg Roach     * @return Response
16626684e68SGreg Roach     */
16726684e68SGreg Roach    public function postAncestorsAction(Request $request, Tree $tree): Response
16826684e68SGreg Roach    {
16926684e68SGreg Roach        $xref       = $request->get('xref', '');
17026684e68SGreg Roach        $individual = Individual::getInstance($xref, $tree);
17126684e68SGreg Roach
17226684e68SGreg Roach        Auth::checkIndividualAccess($individual);
17326684e68SGreg Roach
17426684e68SGreg Roach        $show_spouse = (bool) $request->get('show_spouse');
17526684e68SGreg Roach
17626684e68SGreg Roach        ob_start();
17726684e68SGreg Roach        $this->printPersonPedigree($individual, 0, 1, $show_spouse);
17826684e68SGreg Roach        $html = ob_get_clean();
17926684e68SGreg Roach
18026684e68SGreg Roach        return new Response($html);
18126684e68SGreg Roach    }
18226684e68SGreg Roach
18326684e68SGreg Roach    /**
18426684e68SGreg Roach     * @param Request $request
18526684e68SGreg Roach     * @param Tree    $tree
18626684e68SGreg Roach     *
18726684e68SGreg Roach     * @return Response
18826684e68SGreg Roach     */
18926684e68SGreg Roach    public function postDescendantsAction(Request $request, Tree $tree): Response
19026684e68SGreg Roach    {
19126684e68SGreg Roach        $xref       = $request->get('xref', '');
19226684e68SGreg Roach        $individual = Individual::getInstance($xref, $tree);
19326684e68SGreg Roach
19426684e68SGreg Roach        $show_spouse = (bool) $request->get('show_spouse');
19526684e68SGreg Roach
19626684e68SGreg Roach        ob_start();
19726684e68SGreg Roach        $this->printDescendency($individual, 1, 2, $show_spouse, false);
19826684e68SGreg Roach        $html = ob_get_clean();
19926684e68SGreg Roach
20026684e68SGreg Roach        return new Response($html);
20126684e68SGreg Roach    }
20226684e68SGreg Roach
20326684e68SGreg Roach    /**
20426684e68SGreg Roach     * Prints descendency of passed in person
20526684e68SGreg Roach     *
20626684e68SGreg Roach     * @param Individual $individual  Show descendants of this individual
20726684e68SGreg Roach     * @param int        $generation  The current generation number
20826684e68SGreg Roach     * @param int        $generations Show this number of generations
20926684e68SGreg Roach     * @param bool       $show_spouse
21026684e68SGreg Roach     * @param bool       $show_menu
21126684e68SGreg Roach     *
21226684e68SGreg Roach     * @return void
21326684e68SGreg Roach     */
21426684e68SGreg Roach    private function printDescendency(Individual $individual, int $generation, int $generations, bool $show_spouse, bool $show_menu)
21526684e68SGreg Roach    {
21626684e68SGreg Roach        static $lastGenSecondFam = false;
21726684e68SGreg Roach
21826684e68SGreg Roach        if ($generation > $generations) {
21926684e68SGreg Roach            return;
22026684e68SGreg Roach        }
22126684e68SGreg Roach        $pid         = $individual->xref();
22226684e68SGreg Roach        $tablealign  = 'right';
22326684e68SGreg Roach        $otablealign = 'left';
22426684e68SGreg Roach        if (I18N::direction() === 'rtl') {
22526684e68SGreg Roach            $tablealign  = 'left';
22626684e68SGreg Roach            $otablealign = 'right';
22726684e68SGreg Roach        }
22826684e68SGreg Roach
22926684e68SGreg Roach        //-- put a space between families on the last generation
23026684e68SGreg Roach        if ($generation == $generations - 1) {
23126684e68SGreg Roach            if ($lastGenSecondFam) {
23226684e68SGreg Roach                echo '<br>';
23326684e68SGreg Roach            }
23426684e68SGreg Roach            $lastGenSecondFam = true;
23526684e68SGreg Roach        }
23626684e68SGreg Roach        echo '<table cellspacing="0" cellpadding="0" border="0" id="table_' . e($pid) . '" class="hourglassChart" style="float:' . $tablealign . '">';
23726684e68SGreg Roach        echo '<tr>';
23826684e68SGreg Roach        echo '<td style="text-align:' . $tablealign . '">';
23939ca88baSGreg Roach        $families = $individual->spouseFamilies();
24026684e68SGreg Roach        $children = [];
24126684e68SGreg Roach        if ($generation < $generations) {
24226684e68SGreg Roach            // Put all of the children in a common array
24326684e68SGreg Roach            foreach ($families as $family) {
24439ca88baSGreg Roach                foreach ($family->children() as $child) {
24526684e68SGreg Roach                    $children[] = $child;
24626684e68SGreg Roach                }
24726684e68SGreg Roach            }
24826684e68SGreg Roach
24926684e68SGreg Roach            $ct = count($children);
25026684e68SGreg Roach            if ($ct > 0) {
25126684e68SGreg Roach                echo '<table cellspacing="0" cellpadding="0" border="0" style="position: relative; top: auto; float: ' . $tablealign . ';">';
25226684e68SGreg Roach                for ($i = 0; $i < $ct; $i++) {
25326684e68SGreg Roach                    $individual2 = $children[$i];
25426684e68SGreg Roach                    $chil        = $individual2->xref();
25526684e68SGreg Roach                    echo '<tr>';
25626684e68SGreg Roach                    echo '<td id="td_', e($chil), '" class="', I18N::direction(), '" style="text-align:', $otablealign, '">';
25726684e68SGreg Roach                    $this->printDescendency($individual2, $generation + 1, $generations, $show_spouse, false);
25826684e68SGreg Roach                    echo '</td>';
25926684e68SGreg Roach
26026684e68SGreg Roach                    // Print the lines
26126684e68SGreg Roach                    if ($ct > 1) {
26226684e68SGreg Roach                        if ($i == 0) {
26326684e68SGreg Roach                            // First child
264e837ff07SGreg Roach                            echo '<td style="vertical-align:bottom"><img alt="" role="presentation" class="line1 tvertline" id="vline_' . $chil . '" src="' . e(asset('css/images/vline.png')) . '" width="3"></td>';
26526684e68SGreg Roach                        } elseif ($i == $ct - 1) {
26626684e68SGreg Roach                            // Last child
267e837ff07SGreg Roach                            echo '<td style="vertical-align:top"><img alt="" role="presentation" class="bvertline" id="vline_' . $chil . '" src="' . e(asset('css/images/vline.png')) . '" width="3"></td>';
26826684e68SGreg Roach                        } else {
26926684e68SGreg Roach                            // Middle child
27039b853a7SGreg Roach                            echo '<td style="background:url(' . e('"' . asset('css/images/vline.png') . '"') . ');"><img alt="" role="presentation" src="' . e(asset('css/images/spacer.png')) . '" width="3"></td>';
27126684e68SGreg Roach                        }
27226684e68SGreg Roach                    }
27326684e68SGreg Roach                    echo '</tr>';
27426684e68SGreg Roach                }
27526684e68SGreg Roach                echo '</table>';
27626684e68SGreg Roach            }
27726684e68SGreg Roach            echo '</td>';
278*cab242e7SGreg Roach            echo '<td class="myCharts" width="', app(ModuleThemeInterface::class)->parameter('chart-box-x'), '">';
27926684e68SGreg Roach        }
28026684e68SGreg Roach
28126684e68SGreg Roach        // Print the descendency expansion arrow
28226684e68SGreg Roach        if ($generation == $generations) {
283*cab242e7SGreg Roach            $tbwidth = app(ModuleThemeInterface::class)->parameter('chart-box-x') + 16;
28426684e68SGreg Roach            for ($j = $generation; $j < $generations; $j++) {
285*cab242e7SGreg Roach                echo "<div style='width: ", $tbwidth, "px;'><br></div></td><td style='width:", app(ModuleThemeInterface::class)->parameter('chart-box-x'), "px'>";
28626684e68SGreg Roach            }
28726684e68SGreg Roach            $kcount = 0;
28826684e68SGreg Roach            foreach ($families as $family) {
28939ca88baSGreg Roach                $kcount += $family->numberOfChildren();
29026684e68SGreg Roach            }
29126684e68SGreg Roach            if ($kcount == 0) {
292*cab242e7SGreg Roach                echo "</td><td style='width:", app(ModuleThemeInterface::class)->parameter('chart-box-x'), "px'>";
29326684e68SGreg Roach            } else {
29439b853a7SGreg Roach                echo '<a href="#" title="' . I18N::translate('Children') . '" data-route="Descendants" data-xref="' .  e($pid) . '" data-spouses="' .  e($show_spouse) . '" data-tree="' .  e($individual->tree()->name()) . '">' . view('icons/arrow-left') . '</a>';
29526684e68SGreg Roach
29626684e68SGreg Roach                //-- move the arrow up to line up with the correct box
29726684e68SGreg Roach                if ($show_spouse) {
29826684e68SGreg Roach                    echo str_repeat('<br><br><br>', count($families));
29926684e68SGreg Roach                }
300*cab242e7SGreg Roach                echo "</td><td style='width:", app(ModuleThemeInterface::class)->parameter('chart-box-x'), "px'>";
30126684e68SGreg Roach            }
30226684e68SGreg Roach        }
30326684e68SGreg Roach
30426684e68SGreg Roach        echo '<table cellspacing="0" cellpadding="0" border="0" id="table2_' . $pid . '"><tr><td> ';
30526684e68SGreg Roach        echo FunctionsPrint::printPedigreePerson($individual);
306e837ff07SGreg Roach        echo '</td><td> <img alt="" role="presentation" class="lineh1" src="' . e(asset('css/images/hline.png')) . '" width="7" height="3">';
30726684e68SGreg Roach
30826684e68SGreg Roach        //----- Print the spouse
30926684e68SGreg Roach        if ($show_spouse) {
31026684e68SGreg Roach            foreach ($families as $family) {
31126684e68SGreg Roach                echo "</td></tr><tr><td style='text-align:$otablealign'>";
31239ca88baSGreg Roach                echo FunctionsPrint::printPedigreePerson($family->spouse($individual));
31326684e68SGreg Roach                echo '</td><td> </td>';
31426684e68SGreg Roach            }
31526684e68SGreg Roach            //-- add offset divs to make things line up better
31626684e68SGreg Roach            if ($generation == $generations) {
317*cab242e7SGreg Roach                echo "<tr><td colspan '2'><div style='height:", (app(ModuleThemeInterface::class)->parameter('chart-box-y') / 4), 'px; width:', app(ModuleThemeInterface::class)->parameter('chart-box-x'), "px;'><br></div>";
31826684e68SGreg Roach            }
31926684e68SGreg Roach        }
32026684e68SGreg Roach        echo '</td></tr></table>';
32126684e68SGreg Roach
32226684e68SGreg Roach        // For the root individual, print a down arrow that allows changing the root of tree
32326684e68SGreg Roach        if ($show_menu && $generation == 1) {
324*cab242e7SGreg Roach            echo '<div class="text-center" id="childarrow" style="position:absolute; width:', app(ModuleThemeInterface::class)->parameter('chart-box-x'), 'px;">';
32539b853a7SGreg Roach            echo '<a href="#" title="' . I18N::translate('Family') . '" id="spouse-child-links">' . view('icons/arrow-down') . '</a>';
32626684e68SGreg Roach            echo '<div id="childbox">';
32726684e68SGreg Roach            echo '<table cellspacing="0" cellpadding="0" border="0" class="person_box"><tr><td> ';
32826684e68SGreg Roach
32939ca88baSGreg Roach            foreach ($individual->spouseFamilies() as $family) {
33026684e68SGreg Roach                echo "<span class='name1'>" . I18N::translate('Family') . '</span>';
33139ca88baSGreg Roach                $spouse = $family->spouse($individual);
33226684e68SGreg Roach                if ($spouse !== null) {
33326684e68SGreg Roach                    echo '<a href="' . e(route('hourglass', [
33426684e68SGreg Roach                            'xref'        => $spouse->xref(),
33526684e68SGreg Roach                            'generations' => $generations,
33626684e68SGreg Roach                            'show_spouse' => (int) $show_spouse,
33726684e68SGreg Roach                            'ged'         => $spouse->tree()->name(),
33839ca88baSGreg Roach                        ])) . '" class="name1">' . $spouse->fullName() . '</a>';
33926684e68SGreg Roach                }
34039ca88baSGreg Roach                foreach ($family->children() as $child) {
34126684e68SGreg Roach                    echo '<a href="' . e(route('hourglass', [
34226684e68SGreg Roach                            'xref'        => $child->xref(),
34326684e68SGreg Roach                            'generations' => $generations,
34426684e68SGreg Roach                            'show_spouse' => (int) $show_spouse,
34526684e68SGreg Roach                            'ged'         => $child->tree()->name(),
34639ca88baSGreg Roach                        ])) . '" class="name1">' . $child->fullName() . '</a>';
34726684e68SGreg Roach                }
34826684e68SGreg Roach            }
34926684e68SGreg Roach
35026684e68SGreg Roach            //-- print the siblings
35139ca88baSGreg Roach            foreach ($individual->childFamilies() as $family) {
35239ca88baSGreg Roach                if ($family->husband() || $family->wife()) {
35326684e68SGreg Roach                    echo "<span class='name1'>" . I18N::translate('Parents') . '</span>';
35439ca88baSGreg Roach                    $husb = $family->husband();
35526684e68SGreg Roach                    if ($husb) {
35626684e68SGreg Roach                        echo '<a href="' . e(route('hourglass', [
35726684e68SGreg Roach                                'xref'        => $husb->xref(),
35826684e68SGreg Roach                                'generations' => $generations,
35926684e68SGreg Roach                                'show_spouse' => (int) $show_spouse,
36026684e68SGreg Roach                                'ged'         => $husb->tree()->name(),
36139ca88baSGreg Roach                            ])) . '" class="name1">' . $husb->fullName() . '</a>';
36226684e68SGreg Roach                    }
36339ca88baSGreg Roach                    $wife = $family->wife();
36426684e68SGreg Roach                    if ($wife) {
36526684e68SGreg Roach                        echo '<a href="' . e(route('hourglass', [
36626684e68SGreg Roach                                'xref'        => $wife->xref(),
36726684e68SGreg Roach                                'generations' => $generations,
36826684e68SGreg Roach                                'show_spouse' => (int) $show_spouse,
36926684e68SGreg Roach                                'ged'         => $wife->tree()->name(),
37039ca88baSGreg Roach                            ])) . '" class="name1">' . $wife->fullName() . '</a>';
37126684e68SGreg Roach                    }
37226684e68SGreg Roach                }
37326684e68SGreg Roach
37426684e68SGreg Roach                // filter out root person from children array so only siblings remain
375820b62dfSGreg Roach                $siblings       = $family->children()->filter(function (Individual $x) use ($individual): bool {
37626684e68SGreg Roach                    return $x !== $individual;
37726684e68SGreg Roach                });
378820b62dfSGreg Roach
379820b62dfSGreg Roach                if ($siblings->count() > 0) {
38026684e68SGreg Roach                    echo '<span class="name1">';
381820b62dfSGreg Roach                    echo $siblings->count() > 1 ? I18N::translate('Siblings') : I18N::translate('Sibling');
38226684e68SGreg Roach                    echo '</span>';
38326684e68SGreg Roach                    foreach ($siblings as $child) {
38426684e68SGreg Roach                        echo '<a href="' . e(route('hourglass', [
38526684e68SGreg Roach                                'xref'        => $child->xref(),
38626684e68SGreg Roach                                'generations' => $generations,
38726684e68SGreg Roach                                'show_spouse' => (int) $show_spouse,
38826684e68SGreg Roach                                'ged'         => $child->tree()->name(),
38939ca88baSGreg Roach                            ])) . '" class="name1">' . $child->fullName() . '</a>';
39026684e68SGreg Roach                    }
39126684e68SGreg Roach                }
39226684e68SGreg Roach            }
39326684e68SGreg Roach            echo '</td></tr></table>';
39426684e68SGreg Roach            echo '</div>';
39526684e68SGreg Roach            echo '</div>';
39626684e68SGreg Roach        }
39726684e68SGreg Roach        echo '</td></tr></table>';
39826684e68SGreg Roach    }
39926684e68SGreg Roach
40026684e68SGreg Roach    /**
40126684e68SGreg Roach     * Prints pedigree of the person passed in. Which is the descendancy
40226684e68SGreg Roach     *
40326684e68SGreg Roach     * @param Individual $individual  Show the pedigree of this individual
40426684e68SGreg Roach     * @param int        $generation  Current generation number
40526684e68SGreg Roach     * @param int        $generations Show this number of generations
40626684e68SGreg Roach     * @param bool       $show_spouse
40726684e68SGreg Roach     *
40826684e68SGreg Roach     * @return void
40926684e68SGreg Roach     */
41026684e68SGreg Roach    private function printPersonPedigree(Individual $individual, int $generation, int $generations, bool $show_spouse)
41126684e68SGreg Roach    {
41226684e68SGreg Roach        if ($generation >= $generations) {
41326684e68SGreg Roach            return;
41426684e68SGreg Roach        }
41526684e68SGreg Roach
41626684e68SGreg Roach        // handle pedigree n generations lines
41726684e68SGreg Roach        $genoffset = $generations;
41826684e68SGreg Roach
41939ca88baSGreg Roach        $family = $individual->primaryChildFamily();
42026684e68SGreg Roach
42126684e68SGreg Roach        if ($family === null) {
42226684e68SGreg Roach            // Prints empty table columns for children w/o parents up to the max generation
42326684e68SGreg Roach            // This allows vertical line spacing to be consistent
424*cab242e7SGreg Roach            echo '<table><tr><td> ' . app(ModuleThemeInterface::class)->individualBoxEmpty() . '</td>';
42526684e68SGreg Roach            echo '<td> ';
42626684e68SGreg Roach            // Recursively get the father’s family
42726684e68SGreg Roach            $this->printPersonPedigree($individual, $generation + 1, $generations, $show_spouse);
42826684e68SGreg Roach            echo '</td></tr>';
429*cab242e7SGreg Roach            echo '<tr><td> ' . app(ModuleThemeInterface::class)->individualBoxEmpty() . '</td>';
43026684e68SGreg Roach            echo '<td> ';
43126684e68SGreg Roach            // Recursively get the mother’s family
43226684e68SGreg Roach            $this->printPersonPedigree($individual, $generation + 1, $generations, $show_spouse);
43326684e68SGreg Roach            echo '</td><td> </tr></table>';
43426684e68SGreg Roach        } else {
43526684e68SGreg Roach            echo '<table cellspacing="0" cellpadding="0" border="0"  class="hourglassChart">';
43626684e68SGreg Roach            echo '<tr>';
437e837ff07SGreg Roach            echo '<td style="vertical-align:bottom"><img alt="" role="presnentation" class="line3 pvline" src="' . e(asset('css/images/vline.png')) . '" width="3"></td>';
438e837ff07SGreg Roach            echo '<td> <img alt="" role="presentation" class="lineh2" src="' . e(asset('css/images/hline.png')) . '" width="7" height="3"></td>';
43926684e68SGreg Roach            echo '<td class="myCharts"> ';
44026684e68SGreg Roach            //-- print the father box
44139ca88baSGreg Roach            echo FunctionsPrint::printPedigreePerson($family->husband());
44226684e68SGreg Roach            echo '</td>';
44339ca88baSGreg Roach            if ($family->husband()) {
44439ca88baSGreg Roach                $ARID = $family->husband()->xref();
44526684e68SGreg Roach                echo '<td id="td_' . e($ARID) . '">';
44626684e68SGreg Roach
44739ca88baSGreg Roach                if ($generation == $generations - 1 && $family->husband()->childFamilies()) {
44839ca88baSGreg Roach                    echo '<a href="#" title="' . I18N::translate('Parents') . '" data-route="Ancestors" data-xref="' .  e($ARID) . '" data-spouses="' .  e($show_spouse) . '" data-tree="' .  e($family->husband()->tree()->name()) . '">' . view('icons/arrow-right') . '</a>';
44926684e68SGreg Roach                }
45026684e68SGreg Roach
45139ca88baSGreg Roach                $this->printPersonPedigree($family->husband(), $generation + 1, $generations, $show_spouse);
45226684e68SGreg Roach                echo '</td>';
45326684e68SGreg Roach            } else {
45426684e68SGreg Roach                echo '<td> ';
45526684e68SGreg Roach                if ($generation < $genoffset - 1) {
45626684e68SGreg Roach                    echo '<table>';
45726684e68SGreg Roach                    for ($i = $generation; $i < ((2 ** (($genoffset - 1) - $generation)) / 2) + 2; $i++) {
458*cab242e7SGreg Roach                        echo app(ModuleThemeInterface::class)->individualBoxEmpty();
45926684e68SGreg Roach                        echo '</tr>';
460*cab242e7SGreg Roach                        echo app(ModuleThemeInterface::class)->individualBoxEmpty();
46126684e68SGreg Roach                        echo '</tr>';
46226684e68SGreg Roach                    }
46326684e68SGreg Roach                    echo '</table>';
46426684e68SGreg Roach                }
46526684e68SGreg Roach            }
46626684e68SGreg Roach            echo
46726684e68SGreg Roach            '</tr><tr>',
468e837ff07SGreg Roach                '<td style="vertical-align:top"><img alt="" role="presentation" class="pvline" src="' . e(asset('css/images/vline.png')) . '" width="3"></td>',
469e837ff07SGreg Roach                '<td> <img alt="" role="presentation" class="lineh3" src="' . e(asset('css/images/hline.png')) . '" width="7" height="3"></td>',
47026684e68SGreg Roach            '<td class="myCharts"> ';
47126684e68SGreg Roach
47239ca88baSGreg Roach            echo FunctionsPrint::printPedigreePerson($family->wife());
47326684e68SGreg Roach            echo '</td>';
47439ca88baSGreg Roach            if ($family->wife()) {
47539ca88baSGreg Roach                $ARID = $family->wife()->xref();
47626684e68SGreg Roach                echo '<td id="td_' . e($ARID) . '">';
47726684e68SGreg Roach
47839ca88baSGreg Roach                if ($generation == $generations - 1 && $family->wife()->childFamilies()) {
47939ca88baSGreg Roach                    echo '<a href="#" title="' . I18N::translate('Parents') . '" data-route="Ancestors" data-xref="' .  e($ARID) . '" data-spouses="' .  e($show_spouse) . '" data-tree="' .  e($family->wife()->tree()->name()) . '">' . view('icons/arrow-right') . '</a>';
48026684e68SGreg Roach                }
48126684e68SGreg Roach
48239ca88baSGreg Roach                $this->printPersonPedigree($family->wife(), $generation + 1, $generations, $show_spouse);
48326684e68SGreg Roach                echo '</td>';
48426684e68SGreg Roach            }
48526684e68SGreg Roach            echo '</tr></table>';
48626684e68SGreg Roach        }
487e6562982SGreg Roach    }
488168ff6f3Sric2016}
489