xref: /webtrees/app/Module/CalendarMenuModule.php (revision 46295629d71d2c598181587a342547db33bf65db)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Module;
19
20use Fisharebest\Webtrees\I18N;
21use Fisharebest\Webtrees\Menu;
22use Fisharebest\Webtrees\Tree;
23
24/**
25 * Class CalendarMenuModule - provide a menu option for the calendar
26 */
27class CalendarMenuModule extends AbstractModule implements ModuleInterface, ModuleMenuInterface
28{
29    use ModuleMenuTrait;
30
31    /** {@inheritdoc} */
32    public function title(): string
33    {
34        /* I18N: Name of a module */
35        return I18N::translate('Calendar');
36    }
37
38    /** {@inheritdoc} */
39    public function description(): string
40    {
41        /* I18N: Description of the “Reports” module */
42        return I18N::translate('The calendar menu.');
43    }
44
45    /**
46     * The default position for this menu.  It can be changed in the control panel.
47     *
48     * @return int
49     */
50    public function defaultMenuOrder(): int
51    {
52        return 40;
53    }
54
55    /**
56     * A menu, to be added to the main application menu.
57     *
58     * @param Tree $tree
59     *
60     * @return Menu|null
61     */
62    public function getMenu(Tree $tree): ?Menu
63    {
64        $submenu = [
65            $this->calendarDayMenu($tree),
66            $this->calendarMonthMenu($tree),
67            $this->calendarYearMenu($tree),
68        ];
69
70        return new Menu(I18N::translate('Calendar'), '#', 'menu-calendar', ['rel' => 'nofollow'], $submenu);
71    }
72
73    /**
74     * @param Tree $tree
75     *
76     * @return Menu
77     */
78    protected function calendarDayMenu(Tree $tree): Menu
79    {
80        return new Menu(I18N::translate('Day'), route('calendar', [
81            'view' => 'day',
82            'ged'  => $tree->name(),
83        ]), 'menu-calendar-day', ['rel' => 'nofollow']);
84    }
85
86    /**
87     * @param Tree $tree
88     *
89     * @return Menu
90     */
91    protected function calendarMonthMenu(Tree $tree): Menu
92    {
93        return new Menu(I18N::translate('Month'), route('calendar', [
94            'view' => 'day',
95            'ged'  => $tree->name(),
96        ]), 'menu-calendar-month', ['rel' => 'nofollow']);
97    }
98
99    /**
100     * @param Tree $tree
101     *
102     * @return Menu
103     */
104    protected function calendarYearMenu(Tree $tree): Menu
105    {
106        return new Menu(I18N::translate('Year'), route('calendar', [
107            'view' => 'day',
108            'ged'  => $tree->name(),
109        ]), 'menu-calendar-year', ['rel' => 'nofollow']);
110    }
111}
112