xref: /webtrees/app/Module/ModuleChartTrait.php (revision 455a30fe529581f1d53045f9c38a0674472d498f)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Module;
21
22use Fisharebest\Webtrees\Individual;
23use Fisharebest\Webtrees\Menu;
24
25/**
26 * Trait ModuleChartTrait - default implementation of ModuleChartInterface
27 */
28trait ModuleChartTrait
29{
30    /**
31     * A menu item for this chart for an individual box in a chart.
32     *
33     * @param Individual $individual
34     *
35     * @return Menu|null
36     */
37    public function chartBoxMenu(Individual $individual): ?Menu
38    {
39        return null;
40    }
41
42    /**
43     * A main menu item for this chart.
44     *
45     * @param Individual $individual
46     *
47     * @return Menu
48     */
49    public function chartMenu(Individual $individual): Menu
50    {
51        return new Menu(
52            $this->title(),
53            $this->chartUrl($individual),
54            $this->chartMenuClass(),
55            $this->chartUrlAttributes()
56        );
57    }
58
59    /**
60     * CSS class for the menu.
61     *
62     * @return string
63     */
64    public function chartMenuClass(): string
65    {
66        return '';
67    }
68
69    /**
70     * The title for a specific instance of this chart.
71     *
72     * @param Individual $individual
73     *
74     * @return string
75     */
76    public function chartTitle(Individual $individual): string
77    {
78        return $this->title();
79    }
80
81    /**
82     * The URL for a page showing chart options.
83     *
84     * @param Individual $individual
85     * @param mixed[]    $parameters
86     *
87     * @return string
88     */
89    public function chartUrl(Individual $individual, array $parameters = []): string
90    {
91        return route('module', [
92                'module' => $this->name(),
93                'action' => 'Chart',
94                'xref'   => $individual->xref(),
95                'tree'    => $individual->tree()->name(),
96        ] + $parameters);
97    }
98
99    /**
100     * Attributes for the URL.
101     *
102     * @return string[]
103     */
104    public function chartUrlAttributes(): array
105    {
106        return ['rel' => 'nofollow'];
107    }
108}
109