xref: /webtrees/app/Http/RequestHandlers/ReportListPage.php (revision e93a8df2f8d797005750082cc3766c0e80799688)
11cfe16bdSGreg Roach<?php
21cfe16bdSGreg Roach
31cfe16bdSGreg Roach/**
41cfe16bdSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
61cfe16bdSGreg Roach * This program is free software: you can redistribute it and/or modify
71cfe16bdSGreg Roach * it under the terms of the GNU General Public License as published by
81cfe16bdSGreg Roach * the Free Software Foundation, either version 3 of the License, or
91cfe16bdSGreg Roach * (at your option) any later version.
101cfe16bdSGreg Roach * This program is distributed in the hope that it will be useful,
111cfe16bdSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
121cfe16bdSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131cfe16bdSGreg Roach * GNU General Public License for more details.
141cfe16bdSGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
161cfe16bdSGreg Roach */
171cfe16bdSGreg Roach
181cfe16bdSGreg Roachdeclare(strict_types=1);
191cfe16bdSGreg Roach
201cfe16bdSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
211cfe16bdSGreg Roach
221cfe16bdSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
231cfe16bdSGreg Roachuse Fisharebest\Webtrees\I18N;
241cfe16bdSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface;
251cfe16bdSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService;
26b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator;
271cfe16bdSGreg Roachuse Psr\Http\Message\ResponseInterface;
281cfe16bdSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
291cfe16bdSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
301cfe16bdSGreg Roach
311cfe16bdSGreg Roach/**
321cfe16bdSGreg Roach * Show all available reports.
331cfe16bdSGreg Roach */
341cfe16bdSGreg Roachclass ReportListPage implements RequestHandlerInterface
351cfe16bdSGreg Roach{
361cfe16bdSGreg Roach    use ViewResponseTrait;
371cfe16bdSGreg Roach
3843f2f523SGreg Roach    private ModuleService $module_service;
391cfe16bdSGreg Roach
401cfe16bdSGreg Roach    /**
411cfe16bdSGreg Roach     * @param ModuleService $module_service
421cfe16bdSGreg Roach     */
431cfe16bdSGreg Roach    public function __construct(ModuleService $module_service)
441cfe16bdSGreg Roach    {
451cfe16bdSGreg Roach        $this->module_service = $module_service;
461cfe16bdSGreg Roach    }
471cfe16bdSGreg Roach
481cfe16bdSGreg Roach    /**
491cfe16bdSGreg Roach     * A list of available reports.
501cfe16bdSGreg Roach     *
511cfe16bdSGreg Roach     * @param ServerRequestInterface $request
521cfe16bdSGreg Roach     *
531cfe16bdSGreg Roach     * @return ResponseInterface
541cfe16bdSGreg Roach     */
551cfe16bdSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
561cfe16bdSGreg Roach    {
57b55cbc6bSGreg Roach        $tree = Validator::attributes($request)->tree();
58b55cbc6bSGreg Roach        $user = Validator::attributes($request)->user();
591cfe16bdSGreg Roach
601cfe16bdSGreg Roach        $reports = $this->module_service
611cfe16bdSGreg Roach            ->findByComponent(ModuleReportInterface::class, $tree, $user);
621cfe16bdSGreg Roach
631cfe16bdSGreg Roach        $title = I18N::translate('Choose a report to run');
641cfe16bdSGreg Roach
651cfe16bdSGreg Roach        return $this->viewResponse('report-select-page', [
661cfe16bdSGreg Roach            'reports' => $reports,
671cfe16bdSGreg Roach            'title'   => $title,
681cfe16bdSGreg Roach            'tree'    => $tree,
691cfe16bdSGreg Roach        ]);
701cfe16bdSGreg Roach    }
711cfe16bdSGreg Roach}
72