1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Module; 19 20use Fisharebest\Webtrees\Individual; 21use Fisharebest\Webtrees\Menu; 22 23/** 24 * Trait ModuleChartTrait - default implementation of ModuleChartInterface 25 */ 26trait ModuleChartTrait 27{ 28 /** 29 * @return string 30 */ 31 abstract public function name(): string; 32 33 /** 34 * A menu item for this chart for an individual box in a chart. 35 * 36 * @param Individual $individual 37 * 38 * @return Menu|null 39 */ 40 public function chartBoxMenu(Individual $individual): ?Menu 41 { 42 return null; 43 } 44 45 /** 46 * A main menu item for this chart. 47 * 48 * @param Individual $individual 49 * 50 * @return Menu 51 */ 52 public function chartMenu(Individual $individual): Menu 53 { 54 return new Menu( 55 $this->title(), 56 $this->chartUrl($individual), 57 $this->chartMenuClass(), 58 $this->chartUrlAttributes() 59 ); 60 } 61 62 /** 63 * CSS class for the menu. 64 * 65 * @return string 66 */ 67 public function chartMenuClass(): string 68 { 69 return ''; 70 } 71 72 /** 73 * The title for a specific instance of this chart. 74 * 75 * @param Individual $individual 76 * 77 * @return string 78 */ 79 public function chartTitle(Individual $individual): string 80 { 81 return $this->title(); 82 } 83 84 /** 85 * The URL for a page showing chart options. 86 * 87 * @param Individual $individual 88 * @param string[] $parameters 89 * 90 * @return string 91 */ 92 public function chartUrl(Individual $individual, array $parameters = []): string 93 { 94 return route('module', [ 95 'module' => $this->name(), 96 'action' => 'Chart', 97 'xref' => $individual->xref(), 98 'ged' => $individual->tree()->name(), 99 ] + $parameters); 100 } 101 102 /** 103 * Attributes for the URL. 104 * 105 * @return string[] 106 */ 107 public function chartUrlAttributes(): array 108 { 109 return ['rel' => 'nofollow']; 110 } 111} 112