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'; 53e759aebbSGreg Roach 54e759aebbSGreg Roach // Limits 55e759aebbSGreg Roach public const MINIMUM_GENERATIONS = 2; 56e759aebbSGreg Roach public const MAXIMUM_GENERATIONS = 10; 5754452b04SGreg Roach 5854452b04SGreg Roach /** @var int[] */ 5954452b04SGreg Roach protected $dabo_num = []; 6054452b04SGreg Roach 6154452b04SGreg Roach /** @var string[] */ 6254452b04SGreg Roach protected $dabo_sex = []; 6354452b04SGreg Roach 64168ff6f3Sric2016 /** 650cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 66168ff6f3Sric2016 * 67168ff6f3Sric2016 * @return string 68168ff6f3Sric2016 */ 6949a243cbSGreg Roach public function title(): string 70c1010edaSGreg Roach { 71bbb76c12SGreg Roach /* I18N: Name of a module/chart */ 72bbb76c12SGreg Roach return I18N::translate('Descendants'); 73168ff6f3Sric2016 } 74168ff6f3Sric2016 75168ff6f3Sric2016 /** 76168ff6f3Sric2016 * A sentence describing what this module does. 77168ff6f3Sric2016 * 78168ff6f3Sric2016 * @return string 79168ff6f3Sric2016 */ 8049a243cbSGreg Roach public function description(): string 81c1010edaSGreg Roach { 82bbb76c12SGreg Roach /* I18N: Description of the “DescendancyChart” module */ 83bbb76c12SGreg Roach return I18N::translate('A chart of an individual’s descendants.'); 84168ff6f3Sric2016 } 85168ff6f3Sric2016 86168ff6f3Sric2016 /** 87377a2979SGreg Roach * CSS class for the URL. 88377a2979SGreg Roach * 89377a2979SGreg Roach * @return string 90377a2979SGreg Roach */ 91377a2979SGreg Roach public function chartMenuClass(): string 92377a2979SGreg Roach { 93377a2979SGreg Roach return 'menu-chart-descendants'; 94377a2979SGreg Roach } 95377a2979SGreg Roach 96377a2979SGreg Roach /** 974eb71cfaSGreg Roach * Return a menu item for this chart - for use in individual boxes. 984eb71cfaSGreg Roach * 9960bc3e3fSGreg Roach * @param Individual $individual 10060bc3e3fSGreg Roach * 1014eb71cfaSGreg Roach * @return Menu|null 1024eb71cfaSGreg Roach */ 103377a2979SGreg Roach public function chartBoxMenu(Individual $individual): ?Menu 104c1010edaSGreg Roach { 105e6562982SGreg Roach return $this->chartMenu($individual); 106e6562982SGreg Roach } 107e6562982SGreg Roach 108e6562982SGreg Roach /** 109e6562982SGreg Roach * The title for a specific instance of this chart. 110e6562982SGreg Roach * 111e6562982SGreg Roach * @param Individual $individual 112e6562982SGreg Roach * 113e6562982SGreg Roach * @return string 114e6562982SGreg Roach */ 115e6562982SGreg Roach public function chartTitle(Individual $individual): string 116e6562982SGreg Roach { 117e6562982SGreg Roach /* I18N: %s is an individual’s name */ 11839ca88baSGreg Roach return I18N::translate('Descendants of %s', $individual->fullName()); 119e6562982SGreg Roach } 120e6562982SGreg Roach 121e6562982SGreg Roach /** 12254452b04SGreg Roach * A form to request the chart parameters. 12354452b04SGreg Roach * 12454452b04SGreg Roach * @param Request $request 12554452b04SGreg Roach * @param Tree $tree 126e5a6b4d4SGreg Roach * @param UserInterface $user 12754452b04SGreg Roach * @param ChartService $chart_service 12854452b04SGreg Roach * 12954452b04SGreg Roach * @return Response 13054452b04SGreg Roach */ 131e5a6b4d4SGreg Roach public function getChartAction(Request $request, Tree $tree, UserInterface $user, ChartService $chart_service): Response 13254452b04SGreg Roach { 1339b5537c3SGreg Roach $ajax = (bool) $request->get('ajax'); 13454452b04SGreg Roach $xref = $request->get('xref', ''); 13554452b04SGreg Roach $individual = Individual::getInstance($xref, $tree); 13654452b04SGreg Roach 13754452b04SGreg Roach Auth::checkIndividualAccess($individual); 1389867b2f0SGreg Roach Auth::checkComponentAccess($this, 'chart', $tree, $user); 13954452b04SGreg Roach 14054452b04SGreg Roach $chart_style = (int) $request->get('chart_style', self::DEFAULT_STYLE); 141e759aebbSGreg Roach $generations = (int) $request->get('generations', self::DEFAULT_GENERATIONS); 14254452b04SGreg Roach 143e759aebbSGreg Roach $generations = min($generations, self::MAXIMUM_GENERATIONS); 144e759aebbSGreg Roach $generations = max($generations, self::MINIMUM_GENERATIONS); 14554452b04SGreg Roach 1469b5537c3SGreg Roach if ($ajax) { 14754452b04SGreg Roach return $this->chart($request, $tree, $chart_service); 14854452b04SGreg Roach } 14954452b04SGreg Roach 15054452b04SGreg Roach $ajax_url = $this->chartUrl($individual, [ 15154452b04SGreg Roach 'chart_style' => $chart_style, 15254452b04SGreg Roach 'generations' => $generations, 1539b5537c3SGreg Roach 'ajax' => true, 15454452b04SGreg Roach ]); 15554452b04SGreg Roach 1569b5537c3SGreg Roach return $this->viewResponse('modules/descendancy_chart/page', [ 15754452b04SGreg Roach 'ajax_url' => $ajax_url, 15854452b04SGreg Roach 'chart_style' => $chart_style, 15954452b04SGreg Roach 'chart_styles' => $this->chartStyles(), 160e759aebbSGreg Roach 'default_generations' => self::DEFAULT_GENERATIONS, 16154452b04SGreg Roach 'generations' => $generations, 16254452b04SGreg Roach 'individual' => $individual, 163e759aebbSGreg Roach 'maximum_generations' => self::MAXIMUM_GENERATIONS, 164e759aebbSGreg Roach 'minimum_generations' => self::MINIMUM_GENERATIONS, 16526684e68SGreg Roach 'module_name' => $this->name(), 16654452b04SGreg Roach 'title' => $this->chartTitle($individual), 16754452b04SGreg Roach ]); 16854452b04SGreg Roach } 16954452b04SGreg Roach 17054452b04SGreg Roach /** 17154452b04SGreg Roach * @param Request $request 17254452b04SGreg Roach * @param Tree $tree 17354452b04SGreg Roach * @param ChartService $chart_service 17454452b04SGreg Roach * 17554452b04SGreg Roach * @return Response 17654452b04SGreg Roach */ 17754452b04SGreg Roach public function chart(Request $request, Tree $tree, ChartService $chart_service): Response 17854452b04SGreg Roach { 17954452b04SGreg Roach $this->layout = 'layouts/ajax'; 18054452b04SGreg Roach 18154452b04SGreg Roach $xref = $request->get('xref', ''); 18254452b04SGreg Roach $individual = Individual::getInstance($xref, $tree); 18354452b04SGreg Roach 18454452b04SGreg Roach Auth::checkIndividualAccess($individual); 18554452b04SGreg Roach 18654452b04SGreg Roach $chart_style = (int) $request->get('chart_style', self::DEFAULT_STYLE); 187e759aebbSGreg Roach $generations = (int) $request->get('generations', self::DEFAULT_GENERATIONS); 18854452b04SGreg Roach 189e759aebbSGreg Roach $generations = min($generations, self::MAXIMUM_GENERATIONS); 190e759aebbSGreg Roach $generations = max($generations, self::MINIMUM_GENERATIONS); 19154452b04SGreg Roach 19254452b04SGreg Roach switch ($chart_style) { 19354452b04SGreg Roach case self::CHART_STYLE_LIST: 19454452b04SGreg Roach default: 19554452b04SGreg Roach return $this->descendantsList($individual, $generations); 19654452b04SGreg Roach 19754452b04SGreg Roach case self::CHART_STYLE_BOOKLET: 19854452b04SGreg Roach return $this->descendantsBooklet($individual, $generations); 19954452b04SGreg Roach 20054452b04SGreg Roach case self::CHART_STYLE_INDIVIDUALS: 20154452b04SGreg Roach $individuals = $chart_service->descendants($individual, $generations - 1); 20254452b04SGreg Roach 20354452b04SGreg Roach return $this->descendantsIndividuals($tree, $individuals); 20454452b04SGreg Roach 20554452b04SGreg Roach case self::CHART_STYLE_FAMILIES: 20654452b04SGreg Roach $families = $chart_service->descendantFamilies($individual, $generations - 1); 20754452b04SGreg Roach 20854452b04SGreg Roach return $this->descendantsFamilies($tree, $families); 20954452b04SGreg Roach } 21054452b04SGreg Roach } 21154452b04SGreg Roach 21254452b04SGreg Roach /** 21354452b04SGreg Roach * Show a hierarchical list of descendants 21454452b04SGreg Roach * 21554452b04SGreg Roach * @TODO replace ob_start() with views. 216e6562982SGreg Roach * 217e6562982SGreg Roach * @param Individual $individual 21854452b04SGreg Roach * @param int $generations 219e6562982SGreg Roach * 22054452b04SGreg Roach * @return Response 221e6562982SGreg Roach */ 22254452b04SGreg Roach private function descendantsList(Individual $individual, int $generations): Response 223e6562982SGreg Roach { 22454452b04SGreg Roach ob_start(); 22554452b04SGreg Roach 226242a7862SGreg Roach echo '<ul class="wt-chart-descendants-list list-unstyled">'; 22754452b04SGreg Roach $this->printChildDescendancy($individual, $generations, $generations); 22854452b04SGreg Roach echo '</ul>'; 22954452b04SGreg Roach 23054452b04SGreg Roach $html = ob_get_clean(); 23154452b04SGreg Roach 23254452b04SGreg Roach return new Response($html); 23354452b04SGreg Roach } 23454452b04SGreg Roach 23554452b04SGreg Roach /** 23654452b04SGreg Roach * print a child descendancy 23754452b04SGreg Roach * 23854452b04SGreg Roach * @param Individual $person 23954452b04SGreg Roach * @param int $depth the descendancy depth to show 24054452b04SGreg Roach * @param int $generations 24154452b04SGreg Roach * 24254452b04SGreg Roach * @return void 24354452b04SGreg Roach */ 244*e364afe4SGreg Roach private function printChildDescendancy(Individual $person, $depth, int $generations): void 24554452b04SGreg Roach { 24654452b04SGreg Roach echo '<li>'; 24754452b04SGreg Roach echo '<table><tr><td>'; 24854452b04SGreg Roach if ($depth == $generations) { 249e837ff07SGreg Roach echo '<img alt="" role="presentation" src="' . e(asset('css/images/spacer.png')) . '" height="3" width="15"></td><td>'; 25054452b04SGreg Roach } else { 251e837ff07SGreg Roach echo '<img src="' . e(asset('css/images/spacer.png')) . '" height="3" width="3">'; 252e837ff07SGreg Roach echo '<img src="' . e(asset('css/images/hline.png')) . '" height="3" width="', 12, '"></td><td>'; 25354452b04SGreg Roach } 25454452b04SGreg Roach echo FunctionsPrint::printPedigreePerson($person); 25554452b04SGreg Roach echo '</td>'; 25654452b04SGreg Roach 25754452b04SGreg Roach // check if child has parents and add an arrow 25854452b04SGreg Roach echo '<td></td>'; 25954452b04SGreg Roach echo '<td>'; 26039ca88baSGreg Roach foreach ($person->childFamilies() as $cfamily) { 26139ca88baSGreg Roach foreach ($cfamily->spouses() as $parent) { 26239b853a7SGreg 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>'; 26354452b04SGreg Roach // only show the arrow for one of the parents 26454452b04SGreg Roach break; 26554452b04SGreg Roach } 26654452b04SGreg Roach } 26754452b04SGreg Roach 26854452b04SGreg Roach // d'Aboville child number 26954452b04SGreg Roach $level = $generations - $depth; 27054452b04SGreg Roach echo '<br><br> '; 27154452b04SGreg Roach echo '<span dir="ltr">'; //needed so that RTL languages will display this properly 27254452b04SGreg Roach if (!isset($this->dabo_num[$level])) { 27354452b04SGreg Roach $this->dabo_num[$level] = 0; 27454452b04SGreg Roach } 27554452b04SGreg Roach $this->dabo_num[$level]++; 27654452b04SGreg Roach $this->dabo_num[$level + 1] = 0; 27739ca88baSGreg Roach $this->dabo_sex[$level] = $person->sex(); 27854452b04SGreg Roach for ($i = 0; $i <= $level; $i++) { 27954452b04SGreg Roach $isf = $this->dabo_sex[$i]; 28054452b04SGreg Roach if ($isf === 'M') { 28154452b04SGreg Roach $isf = ''; 28254452b04SGreg Roach } 28354452b04SGreg Roach if ($isf === 'U') { 28454452b04SGreg Roach $isf = 'NN'; 28554452b04SGreg Roach } 28654452b04SGreg Roach echo '<span class="person_box' . $isf . '"> ' . $this->dabo_num[$i] . ' </span>'; 28754452b04SGreg Roach if ($i < $level) { 28854452b04SGreg Roach echo '.'; 28954452b04SGreg Roach } 29054452b04SGreg Roach } 29154452b04SGreg Roach echo '</span>'; 29254452b04SGreg Roach echo '</td></tr>'; 29354452b04SGreg Roach echo '</table>'; 29454452b04SGreg Roach echo '</li>'; 29554452b04SGreg Roach 29654452b04SGreg Roach // loop for each spouse 29739ca88baSGreg Roach foreach ($person->spouseFamilies() as $family) { 29854452b04SGreg Roach $this->printFamilyDescendancy($person, $family, $depth, $generations); 29954452b04SGreg Roach } 30054452b04SGreg Roach } 30154452b04SGreg Roach 30254452b04SGreg Roach /** 30354452b04SGreg Roach * print a family descendancy 30454452b04SGreg Roach * 30554452b04SGreg Roach * @param Individual $person 30654452b04SGreg Roach * @param Family $family 30754452b04SGreg Roach * @param int $depth the descendancy depth to show 30854452b04SGreg Roach * @param int $generations 30954452b04SGreg Roach * 31054452b04SGreg Roach * @return void 31154452b04SGreg Roach */ 312*e364afe4SGreg Roach private function printFamilyDescendancy(Individual $person, Family $family, int $depth, int $generations): void 31354452b04SGreg Roach { 31454452b04SGreg Roach $uid = Uuid::uuid4()->toString(); // create a unique ID 31554452b04SGreg Roach // print marriage info 31654452b04SGreg Roach echo '<li>'; 317e837ff07SGreg Roach echo '<img src="', e(asset('css/images/spacer.png')), '" height="2" width="', 19, '">'; 31854452b04SGreg Roach echo '<span class="details1">'; 31954452b04SGreg 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>'; 32054452b04SGreg Roach if ($family->canShow()) { 32154452b04SGreg Roach foreach ($family->facts(Gedcom::MARRIAGE_EVENTS) as $fact) { 32254452b04SGreg Roach echo ' <a href="', e($family->url()), '" class="details1">', $fact->summary(), '</a>'; 32354452b04SGreg Roach } 32454452b04SGreg Roach } 32554452b04SGreg Roach echo '</span>'; 32654452b04SGreg Roach 32754452b04SGreg Roach // print spouse 32839ca88baSGreg Roach $spouse = $family->spouse($person); 329e5041343SGreg Roach echo '<ul class="generations list-unstyled" id="' . $uid . '">'; 33054452b04SGreg Roach echo '<li>'; 33154452b04SGreg Roach echo '<table><tr><td>'; 33254452b04SGreg Roach echo FunctionsPrint::printPedigreePerson($spouse); 33354452b04SGreg Roach echo '</td>'; 33454452b04SGreg Roach 33554452b04SGreg Roach // check if spouse has parents and add an arrow 33654452b04SGreg Roach echo '<td></td>'; 33754452b04SGreg Roach echo '<td>'; 33854452b04SGreg Roach if ($spouse) { 33939ca88baSGreg Roach foreach ($spouse->childFamilies() as $cfamily) { 34039ca88baSGreg Roach foreach ($cfamily->spouses() as $parent) { 34139b853a7SGreg 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>'; 34254452b04SGreg Roach // only show the arrow for one of the parents 34354452b04SGreg Roach break; 34454452b04SGreg Roach } 34554452b04SGreg Roach } 34654452b04SGreg Roach } 34754452b04SGreg Roach echo '<br><br> '; 34854452b04SGreg Roach echo '</td></tr>'; 34954452b04SGreg Roach 35054452b04SGreg Roach // children 35139ca88baSGreg Roach $children = $family->children(); 35254452b04SGreg Roach echo '<tr><td colspan="3" class="details1" > '; 353820b62dfSGreg Roach if ($children->isNotEmpty()) { 354820b62dfSGreg Roach echo GedcomTag::getLabel('NCHI') . ': ' . $children->count(); 35554452b04SGreg Roach } else { 35654452b04SGreg Roach // Distinguish between no children (NCHI 0) and no recorded 35754452b04SGreg Roach // children (no CHIL records) 35854452b04SGreg Roach if (strpos($family->gedcom(), '\n1 NCHI 0') !== false) { 359820b62dfSGreg Roach echo GedcomTag::getLabel('NCHI') . ': ' . $children->count(); 36054452b04SGreg Roach } else { 36154452b04SGreg Roach echo I18N::translate('No children'); 36254452b04SGreg Roach } 36354452b04SGreg Roach } 36454452b04SGreg Roach echo '</td></tr></table>'; 36554452b04SGreg Roach echo '</li>'; 36654452b04SGreg Roach if ($depth > 1) { 36754452b04SGreg Roach foreach ($children as $child) { 36854452b04SGreg Roach $this->printChildDescendancy($child, $depth - 1, $generations); 36954452b04SGreg Roach } 37054452b04SGreg Roach } 37154452b04SGreg Roach echo '</ul>'; 37254452b04SGreg Roach echo '</li>'; 37354452b04SGreg Roach } 37454452b04SGreg Roach 37554452b04SGreg Roach /** 37654452b04SGreg Roach * Show a tabular list of individual descendants. 37754452b04SGreg Roach * 37854452b04SGreg Roach * @param Tree $tree 37954452b04SGreg Roach * @param Collection $individuals 38054452b04SGreg Roach * 38154452b04SGreg Roach * @return Response 38254452b04SGreg Roach */ 38354452b04SGreg Roach private function descendantsIndividuals(Tree $tree, Collection $individuals): Response 38454452b04SGreg Roach { 38554452b04SGreg Roach $this->layout = 'layouts/ajax'; 38654452b04SGreg Roach 38754452b04SGreg Roach return $this->viewResponse('lists/individuals-table', [ 38854452b04SGreg Roach 'individuals' => $individuals, 38954452b04SGreg Roach 'sosa' => false, 39054452b04SGreg Roach 'tree' => $tree, 39154452b04SGreg Roach ]); 39254452b04SGreg Roach } 39354452b04SGreg Roach 39454452b04SGreg Roach /** 39554452b04SGreg Roach * Show a tabular list of individual descendants. 39654452b04SGreg Roach * 39754452b04SGreg Roach * @param Tree $tree 39854452b04SGreg Roach * @param Collection $families 39954452b04SGreg Roach * 40054452b04SGreg Roach * @return Response 40154452b04SGreg Roach */ 40254452b04SGreg Roach private function descendantsFamilies(Tree $tree, Collection $families): Response 40354452b04SGreg Roach { 40454452b04SGreg Roach $this->layout = 'layouts/ajax'; 40554452b04SGreg Roach 40654452b04SGreg Roach return $this->viewResponse('lists/families-table', [ 40754452b04SGreg Roach 'families' => $families, 40854452b04SGreg Roach 'tree' => $tree, 40954452b04SGreg Roach ]); 41054452b04SGreg Roach } 41154452b04SGreg Roach 41254452b04SGreg Roach /** 41354452b04SGreg Roach * Show a booklet view of descendants 41454452b04SGreg Roach * 41554452b04SGreg Roach * @TODO replace ob_start() with views. 41654452b04SGreg Roach * 41754452b04SGreg Roach * @param Individual $individual 41854452b04SGreg Roach * @param int $generations 41954452b04SGreg Roach * 42054452b04SGreg Roach * @return Response 42154452b04SGreg Roach */ 42254452b04SGreg Roach private function descendantsBooklet(Individual $individual, int $generations): Response 42354452b04SGreg Roach { 42454452b04SGreg Roach ob_start(); 42554452b04SGreg Roach 42654452b04SGreg Roach $this->printChildFamily($individual, $generations); 42754452b04SGreg Roach 42854452b04SGreg Roach $html = ob_get_clean(); 42954452b04SGreg Roach 43054452b04SGreg Roach return new Response($html); 43154452b04SGreg Roach } 43254452b04SGreg Roach 43354452b04SGreg Roach /** 43454452b04SGreg Roach * Print a child family 43554452b04SGreg Roach * 43654452b04SGreg Roach * @param Individual $individual 43754452b04SGreg Roach * @param int $depth - the descendancy depth to show 43854452b04SGreg Roach * @param string $daboville - d'Aboville number 43954452b04SGreg Roach * @param string $gpid 44054452b04SGreg Roach * 44154452b04SGreg Roach * @return void 44254452b04SGreg Roach */ 443*e364afe4SGreg Roach private function printChildFamily(Individual $individual, $depth, $daboville = '1.', $gpid = ''): void 44454452b04SGreg Roach { 44554452b04SGreg Roach if ($depth < 2) { 44654452b04SGreg Roach return; 44754452b04SGreg Roach } 44854452b04SGreg Roach 44954452b04SGreg Roach $i = 1; 45054452b04SGreg Roach 45139ca88baSGreg Roach foreach ($individual->spouseFamilies() as $family) { 45254452b04SGreg Roach FunctionsCharts::printSosaFamily($family, '', -1, $daboville, $individual->xref(), $gpid, false); 45339ca88baSGreg Roach foreach ($family->children() as $child) { 45454452b04SGreg Roach $this->printChildFamily($child, $depth - 1, $daboville . ($i++) . '.', $individual->xref()); 45554452b04SGreg Roach } 45654452b04SGreg Roach } 45754452b04SGreg Roach } 45854452b04SGreg Roach 45954452b04SGreg Roach /** 46054452b04SGreg Roach * This chart can display its output in a number of styles 46154452b04SGreg Roach * 4624db4b4a9SGreg Roach * @return string[] 46354452b04SGreg Roach */ 46454452b04SGreg Roach private function chartStyles(): array 46554452b04SGreg Roach { 46654452b04SGreg Roach return [ 46754452b04SGreg Roach self::CHART_STYLE_LIST => I18N::translate('List'), 46854452b04SGreg Roach self::CHART_STYLE_BOOKLET => I18N::translate('Booklet'), 46954452b04SGreg Roach self::CHART_STYLE_INDIVIDUALS => I18N::translate('Individuals'), 47054452b04SGreg Roach self::CHART_STYLE_FAMILIES => I18N::translate('Families'), 47154452b04SGreg Roach ]; 472e6562982SGreg Roach } 473168ff6f3Sric2016} 474