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 20d84d3988SGreg Roachuse Fisharebest\Webtrees\Auth; 21168ff6f3Sric2016use Fisharebest\Webtrees\I18N; 22168ff6f3Sric2016use Fisharebest\Webtrees\Individual; 23e46b0479SScrutinizer Auto-Fixeruse Fisharebest\Webtrees\Menu; 24d84d3988SGreg Roachuse Fisharebest\Webtrees\Services\ChartService; 25d84d3988SGreg Roachuse Fisharebest\Webtrees\Tree; 26d84d3988SGreg Roachuse Symfony\Component\HttpFoundation\Request; 27d84d3988SGreg Roachuse Symfony\Component\HttpFoundation\Response; 28168ff6f3Sric2016 29168ff6f3Sric2016/** 30168ff6f3Sric2016 * Class CompactTreeChartModule 31168ff6f3Sric2016 */ 32*37eb8894SGreg Roachclass CompactTreeChartModule extends AbstractModule implements ModuleChartInterface 33c1010edaSGreg Roach{ 3449a243cbSGreg Roach use ModuleChartTrait; 3549a243cbSGreg Roach 36168ff6f3Sric2016 /** 37168ff6f3Sric2016 * How should this module be labelled on tabs, menus, etc.? 38168ff6f3Sric2016 * 39168ff6f3Sric2016 * @return string 40168ff6f3Sric2016 */ 4149a243cbSGreg Roach public function title(): string 42c1010edaSGreg Roach { 43bbb76c12SGreg Roach /* I18N: Name of a module/chart */ 44bbb76c12SGreg Roach return I18N::translate('Compact tree'); 45168ff6f3Sric2016 } 46168ff6f3Sric2016 47168ff6f3Sric2016 /** 48168ff6f3Sric2016 * A sentence describing what this module does. 49168ff6f3Sric2016 * 50168ff6f3Sric2016 * @return string 51168ff6f3Sric2016 */ 5249a243cbSGreg Roach public function description(): string 53c1010edaSGreg Roach { 54bbb76c12SGreg Roach /* I18N: Description of the “CompactTreeChart” module */ 55bbb76c12SGreg Roach return I18N::translate('A chart of an individual’s ancestors, as a compact tree.'); 56168ff6f3Sric2016 } 57168ff6f3Sric2016 58168ff6f3Sric2016 /** 59377a2979SGreg Roach * CSS class for the URL. 60377a2979SGreg Roach * 61377a2979SGreg Roach * @return string 62377a2979SGreg Roach */ 63377a2979SGreg Roach public function chartMenuClass(): string 64377a2979SGreg Roach { 65377a2979SGreg Roach return 'menu-chart-compact'; 66377a2979SGreg Roach } 67377a2979SGreg Roach 68377a2979SGreg Roach /** 694eb71cfaSGreg Roach * Return a menu item for this chart - for use in individual boxes. 704eb71cfaSGreg Roach * 7160bc3e3fSGreg Roach * @param Individual $individual 7260bc3e3fSGreg Roach * 734eb71cfaSGreg Roach * @return Menu|null 744eb71cfaSGreg Roach */ 75377a2979SGreg Roach public function chartBoxMenu(Individual $individual): ?Menu 76c1010edaSGreg Roach { 77e6562982SGreg Roach return $this->chartMenu($individual); 78e6562982SGreg Roach } 79e6562982SGreg Roach 80e6562982SGreg Roach /** 81e6562982SGreg Roach * The title for a specific instance of this chart. 82e6562982SGreg Roach * 83e6562982SGreg Roach * @param Individual $individual 84e6562982SGreg Roach * 85e6562982SGreg Roach * @return string 86e6562982SGreg Roach */ 87e6562982SGreg Roach public function chartTitle(Individual $individual): string 88e6562982SGreg Roach { 89e6562982SGreg Roach /* I18N: %s is an individual’s name */ 90e6562982SGreg Roach return I18N::translate('Compact tree of %s', $individual->getFullName()); 91e6562982SGreg Roach } 92d84d3988SGreg Roach 93d84d3988SGreg Roach /** 94d84d3988SGreg Roach * A form to request the chart parameters. 95d84d3988SGreg Roach * 96d84d3988SGreg Roach * @param Request $request 97d84d3988SGreg Roach * @param Tree $tree 98d84d3988SGreg Roach * @param ChartService $chart_service 99d84d3988SGreg Roach * 100d84d3988SGreg Roach * @return Response 101d84d3988SGreg Roach */ 102d84d3988SGreg Roach public function getChartAction(Request $request, Tree $tree, ChartService $chart_service): Response 103d84d3988SGreg Roach { 1049b5537c3SGreg Roach $ajax = (bool) $request->get('ajax'); 105d84d3988SGreg Roach $xref = $request->get('xref', ''); 106d84d3988SGreg Roach $individual = Individual::getInstance($xref, $tree); 107d84d3988SGreg Roach 108d84d3988SGreg Roach Auth::checkIndividualAccess($individual); 109d84d3988SGreg Roach 1109b5537c3SGreg Roach if ($ajax) { 111d84d3988SGreg Roach return $this->chartCompact($individual, $chart_service); 112d84d3988SGreg Roach } 113d84d3988SGreg Roach 114389266c0SGreg Roach $ajax_url = $this->chartUrl($individual, [ 1159b5537c3SGreg Roach 'ajax' => true, 116389266c0SGreg Roach ]); 117389266c0SGreg Roach 1189b5537c3SGreg Roach return $this->viewResponse('modules/compact-chart/page', [ 119389266c0SGreg Roach 'ajax_url' => $ajax_url, 120d84d3988SGreg Roach 'individual' => $individual, 12126684e68SGreg Roach 'module_name' => $this->name(), 122389266c0SGreg Roach 'title' => $this->chartTitle($individual), 123d84d3988SGreg Roach ]); 124d84d3988SGreg Roach } 125d84d3988SGreg Roach 126d84d3988SGreg Roach /** 127d84d3988SGreg Roach * @param Individual $individual 128d84d3988SGreg Roach * @param ChartService $chart_service 129d84d3988SGreg Roach * 130d84d3988SGreg Roach * @return Response 131d84d3988SGreg Roach */ 132d84d3988SGreg Roach protected function chartCompact(Individual $individual, ChartService $chart_service): Response 133d84d3988SGreg Roach { 134d84d3988SGreg Roach $ancestors = $chart_service->sosaStradonitzAncestors($individual, 5); 135d84d3988SGreg Roach 136d84d3988SGreg Roach $html = view('modules/compact-chart/chart', [ 137d84d3988SGreg Roach 'ancestors' => $ancestors, 138d84d3988SGreg Roach ]); 139d84d3988SGreg Roach 140d84d3988SGreg Roach return new Response($html); 141d84d3988SGreg Roach } 142168ff6f3Sric2016} 143