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