xref: /webtrees/app/Module/InteractiveTree/TreeView.php (revision 73d58381388d199b1beb6f2a613b98f25617f706)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
68c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
78c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
88c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
98c2e8227SGreg Roach * (at your option) any later version.
108c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
118c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
128c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
138c2e8227SGreg Roach * GNU General Public License for more details.
148c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
168c2e8227SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
2076692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module\InteractiveTree;
2176692c8bSGreg Roach
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Family;
238d0ebef0SGreg Roachuse Fisharebest\Webtrees\Gedcom;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual;
26ac701fbdSGreg Roachuse Fisharebest\Webtrees\Registry;
27bc8b8f24SGreg Roachuse Fisharebest\Webtrees\Tree;
2839ca88baSGreg Roachuse Illuminate\Support\Collection;
298c2e8227SGreg Roach
3008b5db2aSGreg Roachuse const JSON_THROW_ON_ERROR;
3108b5db2aSGreg Roach
328c2e8227SGreg Roach/**
338c2e8227SGreg Roach * Class TreeView
348c2e8227SGreg Roach */
35c1010edaSGreg Roachclass TreeView
36c1010edaSGreg Roach{
3776692c8bSGreg Roach    /** @var string HTML element name */
388c2e8227SGreg Roach    private $name;
3976692c8bSGreg Roach
408c2e8227SGreg Roach    /**
418c2e8227SGreg Roach     * Treeview Constructor
428c2e8227SGreg Roach     *
438c2e8227SGreg Roach     * @param string $name the name of the TreeView object’s instance
448c2e8227SGreg Roach     */
451de81017SGreg Roach    public function __construct(string $name = 'tree')
46c1010edaSGreg Roach    {
478c2e8227SGreg Roach        $this->name = $name;
488c2e8227SGreg Roach    }
498c2e8227SGreg Roach
508c2e8227SGreg Roach    /**
518c2e8227SGreg Roach     * Draw the viewport which creates the draggable/zoomable framework
528c2e8227SGreg Roach     * Size is set by the container, as the viewport can scale itself automatically
538c2e8227SGreg Roach     *
54f8a18b14SGreg Roach     * @param Individual $individual  Draw the chart for this individual
55cbc1590aSGreg Roach     * @param int        $generations number of generations to draw
568c2e8227SGreg Roach     *
5724f2a3afSGreg Roach     * @return array<string>  HTML and Javascript
588c2e8227SGreg Roach     */
591de81017SGreg Roach    public function drawViewport(Individual $individual, int $generations): array
60c1010edaSGreg Roach    {
61575707d1SGreg Roach        $html = view('modules/interactive-tree/chart', [
6206f42609SGreg Roach            'module'     => 'tree',
63f8a18b14SGreg Roach            'name'       => $this->name,
641de81017SGreg Roach            'individual' => $this->drawPerson($individual, $generations, 0, null, '', true),
65ef5d23f1SGreg Roach            'tree'       => $individual->tree(),
66f8a18b14SGreg Roach        ]);
678c2e8227SGreg Roach
68c1010edaSGreg Roach        return [
69c1010edaSGreg Roach            $html,
70f4afa648SGreg Roach            'var ' . $this->name . 'Handler = new TreeViewHandler("' . $this->name . '", "' . e($individual->tree()->name()) . '");',
71c1010edaSGreg Roach        ];
728c2e8227SGreg Roach    }
738c2e8227SGreg Roach
748c2e8227SGreg Roach    /**
758c2e8227SGreg Roach     * Return a JSON structure to a JSON request
768c2e8227SGreg Roach     *
77bc8b8f24SGreg Roach     * @param Tree   $tree
78e364afe4SGreg Roach     * @param string $request list of JSON requests
798c2e8227SGreg Roach     *
808c2e8227SGreg Roach     * @return string
818c2e8227SGreg Roach     */
8206f42609SGreg Roach    public function getIndividuals(Tree $tree, string $request): string
83c1010edaSGreg Roach    {
84e364afe4SGreg Roach        $json_requests = explode(';', $request);
8513abd6f3SGreg Roach        $r    = [];
86e364afe4SGreg Roach        foreach ($json_requests as $json_request) {
87e364afe4SGreg Roach            $firstLetter = substr($json_request, 0, 1);
88e364afe4SGreg Roach            $json_request = substr($json_request, 1);
891de81017SGreg Roach
908c2e8227SGreg Roach            switch ($firstLetter) {
918c2e8227SGreg Roach                case 'c':
92e364afe4SGreg Roach                    $families = Collection::make(explode(',', $json_request))
930b5fd0a6SGreg Roach                        ->map(static function (string $xref) use ($tree): ?Family {
946b9cb339SGreg Roach                            return Registry::familyFactory()->make($xref, $tree);
95e364afe4SGreg Roach                        })
96e364afe4SGreg Roach                        ->filter();
971de81017SGreg Roach
981de81017SGreg Roach                    $r[] = $this->drawChildren($families, 1, true);
998c2e8227SGreg Roach                    break;
1001de81017SGreg Roach
1018c2e8227SGreg Roach                case 'p':
102e364afe4SGreg Roach                    [$xref, $order] = explode('@', $json_request);
1031de81017SGreg Roach
1046b9cb339SGreg Roach                    $family = Registry::familyFactory()->make($xref, $tree);
1051de81017SGreg Roach                    if ($family instanceof Family) {
1061de81017SGreg Roach                        // Prefer the paternal line
10739ca88baSGreg Roach                        $parent = $family->husband() ?? $family->wife();
1081de81017SGreg Roach
1091de81017SGreg Roach                        // The family may have no parents (just children).
1101de81017SGreg Roach                        if ($parent instanceof Individual) {
1111de81017SGreg Roach                            $r[] = $this->drawPerson($parent, 0, 1, $family, $order, false);
1121de81017SGreg Roach                        }
1138c2e8227SGreg Roach                    }
1148c2e8227SGreg Roach                    break;
1158c2e8227SGreg Roach            }
1168c2e8227SGreg Roach        }
117cbc1590aSGreg Roach
11808b5db2aSGreg Roach        return json_encode($r, JSON_THROW_ON_ERROR);
1198c2e8227SGreg Roach    }
1208c2e8227SGreg Roach
1218c2e8227SGreg Roach    /**
1228c2e8227SGreg Roach     * Get the details for a person and their life partner(s)
1238c2e8227SGreg Roach     *
1248c2e8227SGreg Roach     * @param Individual $individual the individual to return the details for
1258c2e8227SGreg Roach     *
1268c2e8227SGreg Roach     * @return string
1278c2e8227SGreg Roach     */
1288f53f488SRico Sonntag    public function getDetails(Individual $individual): string
129c1010edaSGreg Roach    {
1308c2e8227SGreg Roach        $html = $this->getPersonDetails($individual, null);
13139ca88baSGreg Roach        foreach ($individual->spouseFamilies() as $family) {
13239ca88baSGreg Roach            $spouse = $family->spouse($individual);
1338c2e8227SGreg Roach            if ($spouse) {
1348c2e8227SGreg Roach                $html .= $this->getPersonDetails($spouse, $family);
1358c2e8227SGreg Roach            }
1368c2e8227SGreg Roach        }
1378c2e8227SGreg Roach
1388c2e8227SGreg Roach        return $html;
1398c2e8227SGreg Roach    }
1408c2e8227SGreg Roach
1418c2e8227SGreg Roach    /**
1428c2e8227SGreg Roach     * Return the details for a person
1438c2e8227SGreg Roach     *
1448c2e8227SGreg Roach     * @param Individual  $individual
145d17d7b9eSGreg Roach     * @param Family|null $family
1468c2e8227SGreg Roach     *
1478c2e8227SGreg Roach     * @return string
1488c2e8227SGreg Roach     */
1498f53f488SRico Sonntag    private function getPersonDetails(Individual $individual, Family $family = null): string
150c1010edaSGreg Roach    {
151c1010edaSGreg Roach        $chart_url = route('module', [
152c1010edaSGreg Roach            'module' => 'tree',
153bee0d84bSGreg Roach            'action' => 'Chart',
154c0935879SGreg Roach            'xref'   => $individual->xref(),
155d72b284aSGreg Roach            'tree'   => $individual->tree()->name(),
156c1010edaSGreg Roach        ]);
157db35ed1eSGreg Roach
1588c2e8227SGreg Roach        $hmtl = $this->getThumbnail($individual);
15939ca88baSGreg Roach        $hmtl .= '<a class="tv_link" href="' . e($individual->url()) . '">' . $individual->fullName() . '</a> <a href="' . e($chart_url) . '" title="' . I18N::translate('Interactive tree of %s', strip_tags($individual->fullName())) . '" class="wt-icon-individual tv_link tv_treelink"></a>';
1608d0ebef0SGreg Roach        foreach ($individual->facts(Gedcom::BIRTH_EVENTS, true) as $fact) {
1618c2e8227SGreg Roach            $hmtl .= $fact->summary();
1628c2e8227SGreg Roach        }
1638c2e8227SGreg Roach        if ($family) {
1648d0ebef0SGreg Roach            foreach ($family->facts(Gedcom::MARRIAGE_EVENTS, true) as $fact) {
1658c2e8227SGreg Roach                $hmtl .= $fact->summary();
1668c2e8227SGreg Roach            }
1678c2e8227SGreg Roach        }
1688d0ebef0SGreg Roach        foreach ($individual->facts(Gedcom::DEATH_EVENTS, true) as $fact) {
1698c2e8227SGreg Roach            $hmtl .= $fact->summary();
1708c2e8227SGreg Roach        }
171cbc1590aSGreg Roach
17239ca88baSGreg Roach        return '<div class="tv' . $individual->sex() . ' tv_person_expanded">' . $hmtl . '</div>';
1738c2e8227SGreg Roach    }
1748c2e8227SGreg Roach
1758c2e8227SGreg Roach    /**
1768c2e8227SGreg Roach     * Draw the children for some families
1778c2e8227SGreg Roach     *
178ac701fbdSGreg Roach     * @param Collection<Family> $familyList array of families to draw the children for
179cbc1590aSGreg Roach     * @param int                $gen        number of generations to draw
1809b5537c3SGreg Roach     * @param bool               $ajax       true for an ajax call
1818c2e8227SGreg Roach     *
1828c2e8227SGreg Roach     * @return string
1838c2e8227SGreg Roach     */
18439ca88baSGreg Roach    private function drawChildren(Collection $familyList, int $gen = 1, bool $ajax = false): string
185c1010edaSGreg Roach    {
1868c2e8227SGreg Roach        $html          = '';
18713abd6f3SGreg Roach        $children2draw = [];
18813abd6f3SGreg Roach        $f2load        = [];
1898c2e8227SGreg Roach
1908c2e8227SGreg Roach        foreach ($familyList as $f) {
19139ca88baSGreg Roach            $children = $f->children();
192820b62dfSGreg Roach            if ($children->isNotEmpty()) {
193c0935879SGreg Roach                $f2load[] = $f->xref();
1948c2e8227SGreg Roach                foreach ($children as $child) {
1958c2e8227SGreg Roach                    // Eliminate duplicates - e.g. when adopted by a step-parent
196c0935879SGreg Roach                    $children2draw[$child->xref()] = $child;
1978c2e8227SGreg Roach                }
1988c2e8227SGreg Roach            }
1998c2e8227SGreg Roach        }
2008c2e8227SGreg Roach        $tc = count($children2draw);
2018c2e8227SGreg Roach        if ($tc) {
2028c2e8227SGreg Roach            $f2load = implode(',', $f2load);
2038c2e8227SGreg Roach            $nbc    = 0;
2048c2e8227SGreg Roach            foreach ($children2draw as $child) {
2058c2e8227SGreg Roach                $nbc++;
2068c2e8227SGreg Roach                if ($tc == 1) {
2078c2e8227SGreg Roach                    $co = 'c'; // unique
2088c2e8227SGreg Roach                } elseif ($nbc == 1) {
2098c2e8227SGreg Roach                    $co = 't'; // first
2108c2e8227SGreg Roach                } elseif ($nbc == $tc) {
2118c2e8227SGreg Roach                    $co = 'b'; //last
2128c2e8227SGreg Roach                } else {
2138c2e8227SGreg Roach                    $co = 'h';
2148c2e8227SGreg Roach                }
2151de81017SGreg Roach                $html .= $this->drawPerson($child, $gen - 1, -1, null, $co, false);
2168c2e8227SGreg Roach            }
2178c2e8227SGreg Roach            if (!$ajax) {
21834377a77SGreg Roach                $html = '<td align="right"' . ($gen == 0 ? ' abbr="c' . $f2load . '"' : '') . '>' . $html . '</td>' . $this->drawHorizontalLine();
2198c2e8227SGreg Roach            }
2208c2e8227SGreg Roach        }
221cbc1590aSGreg Roach
2228c2e8227SGreg Roach        return $html;
2238c2e8227SGreg Roach    }
2248c2e8227SGreg Roach
2258c2e8227SGreg Roach    /**
2268c2e8227SGreg Roach     * Draw a person in the tree
2278c2e8227SGreg Roach     *
2288c2e8227SGreg Roach     * @param Individual  $person The Person object to draw the box for
229cbc1590aSGreg Roach     * @param int         $gen    The number of generations up or down to print
230cbc1590aSGreg Roach     * @param int         $state  Whether we are going up or down the tree, -1 for descendents +1 for ancestors
2311de81017SGreg Roach     * @param Family|null $pfamily
2321de81017SGreg Roach     * @param string      $line   b, c, h, t. Required for drawing lines between boxes
233cbc1590aSGreg Roach     * @param bool        $isRoot
2348c2e8227SGreg Roach     *
2358c2e8227SGreg Roach     * @return string
2368c2e8227SGreg Roach     */
237*73d58381SGreg Roach    private function drawPerson(Individual $person, int $gen, int $state, ?Family $pfamily, string $line, bool $isRoot): string
238c1010edaSGreg Roach    {
2398c2e8227SGreg Roach        if ($gen < 0) {
2408c2e8227SGreg Roach            return '';
2418c2e8227SGreg Roach        }
2421de81017SGreg Roach
24337231d1eSGreg Roach        if ($pfamily instanceof Family) {
24439ca88baSGreg Roach            $partner = $pfamily->spouse($person);
2458c2e8227SGreg Roach        } else {
2468c2e8227SGreg Roach            $partner = $person->getCurrentSpouse();
2478c2e8227SGreg Roach        }
2481de81017SGreg Roach
2498c2e8227SGreg Roach        if ($isRoot) {
2508c2e8227SGreg Roach            $html = '<table id="tvTreeBorder" class="tv_tree"><tbody><tr><td id="tv_tree_topleft"></td><td id="tv_tree_top"></td><td id="tv_tree_topright"></td></tr><tr><td id="tv_tree_left"></td><td>';
2518c2e8227SGreg Roach        } else {
2528c2e8227SGreg Roach            $html = '';
2538c2e8227SGreg Roach        }
2548c2e8227SGreg Roach        /* height 1% : this hack enable the div auto-dimensioning in td for FF & Chrome */
2558c2e8227SGreg Roach        $html .= '<table class="tv_tree"' . ($isRoot ? ' id="tv_tree"' : '') . ' style="height: 1%"><tbody><tr>';
2568c2e8227SGreg Roach
2578c2e8227SGreg Roach        if ($state <= 0) {
2588c2e8227SGreg Roach            // draw children
25939ca88baSGreg Roach            $html .= $this->drawChildren($person->spouseFamilies(), $gen);
2608c2e8227SGreg Roach        } else {
2618c2e8227SGreg Roach            // draw the parent’s lines
2621de81017SGreg Roach            $html .= $this->drawVerticalLine($line) . $this->drawHorizontalLine();
2638c2e8227SGreg Roach        }
2648c2e8227SGreg Roach
2658c2e8227SGreg Roach        /* draw the person. Do NOT add person or family id as an id, since a same person could appear more than once in the tree !!! */
2668c2e8227SGreg Roach        // Fixing the width for td to the box initial width when the person is the root person fix a rare bug that happen when a person without child and without known parents is the root person : an unwanted white rectangle appear at the right of the person’s boxes, otherwise.
267c0935879SGreg Roach        $html .= '<td' . ($isRoot ? ' style="width:1px"' : '') . '><div class="tv_box' . ($isRoot ? ' rootPerson' : '') . '" dir="' . I18N::direction() . '" style="text-align: ' . (I18N::direction() === 'rtl' ? 'right' : 'left') . '; direction: ' . I18N::direction() . '" abbr="' . $person->xref() . '" onclick="' . $this->name . 'Handler.expandBox(this, event);">';
2681de81017SGreg Roach        $html .= $this->drawPersonName($person, '');
26937231d1eSGreg Roach
27013abd6f3SGreg Roach        $fop = []; // $fop is fathers of partners
27137231d1eSGreg Roach
2728f038c36SRico Sonntag        if ($partner !== null) {
2738c2e8227SGreg Roach            $dashed = '';
27439ca88baSGreg Roach            foreach ($person->spouseFamilies() as $family) {
27539ca88baSGreg Roach                $spouse = $family->spouse($person);
2761de81017SGreg Roach                if ($spouse instanceof Individual) {
2771afbbc50SGreg Roach                    $spouse_parents = $spouse->childFamilies()->first();
2781de81017SGreg Roach                    if ($spouse_parents instanceof Family) {
27939ca88baSGreg Roach                        $spouse_parent = $spouse_parents->husband() ?? $spouse_parents->wife();
2801de81017SGreg Roach
28137231d1eSGreg Roach                        if ($spouse_parent instanceof Individual) {
28237231d1eSGreg Roach                            $fop[] = [$spouse_parent, $spouse_parents];
2838c2e8227SGreg Roach                        }
28437231d1eSGreg Roach                    }
28537231d1eSGreg Roach
2868c2e8227SGreg Roach                    $html .= $this->drawPersonName($spouse, $dashed);
2878c2e8227SGreg Roach                    $dashed = 'dashed';
2888c2e8227SGreg Roach                }
2898c2e8227SGreg Roach            }
2908c2e8227SGreg Roach        }
2918c2e8227SGreg Roach        $html .= '</div></td>';
2928c2e8227SGreg Roach
2931afbbc50SGreg Roach        $primaryChildFamily = $person->childFamilies()->first();
2941de81017SGreg Roach        if ($primaryChildFamily instanceof Family) {
29539ca88baSGreg Roach            $parent = $primaryChildFamily->husband() ?? $primaryChildFamily->wife();
2961de81017SGreg Roach        } else {
2971de81017SGreg Roach            $parent = null;
2988c2e8227SGreg Roach        }
2991de81017SGreg Roach
3001de81017SGreg Roach        if ($parent instanceof Individual || !empty($fop) || $state < 0) {
3018c2e8227SGreg Roach            $html .= $this->drawHorizontalLine();
3028c2e8227SGreg Roach        }
3031de81017SGreg Roach
3048c2e8227SGreg Roach        /* draw the parents */
30537231d1eSGreg Roach        if ($state >= 0 && ($parent instanceof Individual || !empty($fop))) {
3061de81017SGreg Roach            $unique = $parent === null || empty($fop);
30734377a77SGreg Roach            $html .= '<td align="left"><table class="tv_tree"><tbody>';
3081de81017SGreg Roach
30937231d1eSGreg Roach            if ($parent instanceof Individual) {
3108c2e8227SGreg Roach                $u = $unique ? 'c' : 't';
311c0935879SGreg Roach                $html .= '<tr><td ' . ($gen == 0 ? ' abbr="p' . $primaryChildFamily->xref() . '@' . $u . '"' : '') . '>';
3121de81017SGreg Roach                $html .= $this->drawPerson($parent, $gen - 1, 1, $primaryChildFamily, $u, false);
3138c2e8227SGreg Roach                $html .= '</td></tr>';
3148c2e8227SGreg Roach            }
3151de81017SGreg Roach
3168c2e8227SGreg Roach            if (count($fop)) {
3178c2e8227SGreg Roach                $n  = 0;
3188c2e8227SGreg Roach                $nb = count($fop);
3198c2e8227SGreg Roach                foreach ($fop as $p) {
3208c2e8227SGreg Roach                    $n++;
3218c2e8227SGreg Roach                    $u = $unique ? 'c' : ($n == $nb || empty($p[1]) ? 'b' : 'h');
322c0935879SGreg Roach                    $html .= '<tr><td ' . ($gen == 0 ? ' abbr="p' . $p[1]->xref() . '@' . $u . '"' : '') . '>' . $this->drawPerson($p[0], $gen - 1, 1, $p[1], $u, false) . '</td></tr>';
3238c2e8227SGreg Roach                }
3248c2e8227SGreg Roach            }
3258c2e8227SGreg Roach            $html .= '</tbody></table></td>';
3268c2e8227SGreg Roach        }
3271de81017SGreg Roach
3288c2e8227SGreg Roach        if ($state < 0) {
3291de81017SGreg Roach            $html .= $this->drawVerticalLine($line);
3308c2e8227SGreg Roach        }
3311de81017SGreg Roach
3328c2e8227SGreg Roach        $html .= '</tr></tbody></table>';
3331de81017SGreg Roach
3348c2e8227SGreg Roach        if ($isRoot) {
3358c2e8227SGreg Roach            $html .= '</td><td id="tv_tree_right"></td></tr><tr><td id="tv_tree_bottomleft"></td><td id="tv_tree_bottom"></td><td id="tv_tree_bottomright"></td></tr></tbody></table>';
3368c2e8227SGreg Roach        }
337cbc1590aSGreg Roach
3388c2e8227SGreg Roach        return $html;
3398c2e8227SGreg Roach    }
3408c2e8227SGreg Roach
3418c2e8227SGreg Roach    /**
3428c2e8227SGreg Roach     * Draw a person name preceded by sex icon, with parents as tooltip
3438c2e8227SGreg Roach     *
3441de81017SGreg Roach     * @param Individual $individual The individual to draw
3451de81017SGreg Roach     * @param string     $dashed     Either "dashed", to print dashed top border to separate multiple spouses, or ""
3468c2e8227SGreg Roach     *
3478c2e8227SGreg Roach     * @return string
3488c2e8227SGreg Roach     */
3491de81017SGreg Roach    private function drawPersonName(Individual $individual, string $dashed): string
350c1010edaSGreg Roach    {
3511afbbc50SGreg Roach        $family = $individual->childFamilies()->first();
3528c2e8227SGreg Roach        if ($family) {
35339ca88baSGreg Roach            $family_name = strip_tags($family->fullName());
3541a92e6b6SGreg Roach        } else {
3551a92e6b6SGreg Roach            $family_name = I18N::translateContext('unknown family', 'unknown');
3561a92e6b6SGreg Roach        }
35739ca88baSGreg Roach        switch ($individual->sex()) {
3588c2e8227SGreg Roach            case 'M':
359bbb76c12SGreg Roach                /* I18N: e.g. “Son of [father name & mother name]” */
360bbb76c12SGreg Roach                $title = ' title="' . I18N::translate('Son of %s', $family_name) . '"';
3618c2e8227SGreg Roach                break;
3628c2e8227SGreg Roach            case 'F':
363bbb76c12SGreg Roach                /* I18N: e.g. “Daughter of [father name & mother name]” */
364bbb76c12SGreg Roach                $title = ' title="' . I18N::translate('Daughter of %s', $family_name) . '"';
3658c2e8227SGreg Roach                break;
3668c2e8227SGreg Roach            default:
367bbb76c12SGreg Roach                /* I18N: e.g. “Child of [father name & mother name]” */
368bbb76c12SGreg Roach                $title = ' title="' . I18N::translate('Child of %s', $family_name) . '"';
3698c2e8227SGreg Roach                break;
3708c2e8227SGreg Roach        }
37139ca88baSGreg Roach        $sex = $individual->sex();
372cbc1590aSGreg Roach
3735e6816beSGreg Roach        return '<div class="tv' . $sex . ' ' . $dashed . '"' . $title . '><a href="' . e($individual->url()) . '"></a>' . $individual->fullName() . ' <span class="dates">' . $individual->lifespan() . '</span></div>';
3748c2e8227SGreg Roach    }
3758c2e8227SGreg Roach
3768c2e8227SGreg Roach    /**
3778c2e8227SGreg Roach     * Get the thumbnail image for the given person
3788c2e8227SGreg Roach     *
3798c2e8227SGreg Roach     * @param Individual $individual
3808c2e8227SGreg Roach     *
3818c2e8227SGreg Roach     * @return string
3828c2e8227SGreg Roach     */
3831de81017SGreg Roach    private function getThumbnail(Individual $individual): string
384c1010edaSGreg Roach    {
385f4afa648SGreg Roach        if ($individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES')) {
386dce07401SGreg Roach            return $individual->displayImage(40, 50, 'crop', []);
3878c2e8227SGreg Roach        }
388b2ce94c6SRico Sonntag
389b2ce94c6SRico Sonntag        return '';
3908c2e8227SGreg Roach    }
3918c2e8227SGreg Roach
3928c2e8227SGreg Roach    /**
3938c2e8227SGreg Roach     * Draw a vertical line
3948c2e8227SGreg Roach     *
395fceda430SGreg Roach     * @param string $line A parameter that set how to draw this line with auto-resizing capabilities
3968c2e8227SGreg Roach     *
3978c2e8227SGreg Roach     * @return string
3988c2e8227SGreg Roach     * WARNING : some tricky hacks are required in CSS to ensure cross-browser compliance
3998c2e8227SGreg Roach     * some browsers shows an image, which imply a size limit in height,
4008c2e8227SGreg Roach     * and some other browsers (ex: firefox) shows a <div> tag, which have no size limit in height
4018c2e8227SGreg Roach     * Therefore, Firefox is a good choice to print very big trees.
4028c2e8227SGreg Roach     */
4031de81017SGreg Roach    private function drawVerticalLine(string $line): string
404c1010edaSGreg Roach    {
4051de81017SGreg Roach        return '<td class="tv_vline tv_vline_' . $line . '"><div class="tv_vline tv_vline_' . $line . '"></div></td>';
4068c2e8227SGreg Roach    }
4078c2e8227SGreg Roach
4088c2e8227SGreg Roach    /**
4098c2e8227SGreg Roach     * Draw an horizontal line
4108c2e8227SGreg Roach     */
4118f53f488SRico Sonntag    private function drawHorizontalLine(): string
412c1010edaSGreg Roach    {
4138c2e8227SGreg Roach        return '<td class="tv_hline"><div class="tv_hline"></div></td>';
4148c2e8227SGreg Roach    }
4158c2e8227SGreg Roach}
416