xref: /webtrees/app/Module/ModuleReportTrait.php (revision 5a8afed46297e8105e3e5a33ce37e6a8e88bc79d)
149a243cbSGreg Roach<?php
23976b470SGreg Roach
349a243cbSGreg Roach/**
449a243cbSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
649a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
749a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
849a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
949a243cbSGreg Roach * (at your option) any later version.
1049a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1149a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1249a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1349a243cbSGreg Roach * GNU General Public License for more details.
1449a243cbSGreg 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/>.
1649a243cbSGreg Roach */
17fcfa147eSGreg Roach
1849a243cbSGreg Roachdeclare(strict_types=1);
1949a243cbSGreg Roach
2049a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
2149a243cbSGreg Roach
221cfe16bdSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ReportSetupPage;
239af6b024SGreg Roachuse Fisharebest\Webtrees\Individual;
249af6b024SGreg Roachuse Fisharebest\Webtrees\Menu;
259af6b024SGreg Roach
2649a243cbSGreg Roach/**
2749a243cbSGreg Roach * Trait ModuleReportTrait - default implementation of ModuleReportInterface
2849a243cbSGreg Roach */
2949a243cbSGreg Roachtrait ModuleReportTrait
3049a243cbSGreg Roach{
319af6b024SGreg Roach    /**
32bfed30e4SGreg Roach     * A unique internal name for this module (based on the installation folder).
33bfed30e4SGreg Roach     *
34bfed30e4SGreg Roach     * @return string
35bfed30e4SGreg Roach     */
36bfed30e4SGreg Roach    abstract public function name(): string;
37bfed30e4SGreg Roach
38bfed30e4SGreg Roach    /**
39bfed30e4SGreg Roach     * How should this module be identified in the control panel, etc.?
40bfed30e4SGreg Roach     *
41bfed30e4SGreg Roach     * @return string
42bfed30e4SGreg Roach     */
43bfed30e4SGreg Roach    abstract public function title(): string;
44bfed30e4SGreg Roach
45bfed30e4SGreg Roach    /**
469af6b024SGreg Roach     * Name of the XML report file, relative to the resources folder.
479af6b024SGreg Roach     *
489af6b024SGreg Roach     * @return string
499af6b024SGreg Roach     */
509af6b024SGreg Roach    public function xmlFilename(): string
519af6b024SGreg Roach    {
52aacc22caSGreg Roach        return 'xml/reports/' . $this->name() . '.xml';
539af6b024SGreg Roach    }
549af6b024SGreg Roach
559af6b024SGreg Roach    /**
569af6b024SGreg Roach     * Return a menu item for this report.
579af6b024SGreg Roach     *
589af6b024SGreg Roach     * @param Individual $individual
599af6b024SGreg Roach     *
609af6b024SGreg Roach     * @return Menu
619af6b024SGreg Roach     */
629af6b024SGreg Roach    public function getReportMenu(Individual $individual): Menu
639af6b024SGreg Roach    {
649af6b024SGreg Roach        return new Menu(
659af6b024SGreg Roach            $this->title(),
661cfe16bdSGreg Roach            route(ReportSetupPage::class, [
679af6b024SGreg Roach                'xref'   => $individual->xref(),
68d72b284aSGreg Roach                'tree'   => $individual->tree()->name(),
699af6b024SGreg Roach                'report' => $this->name(),
709af6b024SGreg Roach            ]),
719af6b024SGreg Roach            'menu-report-' . $this->name(),
729af6b024SGreg Roach            ['rel' => 'nofollow']
739af6b024SGreg Roach        );
749af6b024SGreg Roach    }
7549a243cbSGreg Roach}
76