146295629SGreg Roach<?php 23976b470SGreg Roach 346295629SGreg Roach/** 446295629SGreg Roach * webtrees: online genealogy 546295629SGreg Roach * Copyright (C) 2019 webtrees development team 646295629SGreg Roach * This program is free software: you can redistribute it and/or modify 746295629SGreg Roach * it under the terms of the GNU General Public License as published by 846295629SGreg Roach * the Free Software Foundation, either version 3 of the License, or 946295629SGreg Roach * (at your option) any later version. 1046295629SGreg Roach * This program is distributed in the hope that it will be useful, 1146295629SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1246295629SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1346295629SGreg Roach * GNU General Public License for more details. 1446295629SGreg Roach * You should have received a copy of the GNU General Public License 1546295629SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1646295629SGreg Roach */ 17*fcfa147eSGreg Roach 1846295629SGreg Roachdeclare(strict_types=1); 1946295629SGreg Roach 2046295629SGreg Roachnamespace Fisharebest\Webtrees\Module; 2146295629SGreg Roach 2246295629SGreg Roachuse Fisharebest\Webtrees\Auth; 2346295629SGreg Roachuse Fisharebest\Webtrees\I18N; 2446295629SGreg Roachuse Fisharebest\Webtrees\Individual; 2546295629SGreg Roachuse Fisharebest\Webtrees\Menu; 264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 2746295629SGreg Roachuse Fisharebest\Webtrees\Tree; 286ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 293976b470SGreg Roach 306ccdf4f0SGreg Roachuse function app; 3146295629SGreg Roach 3246295629SGreg Roach/** 3346295629SGreg Roach * Class ReportsMenuModule - provide a menu option for the reports 3446295629SGreg Roach */ 3537eb8894SGreg Roachclass ReportsMenuModule extends AbstractModule implements ModuleMenuInterface 3646295629SGreg Roach{ 3746295629SGreg Roach use ModuleMenuTrait; 3846295629SGreg Roach 39961ec755SGreg Roach /** 404ca7e03cSGreg Roach * @var ModuleService 414ca7e03cSGreg Roach */ 424ca7e03cSGreg Roach private $module_service; 434ca7e03cSGreg Roach 444ca7e03cSGreg Roach /** 454ca7e03cSGreg Roach * ChartsMenuModule constructor. 464ca7e03cSGreg Roach * 474ca7e03cSGreg Roach * @param ModuleService $module_service 484ca7e03cSGreg Roach */ 494ca7e03cSGreg Roach public function __construct(ModuleService $module_service) 504ca7e03cSGreg Roach { 514ca7e03cSGreg Roach $this->module_service = $module_service; 524ca7e03cSGreg Roach } 534ca7e03cSGreg Roach 544ca7e03cSGreg Roach /** 550cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 56961ec755SGreg Roach * 57961ec755SGreg Roach * @return string 58961ec755SGreg Roach */ 5946295629SGreg Roach /** {@inheritdoc} */ 6046295629SGreg Roach public function title(): string 6146295629SGreg Roach { 6246295629SGreg Roach /* I18N: Name of a module */ 6346295629SGreg Roach return I18N::translate('Reports'); 6446295629SGreg Roach } 6546295629SGreg Roach 66961ec755SGreg Roach /** 67961ec755SGreg Roach * A sentence describing what this module does. 68961ec755SGreg Roach * 69961ec755SGreg Roach * @return string 70961ec755SGreg Roach */ 7146295629SGreg Roach public function description(): string 7246295629SGreg Roach { 7346295629SGreg Roach /* I18N: Description of the “Reports” module */ 7446295629SGreg Roach return I18N::translate('The reports menu.'); 7546295629SGreg Roach } 7646295629SGreg Roach 7746295629SGreg Roach /** 7846295629SGreg Roach * The default position for this menu. It can be changed in the control panel. 7946295629SGreg Roach * 8046295629SGreg Roach * @return int 8146295629SGreg Roach */ 8246295629SGreg Roach public function defaultMenuOrder(): int 8346295629SGreg Roach { 84353b36abSGreg Roach return 5; 8546295629SGreg Roach } 8646295629SGreg Roach 8746295629SGreg Roach /** 8846295629SGreg Roach * A menu, to be added to the main application menu. 8946295629SGreg Roach * 9046295629SGreg Roach * @param Tree $tree 9146295629SGreg Roach * 9246295629SGreg Roach * @return Menu|null 9346295629SGreg Roach */ 9446295629SGreg Roach public function getMenu(Tree $tree): ?Menu 9546295629SGreg Roach { 966ccdf4f0SGreg Roach $request = app(ServerRequestInterface::class); 976ccdf4f0SGreg Roach $xref = $request->getQueryParams()['xref'] ?? ''; 9846295629SGreg Roach $individual = Individual::getInstance($xref, $tree) ?? $tree->significantIndividual(Auth::user()); 9987cca37cSGreg Roach $submenus = $this->module_service->findByComponent(ModuleReportInterface::class, $tree, Auth::user()) 1000b5fd0a6SGreg Roach ->map(static function (ModuleReportInterface $module) use ($individual): Menu { 10146295629SGreg Roach return $module->getReportMenu($individual); 10246295629SGreg Roach }); 10346295629SGreg Roach 10446295629SGreg Roach if ($submenus->isEmpty()) { 10546295629SGreg Roach return null; 10646295629SGreg Roach } 10746295629SGreg Roach 10846295629SGreg Roach return new Menu(I18N::translate('Reports'), '#', 'menu-report', ['rel' => 'nofollow'], $submenus->all()); 10946295629SGreg Roach } 11046295629SGreg Roach} 111