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 2054452b04SGreg Roachuse Fisharebest\Webtrees\Auth; 21e5a6b4d4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 2254452b04SGreg Roachuse Fisharebest\Webtrees\Family; 2354452b04SGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsCharts; 2454452b04SGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrint; 2554452b04SGreg Roachuse Fisharebest\Webtrees\Gedcom; 2654452b04SGreg Roachuse Fisharebest\Webtrees\GedcomTag; 27168ff6f3Sric2016use Fisharebest\Webtrees\I18N; 28168ff6f3Sric2016use Fisharebest\Webtrees\Individual; 29e46b0479SScrutinizer Auto-Fixeruse Fisharebest\Webtrees\Menu; 3054452b04SGreg Roachuse Fisharebest\Webtrees\Services\ChartService; 3154452b04SGreg Roachuse Fisharebest\Webtrees\Tree; 3254452b04SGreg Roachuse Illuminate\Support\Collection; 3354452b04SGreg Roachuse Ramsey\Uuid\Uuid; 3454452b04SGreg Roachuse Symfony\Component\HttpFoundation\Request; 3554452b04SGreg Roachuse Symfony\Component\HttpFoundation\Response; 36168ff6f3Sric2016 37168ff6f3Sric2016/** 38168ff6f3Sric2016 * Class DescendancyChartModule 39168ff6f3Sric2016 */ 4037eb8894SGreg Roachclass DescendancyChartModule extends AbstractModule implements ModuleChartInterface 41c1010edaSGreg Roach{ 4249a243cbSGreg Roach use ModuleChartTrait; 4349a243cbSGreg Roach 4454452b04SGreg Roach // Chart styles 45677aaceaSGreg Roach public const CHART_STYLE_LIST = 0; 46677aaceaSGreg Roach public const CHART_STYLE_BOOKLET = 1; 47677aaceaSGreg Roach public const CHART_STYLE_INDIVIDUALS = 2; 48677aaceaSGreg Roach public const CHART_STYLE_FAMILIES = 3; 4954452b04SGreg Roach 5054452b04SGreg Roach // Defaults 51677aaceaSGreg Roach public const DEFAULT_STYLE = self::CHART_STYLE_LIST; 52677aaceaSGreg Roach public const DEFAULT_GENERATIONS = '3'; 53677aaceaSGreg Roach public const DEFAULT_MAXIMUM_GENERATIONS = '9'; 5454452b04SGreg Roach 5554452b04SGreg Roach /** @var int[] */ 5654452b04SGreg Roach protected $dabo_num = []; 5754452b04SGreg Roach 5854452b04SGreg Roach /** @var string[] */ 5954452b04SGreg Roach protected $dabo_sex = []; 6054452b04SGreg Roach 61168ff6f3Sric2016 /** 62168ff6f3Sric2016 * How should this module be labelled on tabs, menus, etc.? 63168ff6f3Sric2016 * 64168ff6f3Sric2016 * @return string 65168ff6f3Sric2016 */ 6649a243cbSGreg Roach public function title(): string 67c1010edaSGreg Roach { 68bbb76c12SGreg Roach /* I18N: Name of a module/chart */ 69bbb76c12SGreg Roach return I18N::translate('Descendants'); 70168ff6f3Sric2016 } 71168ff6f3Sric2016 72168ff6f3Sric2016 /** 73168ff6f3Sric2016 * A sentence describing what this module does. 74168ff6f3Sric2016 * 75168ff6f3Sric2016 * @return string 76168ff6f3Sric2016 */ 7749a243cbSGreg Roach public function description(): string 78c1010edaSGreg Roach { 79bbb76c12SGreg Roach /* I18N: Description of the “DescendancyChart” module */ 80bbb76c12SGreg Roach return I18N::translate('A chart of an individual’s descendants.'); 81168ff6f3Sric2016 } 82168ff6f3Sric2016 83168ff6f3Sric2016 /** 84377a2979SGreg Roach * CSS class for the URL. 85377a2979SGreg Roach * 86377a2979SGreg Roach * @return string 87377a2979SGreg Roach */ 88377a2979SGreg Roach public function chartMenuClass(): string 89377a2979SGreg Roach { 90377a2979SGreg Roach return 'menu-chart-descendants'; 91377a2979SGreg Roach } 92377a2979SGreg Roach 93377a2979SGreg Roach /** 944eb71cfaSGreg Roach * Return a menu item for this chart - for use in individual boxes. 954eb71cfaSGreg Roach * 9660bc3e3fSGreg Roach * @param Individual $individual 9760bc3e3fSGreg Roach * 984eb71cfaSGreg Roach * @return Menu|null 994eb71cfaSGreg Roach */ 100377a2979SGreg Roach public function chartBoxMenu(Individual $individual): ?Menu 101c1010edaSGreg Roach { 102e6562982SGreg Roach return $this->chartMenu($individual); 103e6562982SGreg Roach } 104e6562982SGreg Roach 105e6562982SGreg Roach /** 106e6562982SGreg Roach * The title for a specific instance of this chart. 107e6562982SGreg Roach * 108e6562982SGreg Roach * @param Individual $individual 109e6562982SGreg Roach * 110e6562982SGreg Roach * @return string 111e6562982SGreg Roach */ 112e6562982SGreg Roach public function chartTitle(Individual $individual): string 113e6562982SGreg Roach { 114e6562982SGreg Roach /* I18N: %s is an individual’s name */ 115e6562982SGreg Roach return I18N::translate('Descendants of %s', $individual->getFullName()); 116e6562982SGreg Roach } 117e6562982SGreg Roach 118e6562982SGreg Roach /** 11954452b04SGreg Roach * A form to request the chart parameters. 12054452b04SGreg Roach * 12154452b04SGreg Roach * @param Request $request 12254452b04SGreg Roach * @param Tree $tree 123e5a6b4d4SGreg Roach * @param UserInterface $user 12454452b04SGreg Roach * @param ChartService $chart_service 12554452b04SGreg Roach * 12654452b04SGreg Roach * @return Response 12754452b04SGreg Roach */ 128e5a6b4d4SGreg Roach public function getChartAction(Request $request, Tree $tree, UserInterface $user, ChartService $chart_service): Response 12954452b04SGreg Roach { 1309b5537c3SGreg Roach $ajax = (bool) $request->get('ajax'); 13154452b04SGreg Roach $xref = $request->get('xref', ''); 13254452b04SGreg Roach $individual = Individual::getInstance($xref, $tree); 13354452b04SGreg Roach 13454452b04SGreg Roach Auth::checkIndividualAccess($individual); 1359867b2f0SGreg Roach Auth::checkComponentAccess($this, 'chart', $tree, $user); 13654452b04SGreg Roach 13754452b04SGreg Roach $minimum_generations = 2; 13854452b04SGreg Roach $maximum_generations = (int) $tree->getPreference('MAX_DESCENDANCY_GENERATIONS', self::DEFAULT_MAXIMUM_GENERATIONS); 13954452b04SGreg Roach $default_generations = (int) $tree->getPreference('DEFAULT_PEDIGREE_GENERATIONS', self::DEFAULT_GENERATIONS); 14054452b04SGreg Roach 14154452b04SGreg Roach $chart_style = (int) $request->get('chart_style', self::DEFAULT_STYLE); 14254452b04SGreg Roach $generations = (int) $request->get('generations', $default_generations); 14354452b04SGreg Roach 14454452b04SGreg Roach $generations = min($generations, $maximum_generations); 14554452b04SGreg Roach $generations = max($generations, $minimum_generations); 14654452b04SGreg Roach 1479b5537c3SGreg Roach if ($ajax) { 14854452b04SGreg Roach return $this->chart($request, $tree, $chart_service); 14954452b04SGreg Roach } 15054452b04SGreg Roach 15154452b04SGreg Roach $ajax_url = $this->chartUrl($individual, [ 15254452b04SGreg Roach 'chart_style' => $chart_style, 15354452b04SGreg Roach 'generations' => $generations, 1549b5537c3SGreg Roach 'ajax' => true, 15554452b04SGreg Roach ]); 15654452b04SGreg Roach 1579b5537c3SGreg Roach return $this->viewResponse('modules/descendancy_chart/page', [ 15854452b04SGreg Roach 'ajax_url' => $ajax_url, 15954452b04SGreg Roach 'chart_style' => $chart_style, 16054452b04SGreg Roach 'chart_styles' => $this->chartStyles(), 16154452b04SGreg Roach 'default_generations' => $default_generations, 16254452b04SGreg Roach 'generations' => $generations, 16354452b04SGreg Roach 'individual' => $individual, 16454452b04SGreg Roach 'maximum_generations' => $maximum_generations, 16554452b04SGreg Roach 'minimum_generations' => $minimum_generations, 16626684e68SGreg Roach 'module_name' => $this->name(), 16754452b04SGreg Roach 'title' => $this->chartTitle($individual), 16854452b04SGreg Roach ]); 16954452b04SGreg Roach } 17054452b04SGreg Roach 17154452b04SGreg Roach /** 17254452b04SGreg Roach * @param Request $request 17354452b04SGreg Roach * @param Tree $tree 17454452b04SGreg Roach * @param ChartService $chart_service 17554452b04SGreg Roach * 17654452b04SGreg Roach * @return Response 17754452b04SGreg Roach */ 17854452b04SGreg Roach public function chart(Request $request, Tree $tree, ChartService $chart_service): Response 17954452b04SGreg Roach { 18054452b04SGreg Roach $this->layout = 'layouts/ajax'; 18154452b04SGreg Roach 18254452b04SGreg Roach $xref = $request->get('xref', ''); 18354452b04SGreg Roach $individual = Individual::getInstance($xref, $tree); 18454452b04SGreg Roach 18554452b04SGreg Roach Auth::checkIndividualAccess($individual); 18654452b04SGreg Roach 18754452b04SGreg Roach $minimum_generations = 2; 18854452b04SGreg Roach $maximum_generations = (int) $tree->getPreference('MAX_PEDIGREE_GENERATIONS', self::DEFAULT_MAXIMUM_GENERATIONS); 18954452b04SGreg Roach $default_generations = (int) $tree->getPreference('DEFAULT_PEDIGREE_GENERATIONS', self::DEFAULT_GENERATIONS); 19054452b04SGreg Roach 19154452b04SGreg Roach $chart_style = (int) $request->get('chart_style', self::DEFAULT_STYLE); 19254452b04SGreg Roach $generations = (int) $request->get('generations', $default_generations); 19354452b04SGreg Roach 19454452b04SGreg Roach $generations = min($generations, $maximum_generations); 19554452b04SGreg Roach $generations = max($generations, $minimum_generations); 19654452b04SGreg Roach 19754452b04SGreg Roach switch ($chart_style) { 19854452b04SGreg Roach case self::CHART_STYLE_LIST: 19954452b04SGreg Roach default: 20054452b04SGreg Roach return $this->descendantsList($individual, $generations); 20154452b04SGreg Roach 20254452b04SGreg Roach case self::CHART_STYLE_BOOKLET: 20354452b04SGreg Roach return $this->descendantsBooklet($individual, $generations); 20454452b04SGreg Roach 20554452b04SGreg Roach case self::CHART_STYLE_INDIVIDUALS: 20654452b04SGreg Roach $individuals = $chart_service->descendants($individual, $generations - 1); 20754452b04SGreg Roach 20854452b04SGreg Roach return $this->descendantsIndividuals($tree, $individuals); 20954452b04SGreg Roach 21054452b04SGreg Roach case self::CHART_STYLE_FAMILIES: 21154452b04SGreg Roach $families = $chart_service->descendantFamilies($individual, $generations - 1); 21254452b04SGreg Roach 21354452b04SGreg Roach return $this->descendantsFamilies($tree, $families); 21454452b04SGreg Roach } 21554452b04SGreg Roach } 21654452b04SGreg Roach 21754452b04SGreg Roach /** 21854452b04SGreg Roach * Show a hierarchical list of descendants 21954452b04SGreg Roach * 22054452b04SGreg Roach * @TODO replace ob_start() with views. 221e6562982SGreg Roach * 222e6562982SGreg Roach * @param Individual $individual 22354452b04SGreg Roach * @param int $generations 224e6562982SGreg Roach * 22554452b04SGreg Roach * @return Response 226e6562982SGreg Roach */ 22754452b04SGreg Roach private function descendantsList(Individual $individual, int $generations): Response 228e6562982SGreg Roach { 22954452b04SGreg Roach ob_start(); 23054452b04SGreg Roach 23154452b04SGreg Roach echo '<ul class="chart_common">'; 23254452b04SGreg Roach $this->printChildDescendancy($individual, $generations, $generations); 23354452b04SGreg Roach echo '</ul>'; 23454452b04SGreg Roach 23554452b04SGreg Roach $html = ob_get_clean(); 23654452b04SGreg Roach 23754452b04SGreg Roach return new Response($html); 23854452b04SGreg Roach } 23954452b04SGreg Roach 24054452b04SGreg Roach /** 24154452b04SGreg Roach * print a child descendancy 24254452b04SGreg Roach * 24354452b04SGreg Roach * @param Individual $person 24454452b04SGreg Roach * @param int $depth the descendancy depth to show 24554452b04SGreg Roach * @param int $generations 24654452b04SGreg Roach * 24754452b04SGreg Roach * @return void 24854452b04SGreg Roach */ 24954452b04SGreg Roach private function printChildDescendancy(Individual $person, $depth, int $generations) 25054452b04SGreg Roach { 25154452b04SGreg Roach echo '<li>'; 25254452b04SGreg Roach echo '<table><tr><td>'; 25354452b04SGreg Roach if ($depth == $generations) { 254e837ff07SGreg Roach echo '<img alt="" role="presentation" src="' . e(asset('css/images/spacer.png')) . '" height="3" width="15"></td><td>'; 25554452b04SGreg Roach } else { 256e837ff07SGreg Roach echo '<img src="' . e(asset('css/images/spacer.png')) . '" height="3" width="3">'; 257e837ff07SGreg Roach echo '<img src="' . e(asset('css/images/hline.png')) . '" height="3" width="', 12, '"></td><td>'; 25854452b04SGreg Roach } 25954452b04SGreg Roach echo FunctionsPrint::printPedigreePerson($person); 26054452b04SGreg Roach echo '</td>'; 26154452b04SGreg Roach 26254452b04SGreg Roach // check if child has parents and add an arrow 26354452b04SGreg Roach echo '<td></td>'; 26454452b04SGreg Roach echo '<td>'; 26554452b04SGreg Roach foreach ($person->getChildFamilies() as $cfamily) { 26654452b04SGreg Roach foreach ($cfamily->getSpouses() as $parent) { 267*39b853a7SGreg Roach echo '<a href="' . e($this->chartUrl($parent, ['generations' => $generations])) . '" title="' . I18N::translate('Start at parents') . '">' . view('icons/arrow-up') . '<span class="sr-only">' . I18N::translate('Start at parents') . '</span></a>'; 26854452b04SGreg Roach // only show the arrow for one of the parents 26954452b04SGreg Roach break; 27054452b04SGreg Roach } 27154452b04SGreg Roach } 27254452b04SGreg Roach 27354452b04SGreg Roach // d'Aboville child number 27454452b04SGreg Roach $level = $generations - $depth; 27554452b04SGreg Roach echo '<br><br> '; 27654452b04SGreg Roach echo '<span dir="ltr">'; //needed so that RTL languages will display this properly 27754452b04SGreg Roach if (!isset($this->dabo_num[$level])) { 27854452b04SGreg Roach $this->dabo_num[$level] = 0; 27954452b04SGreg Roach } 28054452b04SGreg Roach $this->dabo_num[$level]++; 28154452b04SGreg Roach $this->dabo_num[$level + 1] = 0; 28254452b04SGreg Roach $this->dabo_sex[$level] = $person->getSex(); 28354452b04SGreg Roach for ($i = 0; $i <= $level; $i++) { 28454452b04SGreg Roach $isf = $this->dabo_sex[$i]; 28554452b04SGreg Roach if ($isf === 'M') { 28654452b04SGreg Roach $isf = ''; 28754452b04SGreg Roach } 28854452b04SGreg Roach if ($isf === 'U') { 28954452b04SGreg Roach $isf = 'NN'; 29054452b04SGreg Roach } 29154452b04SGreg Roach echo '<span class="person_box' . $isf . '"> ' . $this->dabo_num[$i] . ' </span>'; 29254452b04SGreg Roach if ($i < $level) { 29354452b04SGreg Roach echo '.'; 29454452b04SGreg Roach } 29554452b04SGreg Roach } 29654452b04SGreg Roach echo '</span>'; 29754452b04SGreg Roach echo '</td></tr>'; 29854452b04SGreg Roach echo '</table>'; 29954452b04SGreg Roach echo '</li>'; 30054452b04SGreg Roach 30154452b04SGreg Roach // loop for each spouse 30254452b04SGreg Roach foreach ($person->getSpouseFamilies() as $family) { 30354452b04SGreg Roach $this->printFamilyDescendancy($person, $family, $depth, $generations); 30454452b04SGreg Roach } 30554452b04SGreg Roach } 30654452b04SGreg Roach 30754452b04SGreg Roach /** 30854452b04SGreg Roach * print a family descendancy 30954452b04SGreg Roach * 31054452b04SGreg Roach * @param Individual $person 31154452b04SGreg Roach * @param Family $family 31254452b04SGreg Roach * @param int $depth the descendancy depth to show 31354452b04SGreg Roach * @param int $generations 31454452b04SGreg Roach * 31554452b04SGreg Roach * @return void 31654452b04SGreg Roach */ 31754452b04SGreg Roach private function printFamilyDescendancy(Individual $person, Family $family, int $depth, int $generations) 31854452b04SGreg Roach { 31954452b04SGreg Roach $uid = Uuid::uuid4()->toString(); // create a unique ID 32054452b04SGreg Roach // print marriage info 32154452b04SGreg Roach echo '<li>'; 322e837ff07SGreg Roach echo '<img src="', e(asset('css/images/spacer.png')), '" height="2" width="', 19, '">'; 32354452b04SGreg Roach echo '<span class="details1">'; 32454452b04SGreg Roach echo '<a href="#" onclick="expand_layer(\'' . $uid . '\'); return false;" class="top"><i id="' . $uid . '_img" class="icon-minus" title="' . I18N::translate('View this family') . '"></i></a>'; 32554452b04SGreg Roach if ($family->canShow()) { 32654452b04SGreg Roach foreach ($family->facts(Gedcom::MARRIAGE_EVENTS) as $fact) { 32754452b04SGreg Roach echo ' <a href="', e($family->url()), '" class="details1">', $fact->summary(), '</a>'; 32854452b04SGreg Roach } 32954452b04SGreg Roach } 33054452b04SGreg Roach echo '</span>'; 33154452b04SGreg Roach 33254452b04SGreg Roach // print spouse 33354452b04SGreg Roach $spouse = $family->getSpouse($person); 33454452b04SGreg Roach echo '<ul class="generations" id="' . $uid . '">'; 33554452b04SGreg Roach echo '<li>'; 33654452b04SGreg Roach echo '<table><tr><td>'; 33754452b04SGreg Roach echo FunctionsPrint::printPedigreePerson($spouse); 33854452b04SGreg Roach echo '</td>'; 33954452b04SGreg Roach 34054452b04SGreg Roach // check if spouse has parents and add an arrow 34154452b04SGreg Roach echo '<td></td>'; 34254452b04SGreg Roach echo '<td>'; 34354452b04SGreg Roach if ($spouse) { 34454452b04SGreg Roach foreach ($spouse->getChildFamilies() as $cfamily) { 34554452b04SGreg Roach foreach ($cfamily->getSpouses() as $parent) { 346*39b853a7SGreg Roach echo '<a href="' . e($this->chartUrl($parent, ['generations' => $generations])) . '" title="' . strip_tags($this->chartTitle($parent)) . '">' . view('icons/arrow-up') . '<span class="sr-only">' . strip_tags($this->chartTitle($parent)) . '</span></a>'; 34754452b04SGreg Roach // only show the arrow for one of the parents 34854452b04SGreg Roach break; 34954452b04SGreg Roach } 35054452b04SGreg Roach } 35154452b04SGreg Roach } 35254452b04SGreg Roach echo '<br><br> '; 35354452b04SGreg Roach echo '</td></tr>'; 35454452b04SGreg Roach 35554452b04SGreg Roach // children 35654452b04SGreg Roach $children = $family->getChildren(); 35754452b04SGreg Roach echo '<tr><td colspan="3" class="details1" > '; 35854452b04SGreg Roach if (!empty($children)) { 35954452b04SGreg Roach echo GedcomTag::getLabel('NCHI') . ': ' . count($children); 36054452b04SGreg Roach } else { 36154452b04SGreg Roach // Distinguish between no children (NCHI 0) and no recorded 36254452b04SGreg Roach // children (no CHIL records) 36354452b04SGreg Roach if (strpos($family->gedcom(), '\n1 NCHI 0') !== false) { 36454452b04SGreg Roach echo GedcomTag::getLabel('NCHI') . ': ' . count($children); 36554452b04SGreg Roach } else { 36654452b04SGreg Roach echo I18N::translate('No children'); 36754452b04SGreg Roach } 36854452b04SGreg Roach } 36954452b04SGreg Roach echo '</td></tr></table>'; 37054452b04SGreg Roach echo '</li>'; 37154452b04SGreg Roach if ($depth > 1) { 37254452b04SGreg Roach foreach ($children as $child) { 37354452b04SGreg Roach $this->printChildDescendancy($child, $depth - 1, $generations); 37454452b04SGreg Roach } 37554452b04SGreg Roach } 37654452b04SGreg Roach echo '</ul>'; 37754452b04SGreg Roach echo '</li>'; 37854452b04SGreg Roach } 37954452b04SGreg Roach 38054452b04SGreg Roach /** 38154452b04SGreg Roach * Show a tabular list of individual descendants. 38254452b04SGreg Roach * 38354452b04SGreg Roach * @param Tree $tree 38454452b04SGreg Roach * @param Collection $individuals 38554452b04SGreg Roach * 38654452b04SGreg Roach * @return Response 38754452b04SGreg Roach */ 38854452b04SGreg Roach private function descendantsIndividuals(Tree $tree, Collection $individuals): Response 38954452b04SGreg Roach { 39054452b04SGreg Roach $this->layout = 'layouts/ajax'; 39154452b04SGreg Roach 39254452b04SGreg Roach return $this->viewResponse('lists/individuals-table', [ 39354452b04SGreg Roach 'individuals' => $individuals, 39454452b04SGreg Roach 'sosa' => false, 39554452b04SGreg Roach 'tree' => $tree, 39654452b04SGreg Roach ]); 39754452b04SGreg Roach } 39854452b04SGreg Roach 39954452b04SGreg Roach /** 40054452b04SGreg Roach * Show a tabular list of individual descendants. 40154452b04SGreg Roach * 40254452b04SGreg Roach * @param Tree $tree 40354452b04SGreg Roach * @param Collection $families 40454452b04SGreg Roach * 40554452b04SGreg Roach * @return Response 40654452b04SGreg Roach */ 40754452b04SGreg Roach private function descendantsFamilies(Tree $tree, Collection $families): Response 40854452b04SGreg Roach { 40954452b04SGreg Roach $this->layout = 'layouts/ajax'; 41054452b04SGreg Roach 41154452b04SGreg Roach return $this->viewResponse('lists/families-table', [ 41254452b04SGreg Roach 'families' => $families, 41354452b04SGreg Roach 'tree' => $tree, 41454452b04SGreg Roach ]); 41554452b04SGreg Roach } 41654452b04SGreg Roach 41754452b04SGreg Roach /** 41854452b04SGreg Roach * Show a booklet view of descendants 41954452b04SGreg Roach * 42054452b04SGreg Roach * @TODO replace ob_start() with views. 42154452b04SGreg Roach * 42254452b04SGreg Roach * @param Individual $individual 42354452b04SGreg Roach * @param int $generations 42454452b04SGreg Roach * 42554452b04SGreg Roach * @return Response 42654452b04SGreg Roach */ 42754452b04SGreg Roach private function descendantsBooklet(Individual $individual, int $generations): Response 42854452b04SGreg Roach { 42954452b04SGreg Roach ob_start(); 43054452b04SGreg Roach 43154452b04SGreg Roach $this->printChildFamily($individual, $generations); 43254452b04SGreg Roach 43354452b04SGreg Roach $html = ob_get_clean(); 43454452b04SGreg Roach 43554452b04SGreg Roach return new Response($html); 43654452b04SGreg Roach } 43754452b04SGreg Roach 43854452b04SGreg Roach /** 43954452b04SGreg Roach * Print a child family 44054452b04SGreg Roach * 44154452b04SGreg Roach * @param Individual $individual 44254452b04SGreg Roach * @param int $depth - the descendancy depth to show 44354452b04SGreg Roach * @param string $daboville - d'Aboville number 44454452b04SGreg Roach * @param string $gpid 44554452b04SGreg Roach * 44654452b04SGreg Roach * @return void 44754452b04SGreg Roach */ 44854452b04SGreg Roach private function printChildFamily(Individual $individual, $depth, $daboville = '1.', $gpid = '') 44954452b04SGreg Roach { 45054452b04SGreg Roach if ($depth < 2) { 45154452b04SGreg Roach return; 45254452b04SGreg Roach } 45354452b04SGreg Roach 45454452b04SGreg Roach $i = 1; 45554452b04SGreg Roach 45654452b04SGreg Roach foreach ($individual->getSpouseFamilies() as $family) { 45754452b04SGreg Roach FunctionsCharts::printSosaFamily($family, '', -1, $daboville, $individual->xref(), $gpid, false); 45854452b04SGreg Roach foreach ($family->getChildren() as $child) { 45954452b04SGreg Roach $this->printChildFamily($child, $depth - 1, $daboville . ($i++) . '.', $individual->xref()); 46054452b04SGreg Roach } 46154452b04SGreg Roach } 46254452b04SGreg Roach } 46354452b04SGreg Roach 46454452b04SGreg Roach /** 46554452b04SGreg Roach * This chart can display its output in a number of styles 46654452b04SGreg Roach * 46754452b04SGreg Roach * @return array 46854452b04SGreg Roach */ 46954452b04SGreg Roach private function chartStyles(): array 47054452b04SGreg Roach { 47154452b04SGreg Roach return [ 47254452b04SGreg Roach self::CHART_STYLE_LIST => I18N::translate('List'), 47354452b04SGreg Roach self::CHART_STYLE_BOOKLET => I18N::translate('Booklet'), 47454452b04SGreg Roach self::CHART_STYLE_INDIVIDUALS => I18N::translate('Individuals'), 47554452b04SGreg Roach self::CHART_STYLE_FAMILIES => I18N::translate('Families'), 47654452b04SGreg Roach ]; 477e6562982SGreg Roach } 478168ff6f3Sric2016} 479