1*46295629SGreg Roach<?php 2*46295629SGreg Roach/** 3*46295629SGreg Roach * webtrees: online genealogy 4*46295629SGreg Roach * Copyright (C) 2019 webtrees development team 5*46295629SGreg Roach * This program is free software: you can redistribute it and/or modify 6*46295629SGreg Roach * it under the terms of the GNU General Public License as published by 7*46295629SGreg Roach * the Free Software Foundation, either version 3 of the License, or 8*46295629SGreg Roach * (at your option) any later version. 9*46295629SGreg Roach * This program is distributed in the hope that it will be useful, 10*46295629SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*46295629SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*46295629SGreg Roach * GNU General Public License for more details. 13*46295629SGreg Roach * You should have received a copy of the GNU General Public License 14*46295629SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 15*46295629SGreg Roach */ 16*46295629SGreg Roachdeclare(strict_types=1); 17*46295629SGreg Roach 18*46295629SGreg Roachnamespace Fisharebest\Webtrees\Module; 19*46295629SGreg Roach 20*46295629SGreg Roachuse Fisharebest\Webtrees\I18N; 21*46295629SGreg Roachuse Fisharebest\Webtrees\Menu; 22*46295629SGreg Roachuse Fisharebest\Webtrees\Site; 23*46295629SGreg Roachuse Fisharebest\Webtrees\Tree; 24*46295629SGreg Roach 25*46295629SGreg Roach/** 26*46295629SGreg Roach * Class TreesMenuModule - provide a menu option for the trees options 27*46295629SGreg Roach */ 28*46295629SGreg Roachclass TreesMenuModule extends AbstractModule implements ModuleInterface, ModuleMenuInterface 29*46295629SGreg Roach{ 30*46295629SGreg Roach use ModuleMenuTrait; 31*46295629SGreg Roach 32*46295629SGreg Roach /** {@inheritdoc} */ 33*46295629SGreg Roach public function title(): string 34*46295629SGreg Roach { 35*46295629SGreg Roach /* I18N: Name of a module */ 36*46295629SGreg Roach return I18N::translate('Family trees'); 37*46295629SGreg Roach } 38*46295629SGreg Roach 39*46295629SGreg Roach /** {@inheritdoc} */ 40*46295629SGreg Roach public function description(): string 41*46295629SGreg Roach { 42*46295629SGreg Roach /* I18N: Description of the “Reports” module */ 43*46295629SGreg Roach return I18N::translate('The family trees menu.'); 44*46295629SGreg Roach } 45*46295629SGreg Roach 46*46295629SGreg Roach /** 47*46295629SGreg Roach * The default position for this menu. It can be changed in the control panel. 48*46295629SGreg Roach * 49*46295629SGreg Roach * @return int 50*46295629SGreg Roach */ 51*46295629SGreg Roach public function defaultMenuOrder(): int 52*46295629SGreg Roach { 53*46295629SGreg Roach return 10; 54*46295629SGreg Roach } 55*46295629SGreg Roach 56*46295629SGreg Roach /** 57*46295629SGreg Roach * A menu, to be added to the main application menu. 58*46295629SGreg Roach * 59*46295629SGreg Roach * @param Tree $tree 60*46295629SGreg Roach * 61*46295629SGreg Roach * @return Menu|null 62*46295629SGreg Roach */ 63*46295629SGreg Roach public function getMenu(Tree $tree): ?Menu 64*46295629SGreg Roach { 65*46295629SGreg Roach if (Tree::all()->count() === 1 || Site::getPreference('ALLOW_CHANGE_GEDCOM') !== '1') { 66*46295629SGreg Roach return new Menu(I18N::translate('Family tree'), route('tree-page', ['ged' => $tree->name()]), 'menu-tree'); 67*46295629SGreg Roach } 68*46295629SGreg Roach 69*46295629SGreg Roach $submenus = []; 70*46295629SGreg Roach foreach (Tree::all() as $menu_tree) { 71*46295629SGreg Roach if ($menu_tree->id() === $tree->id()) { 72*46295629SGreg Roach $active = 'active '; 73*46295629SGreg Roach } else { 74*46295629SGreg Roach $active = ''; 75*46295629SGreg Roach } 76*46295629SGreg Roach $submenus[] = new Menu(e($menu_tree->title()), route('tree-page', ['ged' => $menu_tree->name()]), $active . 'menu-tree-' . $menu_tree->id()); 77*46295629SGreg Roach } 78*46295629SGreg Roach 79*46295629SGreg Roach return new Menu(I18N::translate('Family trees'), '#', 'menu-tree', [], $submenus); 80*46295629SGreg Roach } 81*46295629SGreg Roach} 82