xref: /webtrees/app/Module/InteractiveTree/TreeView.php (revision 1ff45046fabc22237b5d0d8e489c96f031fc598d)
18c2e8227SGreg Roach<?php
23976b470SGreg Roach
38c2e8227SGreg Roach/**
48c2e8227SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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
3010e06497SGreg Roachuse function count;
3110e06497SGreg Roach
3208b5db2aSGreg Roachuse const JSON_THROW_ON_ERROR;
3308b5db2aSGreg Roach
348c2e8227SGreg Roach/**
358c2e8227SGreg Roach * Class TreeView
368c2e8227SGreg Roach */
37c1010edaSGreg Roachclass TreeView
38c1010edaSGreg Roach{
3933c746f1SGreg Roach    // HTML element name
4033c746f1SGreg Roach    private string $name;
4176692c8bSGreg Roach
428c2e8227SGreg Roach    /**
438c2e8227SGreg Roach     * Treeview Constructor
448c2e8227SGreg Roach     *
458c2e8227SGreg Roach     * @param string $name the name of the TreeView object’s instance
468c2e8227SGreg Roach     */
471de81017SGreg Roach    public function __construct(string $name = 'tree')
48c1010edaSGreg Roach    {
498c2e8227SGreg Roach        $this->name = $name;
508c2e8227SGreg Roach    }
518c2e8227SGreg Roach
528c2e8227SGreg Roach    /**
538c2e8227SGreg Roach     * Draw the viewport which creates the draggable/zoomable framework
548c2e8227SGreg Roach     * Size is set by the container, as the viewport can scale itself automatically
558c2e8227SGreg Roach     *
56f8a18b14SGreg Roach     * @param Individual $individual  Draw the chart for this individual
57cbc1590aSGreg Roach     * @param int        $generations number of generations to draw
588c2e8227SGreg Roach     *
5924f2a3afSGreg Roach     * @return array<string>  HTML and Javascript
608c2e8227SGreg Roach     */
611de81017SGreg Roach    public function drawViewport(Individual $individual, int $generations): array
62c1010edaSGreg Roach    {
63575707d1SGreg Roach        $html = view('modules/interactive-tree/chart', [
6406f42609SGreg Roach            'module'     => 'tree',
65f8a18b14SGreg Roach            'name'       => $this->name,
661de81017SGreg Roach            'individual' => $this->drawPerson($individual, $generations, 0, null, '', true),
67ef5d23f1SGreg Roach            'tree'       => $individual->tree(),
68f8a18b14SGreg Roach        ]);
698c2e8227SGreg Roach
70c1010edaSGreg Roach        return [
71c1010edaSGreg Roach            $html,
72f4afa648SGreg Roach            'var ' . $this->name . 'Handler = new TreeViewHandler("' . $this->name . '", "' . e($individual->tree()->name()) . '");',
73c1010edaSGreg Roach        ];
748c2e8227SGreg Roach    }
758c2e8227SGreg Roach
768c2e8227SGreg Roach    /**
778c2e8227SGreg Roach     * Return a JSON structure to a JSON request
788c2e8227SGreg Roach     *
79bc8b8f24SGreg Roach     * @param Tree   $tree
80e364afe4SGreg Roach     * @param string $request list of JSON requests
818c2e8227SGreg Roach     *
828c2e8227SGreg Roach     * @return string
838c2e8227SGreg Roach     */
8406f42609SGreg Roach    public function getIndividuals(Tree $tree, string $request): string
85c1010edaSGreg Roach    {
86e364afe4SGreg Roach        $json_requests = explode(';', $request);
8713abd6f3SGreg Roach        $r             = [];
884fedbbe7SGreg Roach
89e364afe4SGreg Roach        foreach ($json_requests as $json_request) {
90e364afe4SGreg Roach            $firstLetter = substr($json_request, 0, 1);
91e364afe4SGreg Roach            $json_request = substr($json_request, 1);
921de81017SGreg Roach
938c2e8227SGreg Roach            switch ($firstLetter) {
948c2e8227SGreg Roach                case 'c':
95e364afe4SGreg Roach                    $families = Collection::make(explode(',', $json_request))
96*1ff45046SGreg Roach                        ->map(static fn(string $xref): Family|null => Registry::familyFactory()->make($xref, $tree))
97e364afe4SGreg Roach                        ->filter();
981de81017SGreg Roach
991de81017SGreg Roach                    $r[] = $this->drawChildren($families, 1, true);
1008c2e8227SGreg Roach                    break;
1011de81017SGreg Roach
1028c2e8227SGreg Roach                case 'p':
103e364afe4SGreg Roach                    [$xref, $order] = explode('@', $json_request);
1041de81017SGreg Roach
1056b9cb339SGreg Roach                    $family = Registry::familyFactory()->make($xref, $tree);
1061de81017SGreg Roach                    if ($family instanceof Family) {
1071de81017SGreg Roach                        // Prefer the paternal line
10839ca88baSGreg Roach                        $parent = $family->husband() ?? $family->wife();
1091de81017SGreg Roach
1101de81017SGreg Roach                        // The family may have no parents (just children).
1111de81017SGreg Roach                        if ($parent instanceof Individual) {
1121de81017SGreg Roach                            $r[] = $this->drawPerson($parent, 0, 1, $family, $order, false);
1131de81017SGreg Roach                        }
1148c2e8227SGreg Roach                    }
1158c2e8227SGreg Roach                    break;
1168c2e8227SGreg Roach            }
1178c2e8227SGreg Roach        }
118cbc1590aSGreg Roach
11908b5db2aSGreg Roach        return json_encode($r, JSON_THROW_ON_ERROR);
1208c2e8227SGreg Roach    }
1218c2e8227SGreg Roach
1228c2e8227SGreg Roach    /**
1238c2e8227SGreg Roach     * Get the details for a person and their life partner(s)
1248c2e8227SGreg Roach     *
1258c2e8227SGreg Roach     * @param Individual $individual the individual to return the details for
1268c2e8227SGreg Roach     *
1278c2e8227SGreg Roach     * @return string
1288c2e8227SGreg Roach     */
1298f53f488SRico Sonntag    public function getDetails(Individual $individual): string
130c1010edaSGreg Roach    {
1318c2e8227SGreg Roach        $html = $this->getPersonDetails($individual, null);
13239ca88baSGreg Roach        foreach ($individual->spouseFamilies() as $family) {
13339ca88baSGreg Roach            $spouse = $family->spouse($individual);
1348c2e8227SGreg Roach            if ($spouse) {
1358c2e8227SGreg Roach                $html .= $this->getPersonDetails($spouse, $family);
1368c2e8227SGreg Roach            }
1378c2e8227SGreg Roach        }
1388c2e8227SGreg Roach
1398c2e8227SGreg Roach        return $html;
1408c2e8227SGreg Roach    }
1418c2e8227SGreg Roach
1428c2e8227SGreg Roach    /**
1438c2e8227SGreg Roach     * Return the details for a person
1448c2e8227SGreg Roach     *
1458c2e8227SGreg Roach     * @param Individual  $individual
146d17d7b9eSGreg Roach     * @param Family|null $family
1478c2e8227SGreg Roach     *
1488c2e8227SGreg Roach     * @return string
1498c2e8227SGreg Roach     */
1502c6f1bd5SGreg Roach    private function getPersonDetails(Individual $individual, Family|null $family = null): string
151c1010edaSGreg Roach    {
152c1010edaSGreg Roach        $chart_url = route('module', [
153c1010edaSGreg Roach            'module' => 'tree',
154bee0d84bSGreg Roach            'action' => 'Chart',
155c0935879SGreg Roach            'xref'   => $individual->xref(),
156d72b284aSGreg Roach            'tree'   => $individual->tree()->name(),
157c1010edaSGreg Roach        ]);
158db35ed1eSGreg Roach
1598c2e8227SGreg Roach        $hmtl = $this->getThumbnail($individual);
160dc6db0eaSGreg 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="tv_link tv_treelink">' . view('icons/individual') . '</a>';
1618d0ebef0SGreg Roach        foreach ($individual->facts(Gedcom::BIRTH_EVENTS, true) as $fact) {
1628c2e8227SGreg Roach            $hmtl .= $fact->summary();
1638c2e8227SGreg Roach        }
164b6ec1ccfSGreg Roach        if ($family instanceof Family) {
1658d0ebef0SGreg Roach            foreach ($family->facts(Gedcom::MARRIAGE_EVENTS, true) as $fact) {
1668c2e8227SGreg Roach                $hmtl .= $fact->summary();
1678c2e8227SGreg Roach            }
1688c2e8227SGreg Roach        }
1698d0ebef0SGreg Roach        foreach ($individual->facts(Gedcom::DEATH_EVENTS, true) as $fact) {
1708c2e8227SGreg Roach            $hmtl .= $fact->summary();
1718c2e8227SGreg Roach        }
172cbc1590aSGreg Roach
17339ca88baSGreg Roach        return '<div class="tv' . $individual->sex() . ' tv_person_expanded">' . $hmtl . '</div>';
1748c2e8227SGreg Roach    }
1758c2e8227SGreg Roach
1768c2e8227SGreg Roach    /**
1778c2e8227SGreg Roach     * Draw the children for some families
1788c2e8227SGreg Roach     *
17936779af1SGreg Roach     * @param Collection<int,Family> $familyList array of families to draw the children for
180cbc1590aSGreg Roach     * @param int                    $gen        number of generations to draw
1819b5537c3SGreg Roach     * @param bool                   $ajax       true for an ajax call
1828c2e8227SGreg Roach     *
1838c2e8227SGreg Roach     * @return string
1848c2e8227SGreg Roach     */
18539ca88baSGreg Roach    private function drawChildren(Collection $familyList, int $gen = 1, bool $ajax = false): string
186c1010edaSGreg Roach    {
1878c2e8227SGreg Roach        $html          = '';
18813abd6f3SGreg Roach        $children2draw = [];
18913abd6f3SGreg Roach        $f2load        = [];
1908c2e8227SGreg Roach
1918c2e8227SGreg Roach        foreach ($familyList as $f) {
19239ca88baSGreg Roach            $children = $f->children();
193820b62dfSGreg Roach            if ($children->isNotEmpty()) {
194c0935879SGreg Roach                $f2load[] = $f->xref();
1958c2e8227SGreg Roach                foreach ($children as $child) {
1968c2e8227SGreg Roach                    // Eliminate duplicates - e.g. when adopted by a step-parent
197c0935879SGreg Roach                    $children2draw[$child->xref()] = $child;
1988c2e8227SGreg Roach                }
1998c2e8227SGreg Roach            }
2008c2e8227SGreg Roach        }
2018c2e8227SGreg Roach        $tc = count($children2draw);
2027fa97a69SGreg Roach        if ($tc > 0) {
2038c2e8227SGreg Roach            $f2load = implode(',', $f2load);
2048c2e8227SGreg Roach            $nbc    = 0;
2058c2e8227SGreg Roach            foreach ($children2draw as $child) {
2068c2e8227SGreg Roach                $nbc++;
2077fa97a69SGreg Roach                if ($tc === 1) {
2088c2e8227SGreg Roach                    $co = 'c'; // unique
2097fa97a69SGreg Roach                } elseif ($nbc === 1) {
2108c2e8227SGreg Roach                    $co = 't'; // first
2117fa97a69SGreg Roach                } elseif ($nbc === $tc) {
2128c2e8227SGreg Roach                    $co = 'b'; //last
2138c2e8227SGreg Roach                } else {
2148c2e8227SGreg Roach                    $co = 'h';
2158c2e8227SGreg Roach                }
2161de81017SGreg Roach                $html .= $this->drawPerson($child, $gen - 1, -1, null, $co, false);
2178c2e8227SGreg Roach            }
2188c2e8227SGreg Roach            if (!$ajax) {
2197fa97a69SGreg Roach                $html = '<td align="right"' . ($gen === 0 ? ' abbr="c' . $f2load . '"' : '') . '>' . $html . '</td>' . $this->drawHorizontalLine();
2208c2e8227SGreg Roach            }
2218c2e8227SGreg Roach        }
222cbc1590aSGreg Roach
2238c2e8227SGreg Roach        return $html;
2248c2e8227SGreg Roach    }
2258c2e8227SGreg Roach
2268c2e8227SGreg Roach    /**
2278c2e8227SGreg Roach     * Draw a person in the tree
2288c2e8227SGreg Roach     *
2298c2e8227SGreg Roach     * @param Individual  $person The Person object to draw the box for
230cbc1590aSGreg Roach     * @param int         $gen    The number of generations up or down to print
231cbc1590aSGreg Roach     * @param int         $state  Whether we are going up or down the tree, -1 for descendents +1 for ancestors
2321de81017SGreg Roach     * @param Family|null $pfamily
2331de81017SGreg Roach     * @param string      $line   b, c, h, t. Required for drawing lines between boxes
234cbc1590aSGreg Roach     * @param bool        $isRoot
2358c2e8227SGreg Roach     *
2368c2e8227SGreg Roach     * @return string
2378c2e8227SGreg Roach     */
238*1ff45046SGreg Roach    private function drawPerson(Individual $person, int $gen, int $state, Family|null $pfamily, string $line, bool $isRoot): string
239c1010edaSGreg Roach    {
2408c2e8227SGreg Roach        if ($gen < 0) {
2418c2e8227SGreg Roach            return '';
2428c2e8227SGreg Roach        }
2431de81017SGreg Roach
24437231d1eSGreg Roach        if ($pfamily instanceof Family) {
24539ca88baSGreg Roach            $partner = $pfamily->spouse($person);
2468c2e8227SGreg Roach        } else {
2478c2e8227SGreg Roach            $partner = $person->getCurrentSpouse();
2488c2e8227SGreg Roach        }
2491de81017SGreg Roach
2508c2e8227SGreg Roach        if ($isRoot) {
2518c2e8227SGreg 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>';
2528c2e8227SGreg Roach        } else {
2538c2e8227SGreg Roach            $html = '';
2548c2e8227SGreg Roach        }
2558c2e8227SGreg Roach        /* height 1% : this hack enable the div auto-dimensioning in td for FF & Chrome */
2568c2e8227SGreg Roach        $html .= '<table class="tv_tree"' . ($isRoot ? ' id="tv_tree"' : '') . ' style="height: 1%"><tbody><tr>';
2578c2e8227SGreg Roach
2588c2e8227SGreg Roach        if ($state <= 0) {
2598c2e8227SGreg Roach            // draw children
26039ca88baSGreg Roach            $html .= $this->drawChildren($person->spouseFamilies(), $gen);
2618c2e8227SGreg Roach        } else {
2628c2e8227SGreg Roach            // draw the parent’s lines
2631de81017SGreg Roach            $html .= $this->drawVerticalLine($line) . $this->drawHorizontalLine();
2648c2e8227SGreg Roach        }
2658c2e8227SGreg Roach
2668c2e8227SGreg 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 !!! */
2678c2e8227SGreg 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.
268c0935879SGreg 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);">';
2691de81017SGreg Roach        $html .= $this->drawPersonName($person, '');
27037231d1eSGreg Roach
27113abd6f3SGreg Roach        $fop = []; // $fop is fathers of partners
27237231d1eSGreg Roach
2738f038c36SRico Sonntag        if ($partner !== null) {
2748c2e8227SGreg Roach            $dashed = '';
27539ca88baSGreg Roach            foreach ($person->spouseFamilies() as $family) {
27639ca88baSGreg Roach                $spouse = $family->spouse($person);
2771de81017SGreg Roach                if ($spouse instanceof Individual) {
2781afbbc50SGreg Roach                    $spouse_parents = $spouse->childFamilies()->first();
2791de81017SGreg Roach                    if ($spouse_parents instanceof Family) {
28039ca88baSGreg Roach                        $spouse_parent = $spouse_parents->husband() ?? $spouse_parents->wife();
2811de81017SGreg Roach
28237231d1eSGreg Roach                        if ($spouse_parent instanceof Individual) {
28337231d1eSGreg Roach                            $fop[] = [$spouse_parent, $spouse_parents];
2848c2e8227SGreg Roach                        }
28537231d1eSGreg Roach                    }
28637231d1eSGreg Roach
2878c2e8227SGreg Roach                    $html .= $this->drawPersonName($spouse, $dashed);
2888c2e8227SGreg Roach                    $dashed = 'dashed';
2898c2e8227SGreg Roach                }
2908c2e8227SGreg Roach            }
2918c2e8227SGreg Roach        }
2928c2e8227SGreg Roach        $html .= '</div></td>';
2938c2e8227SGreg Roach
2941afbbc50SGreg Roach        $primaryChildFamily = $person->childFamilies()->first();
2951de81017SGreg Roach        if ($primaryChildFamily instanceof Family) {
29639ca88baSGreg Roach            $parent = $primaryChildFamily->husband() ?? $primaryChildFamily->wife();
2971de81017SGreg Roach        } else {
2981de81017SGreg Roach            $parent = null;
2998c2e8227SGreg Roach        }
3001de81017SGreg Roach
301b6ec1ccfSGreg Roach        if ($parent instanceof Individual || $fop !== [] || $state < 0) {
3028c2e8227SGreg Roach            $html .= $this->drawHorizontalLine();
3038c2e8227SGreg Roach        }
3041de81017SGreg Roach
3058c2e8227SGreg Roach        /* draw the parents */
306b6ec1ccfSGreg Roach        if ($state >= 0 && ($parent instanceof Individual || $fop !== [])) {
307b6ec1ccfSGreg Roach            $unique = $parent === null || $fop === [];
30834377a77SGreg Roach            $html .= '<td align="left"><table class="tv_tree"><tbody>';
3091de81017SGreg Roach
31037231d1eSGreg Roach            if ($parent instanceof Individual) {
3118c2e8227SGreg Roach                $u = $unique ? 'c' : 't';
3127fa97a69SGreg Roach                $html .= '<tr><td ' . ($gen === 0 ? ' abbr="p' . $primaryChildFamily->xref() . '@' . $u . '"' : '') . '>';
3131de81017SGreg Roach                $html .= $this->drawPerson($parent, $gen - 1, 1, $primaryChildFamily, $u, false);
3148c2e8227SGreg Roach                $html .= '</td></tr>';
3158c2e8227SGreg Roach            }
3161de81017SGreg Roach
317b6ec1ccfSGreg Roach            if ($fop !== []) {
3188c2e8227SGreg Roach                $n  = 0;
3198c2e8227SGreg Roach                $nb = count($fop);
3208c2e8227SGreg Roach                foreach ($fop as $p) {
3218c2e8227SGreg Roach                    $n++;
3227fa97a69SGreg Roach                    $u = $unique ? 'c' : ($n === $nb || empty($p[1]) ? 'b' : 'h');
3237fa97a69SGreg 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>';
3248c2e8227SGreg Roach                }
3258c2e8227SGreg Roach            }
3268c2e8227SGreg Roach            $html .= '</tbody></table></td>';
3278c2e8227SGreg Roach        }
3281de81017SGreg Roach
3298c2e8227SGreg Roach        if ($state < 0) {
3301de81017SGreg Roach            $html .= $this->drawVerticalLine($line);
3318c2e8227SGreg Roach        }
3321de81017SGreg Roach
3338c2e8227SGreg Roach        $html .= '</tr></tbody></table>';
3341de81017SGreg Roach
3358c2e8227SGreg Roach        if ($isRoot) {
3368c2e8227SGreg 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>';
3378c2e8227SGreg Roach        }
338cbc1590aSGreg Roach
3398c2e8227SGreg Roach        return $html;
3408c2e8227SGreg Roach    }
3418c2e8227SGreg Roach
3428c2e8227SGreg Roach    /**
3438c2e8227SGreg Roach     * Draw a person name preceded by sex icon, with parents as tooltip
3448c2e8227SGreg Roach     *
3451de81017SGreg Roach     * @param Individual $individual The individual to draw
3461de81017SGreg Roach     * @param string     $dashed     Either "dashed", to print dashed top border to separate multiple spouses, or ""
3478c2e8227SGreg Roach     *
3488c2e8227SGreg Roach     * @return string
3498c2e8227SGreg Roach     */
3501de81017SGreg Roach    private function drawPersonName(Individual $individual, string $dashed): string
351c1010edaSGreg Roach    {
3521afbbc50SGreg Roach        $family = $individual->childFamilies()->first();
3538c2e8227SGreg Roach        if ($family) {
35439ca88baSGreg Roach            $family_name = strip_tags($family->fullName());
3551a92e6b6SGreg Roach        } else {
3561a92e6b6SGreg Roach            $family_name = I18N::translateContext('unknown family', 'unknown');
3571a92e6b6SGreg Roach        }
35839ca88baSGreg Roach        switch ($individual->sex()) {
3598c2e8227SGreg Roach            case 'M':
360bbb76c12SGreg Roach                /* I18N: e.g. “Son of [father name & mother name]” */
361bbb76c12SGreg Roach                $title = ' title="' . I18N::translate('Son of %s', $family_name) . '"';
3628c2e8227SGreg Roach                break;
3638c2e8227SGreg Roach            case 'F':
364bbb76c12SGreg Roach                /* I18N: e.g. “Daughter of [father name & mother name]” */
365bbb76c12SGreg Roach                $title = ' title="' . I18N::translate('Daughter of %s', $family_name) . '"';
3668c2e8227SGreg Roach                break;
3678c2e8227SGreg Roach            default:
368bbb76c12SGreg Roach                /* I18N: e.g. “Child of [father name & mother name]” */
369bbb76c12SGreg Roach                $title = ' title="' . I18N::translate('Child of %s', $family_name) . '"';
3708c2e8227SGreg Roach                break;
3718c2e8227SGreg Roach        }
37239ca88baSGreg Roach        $sex = $individual->sex();
373cbc1590aSGreg Roach
3745e6816beSGreg Roach        return '<div class="tv' . $sex . ' ' . $dashed . '"' . $title . '><a href="' . e($individual->url()) . '"></a>' . $individual->fullName() . ' <span class="dates">' . $individual->lifespan() . '</span></div>';
3758c2e8227SGreg Roach    }
3768c2e8227SGreg Roach
3778c2e8227SGreg Roach    /**
3788c2e8227SGreg Roach     * Get the thumbnail image for the given person
3798c2e8227SGreg Roach     *
3808c2e8227SGreg Roach     * @param Individual $individual
3818c2e8227SGreg Roach     *
3828c2e8227SGreg Roach     * @return string
3838c2e8227SGreg Roach     */
3841de81017SGreg Roach    private function getThumbnail(Individual $individual): string
385c1010edaSGreg Roach    {
386b6ec1ccfSGreg Roach        if ($individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES') !== '' && $individual->tree()->getPreference('SHOW_HIGHLIGHT_IMAGES') !== '0') {
387dce07401SGreg Roach            return $individual->displayImage(40, 50, 'crop', []);
3888c2e8227SGreg Roach        }
389b2ce94c6SRico Sonntag
390b2ce94c6SRico Sonntag        return '';
3918c2e8227SGreg Roach    }
3928c2e8227SGreg Roach
3938c2e8227SGreg Roach    /**
3948c2e8227SGreg Roach     * Draw a vertical line
3958c2e8227SGreg Roach     *
396fceda430SGreg Roach     * @param string $line A parameter that set how to draw this line with auto-resizing capabilities
3978c2e8227SGreg Roach     *
3988c2e8227SGreg Roach     * @return string
3998c2e8227SGreg Roach     * WARNING : some tricky hacks are required in CSS to ensure cross-browser compliance
4008c2e8227SGreg Roach     * some browsers shows an image, which imply a size limit in height,
4018c2e8227SGreg Roach     * and some other browsers (ex: firefox) shows a <div> tag, which have no size limit in height
4028c2e8227SGreg Roach     * Therefore, Firefox is a good choice to print very big trees.
4038c2e8227SGreg Roach     */
4041de81017SGreg Roach    private function drawVerticalLine(string $line): string
405c1010edaSGreg Roach    {
4061de81017SGreg Roach        return '<td class="tv_vline tv_vline_' . $line . '"><div class="tv_vline tv_vline_' . $line . '"></div></td>';
4078c2e8227SGreg Roach    }
4088c2e8227SGreg Roach
4098c2e8227SGreg Roach    /**
4108c2e8227SGreg Roach     * Draw an horizontal line
4118c2e8227SGreg Roach     */
4128f53f488SRico Sonntag    private function drawHorizontalLine(): string
413c1010edaSGreg Roach    {
4148c2e8227SGreg Roach        return '<td class="tv_hline"><div class="tv_hline"></div></td>';
4158c2e8227SGreg Roach    }
4168c2e8227SGreg Roach}
417