xref: /webtrees/app/Module/ReportsMenuModule.php (revision 353b36ab5fd4f6ba09f89e2865edee7108bdf7c0)
146295629SGreg Roach<?php
246295629SGreg Roach/**
346295629SGreg Roach * webtrees: online genealogy
446295629SGreg Roach * Copyright (C) 2019 webtrees development team
546295629SGreg Roach * This program is free software: you can redistribute it and/or modify
646295629SGreg Roach * it under the terms of the GNU General Public License as published by
746295629SGreg Roach * the Free Software Foundation, either version 3 of the License, or
846295629SGreg Roach * (at your option) any later version.
946295629SGreg Roach * This program is distributed in the hope that it will be useful,
1046295629SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1146295629SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1246295629SGreg Roach * GNU General Public License for more details.
1346295629SGreg Roach * You should have received a copy of the GNU General Public License
1446295629SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1546295629SGreg Roach */
1646295629SGreg Roachdeclare(strict_types=1);
1746295629SGreg Roach
1846295629SGreg Roachnamespace Fisharebest\Webtrees\Module;
1946295629SGreg Roach
2046295629SGreg Roachuse Fisharebest\Webtrees\Auth;
2146295629SGreg Roachuse Fisharebest\Webtrees\I18N;
2246295629SGreg Roachuse Fisharebest\Webtrees\Individual;
2346295629SGreg Roachuse Fisharebest\Webtrees\Menu;
2446295629SGreg Roachuse Fisharebest\Webtrees\Module;
2546295629SGreg Roachuse Fisharebest\Webtrees\Tree;
2646295629SGreg Roachuse Symfony\Component\HttpFoundation\Request;
2746295629SGreg Roach
2846295629SGreg Roach/**
2946295629SGreg Roach * Class ReportsMenuModule - provide a menu option for the reports
3046295629SGreg Roach */
3146295629SGreg Roachclass ReportsMenuModule extends AbstractModule implements ModuleInterface, ModuleMenuInterface
3246295629SGreg Roach{
3346295629SGreg Roach    use ModuleMenuTrait;
3446295629SGreg Roach
35961ec755SGreg Roach    /**
36961ec755SGreg Roach     * How should this module be labelled on tabs, menus, etc.?
37961ec755SGreg Roach     *
38961ec755SGreg Roach     * @return string
39961ec755SGreg Roach     */
4046295629SGreg Roach    /** {@inheritdoc} */
4146295629SGreg Roach    public function title(): string
4246295629SGreg Roach    {
4346295629SGreg Roach        /* I18N: Name of a module */
4446295629SGreg Roach        return I18N::translate('Reports');
4546295629SGreg Roach    }
4646295629SGreg Roach
47961ec755SGreg Roach    /**
48961ec755SGreg Roach     * A sentence describing what this module does.
49961ec755SGreg Roach     *
50961ec755SGreg Roach     * @return string
51961ec755SGreg Roach     */
5246295629SGreg Roach    public function description(): string
5346295629SGreg Roach    {
5446295629SGreg Roach        /* I18N: Description of the “Reports” module */
5546295629SGreg Roach        return I18N::translate('The reports menu.');
5646295629SGreg Roach    }
5746295629SGreg Roach
5846295629SGreg Roach    /**
5946295629SGreg Roach     * The default position for this menu.  It can be changed in the control panel.
6046295629SGreg Roach     *
6146295629SGreg Roach     * @return int
6246295629SGreg Roach     */
6346295629SGreg Roach    public function defaultMenuOrder(): int
6446295629SGreg Roach    {
65*353b36abSGreg Roach        return 5;
6646295629SGreg Roach    }
6746295629SGreg Roach
6846295629SGreg Roach    /**
6946295629SGreg Roach     * A menu, to be added to the main application menu.
7046295629SGreg Roach     *
7146295629SGreg Roach     * @param Tree $tree
7246295629SGreg Roach     *
7346295629SGreg Roach     * @return Menu|null
7446295629SGreg Roach     */
7546295629SGreg Roach    public function getMenu(Tree $tree): ?Menu
7646295629SGreg Roach    {
7746295629SGreg Roach        $request    = Request::createFromGlobals();
7846295629SGreg Roach        $xref       = $request->get('xref', '');
7946295629SGreg Roach        $individual = Individual::getInstance($xref, $tree) ?? $tree->significantIndividual(Auth::user());
8046295629SGreg Roach        $submenus   = Module::activeReports($tree)
8146295629SGreg Roach            ->map(function (ModuleReportInterface $module) use ($individual): Menu {
8246295629SGreg Roach                return $module->getReportMenu($individual);
8346295629SGreg Roach            });
8446295629SGreg Roach
8546295629SGreg Roach        if ($submenus->isEmpty()) {
8646295629SGreg Roach            return null;
8746295629SGreg Roach        }
8846295629SGreg Roach
8946295629SGreg Roach        return new Menu(I18N::translate('Reports'), '#', 'menu-report', ['rel' => 'nofollow'], $submenus->all());
9046295629SGreg Roach    }
9146295629SGreg Roach}
92