146295629SGreg Roach<?php 246295629SGreg Roach/** 346295629SGreg Roach * webtrees: online genealogy 446295629SGreg Roach * Copyright (C) 2019 webtrees development team 546295629SGreg Roach * This program is free software: you can redistribute it and/or modify 646295629SGreg Roach * it under the terms of the GNU General Public License as published by 746295629SGreg Roach * the Free Software Foundation, either version 3 of the License, or 846295629SGreg Roach * (at your option) any later version. 946295629SGreg Roach * This program is distributed in the hope that it will be useful, 1046295629SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1146295629SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1246295629SGreg Roach * GNU General Public License for more details. 1346295629SGreg Roach * You should have received a copy of the GNU General Public License 1446295629SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1546295629SGreg Roach */ 1646295629SGreg Roachdeclare(strict_types=1); 1746295629SGreg Roach 1846295629SGreg Roachnamespace Fisharebest\Webtrees\Module; 1946295629SGreg Roach 2067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Auth; 2146295629SGreg Roachuse Fisharebest\Webtrees\I18N; 2246295629SGreg Roachuse Fisharebest\Webtrees\Menu; 2367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\ModuleService; 2446295629SGreg Roachuse Fisharebest\Webtrees\Tree; 2546295629SGreg Roach 2646295629SGreg Roach/** 2746295629SGreg Roach * Class ListsMenuModule - provide a menu option for the lists 2846295629SGreg Roach */ 2937eb8894SGreg Roachclass ListsMenuModule extends AbstractModule implements ModuleMenuInterface 3046295629SGreg Roach{ 3146295629SGreg Roach use ModuleMenuTrait; 3246295629SGreg Roach 33961ec755SGreg Roach /** 3467992b6aSRichard Cissee * @var ModuleService 3567992b6aSRichard Cissee */ 3667992b6aSRichard Cissee private $module_service; 3767992b6aSRichard Cissee 3867992b6aSRichard Cissee /** 3967992b6aSRichard Cissee * ListsMenuModule constructor. 4067992b6aSRichard Cissee * 4167992b6aSRichard Cissee * @param ModuleService $module_service 4267992b6aSRichard Cissee */ 4367992b6aSRichard Cissee public function __construct(ModuleService $module_service) 4467992b6aSRichard Cissee { 4567992b6aSRichard Cissee $this->module_service = $module_service; 4667992b6aSRichard Cissee } 4767992b6aSRichard Cissee 4867992b6aSRichard Cissee /** 490cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 50961ec755SGreg Roach * 51961ec755SGreg Roach * @return string 52961ec755SGreg Roach */ 5346295629SGreg Roach public function title(): string 5446295629SGreg Roach { 5546295629SGreg Roach /* I18N: Name of a module */ 5646295629SGreg Roach return I18N::translate('Lists'); 5746295629SGreg Roach } 5846295629SGreg Roach 59961ec755SGreg Roach /** 60961ec755SGreg Roach * A sentence describing what this module does. 61961ec755SGreg Roach * 62961ec755SGreg Roach * @return string 63961ec755SGreg Roach */ 6446295629SGreg Roach public function description(): string 6546295629SGreg Roach { 6646295629SGreg Roach /* I18N: Description of the “Reports” module */ 6746295629SGreg Roach return I18N::translate('The lists menu.'); 6846295629SGreg Roach } 6946295629SGreg Roach 7046295629SGreg Roach /** 7146295629SGreg Roach * The default position for this menu. It can be changed in the control panel. 7246295629SGreg Roach * 7346295629SGreg Roach * @return int 7446295629SGreg Roach */ 7546295629SGreg Roach public function defaultMenuOrder(): int 7646295629SGreg Roach { 77353b36abSGreg Roach return 3; 7846295629SGreg Roach } 7946295629SGreg Roach 8046295629SGreg Roach /** 8146295629SGreg Roach * A menu, to be added to the main application menu. 8246295629SGreg Roach * 8346295629SGreg Roach * @param Tree $tree 8446295629SGreg Roach * 8546295629SGreg Roach * @return Menu|null 8646295629SGreg Roach */ 8746295629SGreg Roach public function getMenu(Tree $tree): ?Menu 8846295629SGreg Roach { 8987cca37cSGreg Roach $submenus = $this->module_service->findByComponent(ModuleListInterface::class, $tree, Auth::user()) 90*0b5fd0a6SGreg Roach ->map(static function (ModuleListInterface $module) use ($tree): ?Menu { 9167992b6aSRichard Cissee return $module->listMenu($tree); 9267992b6aSRichard Cissee }) 9387cca37cSGreg Roach ->filter() 94*0b5fd0a6SGreg Roach ->sort(static function (Menu $x, Menu $y) { 9587cca37cSGreg Roach return $x->getLabel() <=> $y->getLabel(); 9667992b6aSRichard Cissee }); 9746295629SGreg Roach 9887cca37cSGreg Roach if ($submenus->isEmpty()) { 9967992b6aSRichard Cissee return null; 10046295629SGreg Roach } 10146295629SGreg Roach 10287cca37cSGreg Roach return new Menu(I18N::translate('Lists'), '#', 'menu-list', [], $submenus->all()); 10346295629SGreg Roach } 10446295629SGreg Roach} 105