xref: /webtrees/app/Module/CalendarMenuModule.php (revision fcfa147e10aaa6c7ff580c29bd6e5b88666befc1)
146295629SGreg Roach<?php
23976b470SGreg Roach
346295629SGreg Roach/**
446295629SGreg Roach * webtrees: online genealogy
546295629SGreg Roach * Copyright (C) 2019 webtrees development team
646295629SGreg Roach * This program is free software: you can redistribute it and/or modify
746295629SGreg Roach * it under the terms of the GNU General Public License as published by
846295629SGreg Roach * the Free Software Foundation, either version 3 of the License, or
946295629SGreg Roach * (at your option) any later version.
1046295629SGreg Roach * This program is distributed in the hope that it will be useful,
1146295629SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1246295629SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1346295629SGreg Roach * GNU General Public License for more details.
1446295629SGreg Roach * You should have received a copy of the GNU General Public License
1546295629SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1646295629SGreg Roach */
17*fcfa147eSGreg Roach
1846295629SGreg Roachdeclare(strict_types=1);
1946295629SGreg Roach
2046295629SGreg Roachnamespace Fisharebest\Webtrees\Module;
2146295629SGreg Roach
2246295629SGreg Roachuse Fisharebest\Webtrees\I18N;
2346295629SGreg Roachuse Fisharebest\Webtrees\Menu;
2446295629SGreg Roachuse Fisharebest\Webtrees\Tree;
2546295629SGreg Roach
2646295629SGreg Roach/**
2746295629SGreg Roach * Class CalendarMenuModule - provide a menu option for the calendar
2846295629SGreg Roach */
2937eb8894SGreg Roachclass CalendarMenuModule extends AbstractModule implements ModuleMenuInterface
3046295629SGreg Roach{
3146295629SGreg Roach    use ModuleMenuTrait;
3246295629SGreg Roach
33961ec755SGreg Roach    /**
340cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
35961ec755SGreg Roach     *
36961ec755SGreg Roach     * @return string
37961ec755SGreg Roach     */
3846295629SGreg Roach    public function title(): string
3946295629SGreg Roach    {
4046295629SGreg Roach        /* I18N: Name of a module */
4146295629SGreg Roach        return I18N::translate('Calendar');
4246295629SGreg Roach    }
4346295629SGreg Roach
44961ec755SGreg Roach    /**
45961ec755SGreg Roach     * A sentence describing what this module does.
46961ec755SGreg Roach     *
47961ec755SGreg Roach     * @return string
48961ec755SGreg Roach     */
4946295629SGreg Roach    public function description(): string
5046295629SGreg Roach    {
5146295629SGreg Roach        /* I18N: Description of the “Reports” module */
5246295629SGreg Roach        return I18N::translate('The calendar menu.');
5346295629SGreg Roach    }
5446295629SGreg Roach
5546295629SGreg Roach    /**
5646295629SGreg Roach     * The default position for this menu.  It can be changed in the control panel.
5746295629SGreg Roach     *
5846295629SGreg Roach     * @return int
5946295629SGreg Roach     */
6046295629SGreg Roach    public function defaultMenuOrder(): int
6146295629SGreg Roach    {
62353b36abSGreg Roach        return 4;
6346295629SGreg Roach    }
6446295629SGreg Roach
6546295629SGreg Roach    /**
6646295629SGreg Roach     * A menu, to be added to the main application menu.
6746295629SGreg Roach     *
6846295629SGreg Roach     * @param Tree $tree
6946295629SGreg Roach     *
7046295629SGreg Roach     * @return Menu|null
7146295629SGreg Roach     */
7246295629SGreg Roach    public function getMenu(Tree $tree): ?Menu
7346295629SGreg Roach    {
7446295629SGreg Roach        $submenu = [
7546295629SGreg Roach            $this->calendarDayMenu($tree),
7646295629SGreg Roach            $this->calendarMonthMenu($tree),
7746295629SGreg Roach            $this->calendarYearMenu($tree),
7846295629SGreg Roach        ];
7946295629SGreg Roach
8046295629SGreg Roach        return new Menu(I18N::translate('Calendar'), '#', 'menu-calendar', ['rel' => 'nofollow'], $submenu);
8146295629SGreg Roach    }
8246295629SGreg Roach
8346295629SGreg Roach    /**
8446295629SGreg Roach     * @param Tree $tree
8546295629SGreg Roach     *
8646295629SGreg Roach     * @return Menu
8746295629SGreg Roach     */
8846295629SGreg Roach    protected function calendarDayMenu(Tree $tree): Menu
8946295629SGreg Roach    {
9046295629SGreg Roach        return new Menu(I18N::translate('Day'), route('calendar', [
9146295629SGreg Roach            'view' => 'day',
92d72b284aSGreg Roach            'tree' => $tree->name(),
9346295629SGreg Roach        ]), 'menu-calendar-day', ['rel' => 'nofollow']);
9446295629SGreg Roach    }
9546295629SGreg Roach
9646295629SGreg Roach    /**
9746295629SGreg Roach     * @param Tree $tree
9846295629SGreg Roach     *
9946295629SGreg Roach     * @return Menu
10046295629SGreg Roach     */
10146295629SGreg Roach    protected function calendarMonthMenu(Tree $tree): Menu
10246295629SGreg Roach    {
10346295629SGreg Roach        return new Menu(I18N::translate('Month'), route('calendar', [
104a5145634SGreg Roach            'view' => 'month',
105d72b284aSGreg Roach            'tree' => $tree->name(),
10646295629SGreg Roach        ]), 'menu-calendar-month', ['rel' => 'nofollow']);
10746295629SGreg Roach    }
10846295629SGreg Roach
10946295629SGreg Roach    /**
11046295629SGreg Roach     * @param Tree $tree
11146295629SGreg Roach     *
11246295629SGreg Roach     * @return Menu
11346295629SGreg Roach     */
11446295629SGreg Roach    protected function calendarYearMenu(Tree $tree): Menu
11546295629SGreg Roach    {
11646295629SGreg Roach        return new Menu(I18N::translate('Year'), route('calendar', [
117a5145634SGreg Roach            'view' => 'year',
118d72b284aSGreg Roach            'tree' => $tree->name(),
11946295629SGreg Roach        ]), 'menu-calendar-year', ['rel' => 'nofollow']);
12046295629SGreg Roach    }
12146295629SGreg Roach}
122