xref: /webtrees/app/Http/RequestHandlers/ReportSetupAction.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\Auth;
231cfe16bdSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
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 Roachuse function redirect;
321cfe16bdSGreg Roachuse function route;
331cfe16bdSGreg Roach
341cfe16bdSGreg Roach/**
351cfe16bdSGreg Roach * Get parameters for a report.
361cfe16bdSGreg Roach */
371cfe16bdSGreg Roachclass ReportSetupAction implements RequestHandlerInterface
381cfe16bdSGreg Roach{
391cfe16bdSGreg Roach    use ViewResponseTrait;
401cfe16bdSGreg Roach
4143f2f523SGreg Roach    private ModuleService $module_service;
421cfe16bdSGreg Roach
431cfe16bdSGreg Roach    /**
441cfe16bdSGreg Roach     * @param ModuleService $module_service
451cfe16bdSGreg Roach     */
461cfe16bdSGreg Roach    public function __construct(ModuleService $module_service)
471cfe16bdSGreg Roach    {
481cfe16bdSGreg Roach        $this->module_service = $module_service;
491cfe16bdSGreg Roach    }
501cfe16bdSGreg Roach
511cfe16bdSGreg Roach    /**
521cfe16bdSGreg Roach     * @param ServerRequestInterface $request
531cfe16bdSGreg Roach     *
541cfe16bdSGreg Roach     * @return ResponseInterface
551cfe16bdSGreg Roach     */
561cfe16bdSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
571cfe16bdSGreg Roach    {
58b55cbc6bSGreg Roach        $tree   = Validator::attributes($request)->tree();
59b55cbc6bSGreg Roach        $user   = Validator::attributes($request)->user();
60b55cbc6bSGreg Roach        $report = Validator::attributes($request)->string('report');
611cfe16bdSGreg Roach        $module = $this->module_service->findByName($report);
621cfe16bdSGreg Roach
631cfe16bdSGreg Roach        if (!$module instanceof ModuleReportInterface) {
641cfe16bdSGreg Roach            return redirect(route(ReportListPage::class, ['tree' => $tree->name()]));
651cfe16bdSGreg Roach        }
661cfe16bdSGreg Roach
67ef483801SGreg Roach        Auth::checkComponentAccess($module, ModuleReportInterface::class, $tree, $user);
681cfe16bdSGreg Roach
69748dbe15SGreg Roach        return redirect(route(ReportGenerate::class, [
70748dbe15SGreg Roach            'tree'        => $tree->name(),
71748dbe15SGreg Roach            'report'      => $report,
72748dbe15SGreg Roach            'destination' => Validator::parsedBody($request)->string('destination'),
73748dbe15SGreg Roach            'format'      => Validator::parsedBody($request)->string('format'),
74748dbe15SGreg Roach            'varnames'    => Validator::parsedBody($request)->array('varnames'),
75748dbe15SGreg Roach            'vars'        => Validator::parsedBody($request)->array('vars'),
76748dbe15SGreg Roach        ]));
771cfe16bdSGreg Roach    }
781cfe16bdSGreg Roach}
79