1*1cfe16bdSGreg Roach<?php 2*1cfe16bdSGreg Roach 3*1cfe16bdSGreg Roach/** 4*1cfe16bdSGreg Roach * webtrees: online genealogy 5*1cfe16bdSGreg Roach * Copyright (C) 2019 webtrees development team 6*1cfe16bdSGreg Roach * This program is free software: you can redistribute it and/or modify 7*1cfe16bdSGreg Roach * it under the terms of the GNU General Public License as published by 8*1cfe16bdSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*1cfe16bdSGreg Roach * (at your option) any later version. 10*1cfe16bdSGreg Roach * This program is distributed in the hope that it will be useful, 11*1cfe16bdSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*1cfe16bdSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*1cfe16bdSGreg Roach * GNU General Public License for more details. 14*1cfe16bdSGreg Roach * You should have received a copy of the GNU General Public License 15*1cfe16bdSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*1cfe16bdSGreg Roach */ 17*1cfe16bdSGreg Roach 18*1cfe16bdSGreg Roachdeclare(strict_types=1); 19*1cfe16bdSGreg Roach 20*1cfe16bdSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*1cfe16bdSGreg Roach 22*1cfe16bdSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 23*1cfe16bdSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 24*1cfe16bdSGreg Roachuse Fisharebest\Webtrees\I18N; 25*1cfe16bdSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface; 26*1cfe16bdSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 27*1cfe16bdSGreg Roachuse Fisharebest\Webtrees\Tree; 28*1cfe16bdSGreg Roachuse InvalidArgumentException; 29*1cfe16bdSGreg Roachuse Psr\Http\Message\ResponseInterface; 30*1cfe16bdSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 31*1cfe16bdSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 32*1cfe16bdSGreg Roach 33*1cfe16bdSGreg Roachuse function assert; 34*1cfe16bdSGreg Roach 35*1cfe16bdSGreg Roach/** 36*1cfe16bdSGreg Roach * Show all available reports. 37*1cfe16bdSGreg Roach */ 38*1cfe16bdSGreg Roachclass ReportListPage implements RequestHandlerInterface 39*1cfe16bdSGreg Roach{ 40*1cfe16bdSGreg Roach use ViewResponseTrait; 41*1cfe16bdSGreg Roach 42*1cfe16bdSGreg Roach /** 43*1cfe16bdSGreg Roach * @var ModuleService 44*1cfe16bdSGreg Roach */ 45*1cfe16bdSGreg Roach private $module_service; 46*1cfe16bdSGreg Roach 47*1cfe16bdSGreg Roach /** 48*1cfe16bdSGreg Roach * ReportEngineController constructor. 49*1cfe16bdSGreg Roach * 50*1cfe16bdSGreg Roach * @param ModuleService $module_service 51*1cfe16bdSGreg Roach */ 52*1cfe16bdSGreg Roach public function __construct(ModuleService $module_service) 53*1cfe16bdSGreg Roach { 54*1cfe16bdSGreg Roach $this->module_service = $module_service; 55*1cfe16bdSGreg Roach } 56*1cfe16bdSGreg Roach 57*1cfe16bdSGreg Roach /** 58*1cfe16bdSGreg Roach * A list of available reports. 59*1cfe16bdSGreg Roach * 60*1cfe16bdSGreg Roach * @param ServerRequestInterface $request 61*1cfe16bdSGreg Roach * 62*1cfe16bdSGreg Roach * @return ResponseInterface 63*1cfe16bdSGreg Roach */ 64*1cfe16bdSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 65*1cfe16bdSGreg Roach { 66*1cfe16bdSGreg Roach $tree = $request->getAttribute('tree'); 67*1cfe16bdSGreg Roach assert($tree instanceof Tree, new InvalidArgumentException()); 68*1cfe16bdSGreg Roach 69*1cfe16bdSGreg Roach $user = $request->getAttribute('user'); 70*1cfe16bdSGreg Roach assert($user instanceof UserInterface, new InvalidArgumentException()); 71*1cfe16bdSGreg Roach 72*1cfe16bdSGreg Roach $reports = $this->module_service 73*1cfe16bdSGreg Roach ->findByComponent(ModuleReportInterface::class, $tree, $user); 74*1cfe16bdSGreg Roach 75*1cfe16bdSGreg Roach $title = I18N::translate('Choose a report to run'); 76*1cfe16bdSGreg Roach 77*1cfe16bdSGreg Roach return $this->viewResponse('report-select-page', [ 78*1cfe16bdSGreg Roach 'reports' => $reports, 79*1cfe16bdSGreg Roach 'title' => $title, 80*1cfe16bdSGreg Roach 'tree' => $tree, 81*1cfe16bdSGreg Roach ]); 82*1cfe16bdSGreg Roach } 83*1cfe16bdSGreg Roach} 84