xref: /webtrees/app/Module/ModuleChartTrait.php (revision 4a1f1d433794f86f893b59883147e57af4e94374)
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\Individual;
21use Fisharebest\Webtrees\Menu;
22
23/**
24 * Trait ModuleChartTrait - default implementation of ModuleChartInterface
25 */
26trait ModuleChartTrait
27{
28    /**
29     * @return string
30     */
31    abstract public function name(): string;
32
33    /**
34     * @return string
35     */
36    abstract public function title(): string;
37
38    /**
39     * A menu item for this chart for an individual box in a chart.
40     *
41     * @param Individual $individual
42     *
43     * @return Menu|null
44     */
45    public function chartBoxMenu(Individual $individual): ?Menu
46    {
47        return null;
48    }
49
50    /**
51     * A main menu item for this chart.
52     *
53     * @param Individual $individual
54     *
55     * @return Menu
56     */
57    public function chartMenu(Individual $individual): Menu
58    {
59        return new Menu(
60            $this->title(),
61            $this->chartUrl($individual),
62            $this->chartMenuClass(),
63            $this->chartUrlAttributes()
64        );
65    }
66
67    /**
68     * CSS class for the menu.
69     *
70     * @return string
71     */
72    public function chartMenuClass(): string
73    {
74        return '';
75    }
76
77    /**
78     * The title for a specific instance of this chart.
79     *
80     * @param Individual $individual
81     *
82     * @return string
83     */
84    public function chartTitle(Individual $individual): string
85    {
86        return $this->title();
87    }
88
89    /**
90     * The URL for a page showing chart options.
91     *
92     * @param Individual $individual
93     * @param string[]   $parameters
94     *
95     * @return string
96     */
97    public function chartUrl(Individual $individual, array $parameters = []): string
98    {
99        return route('module', [
100                'module' => $this->name(),
101                'action' => 'Chart',
102                'xref'   => $individual->xref(),
103                'ged'    => $individual->tree()->name(),
104        ] + $parameters);
105    }
106
107    /**
108     * Attributes for the URL.
109     *
110     * @return string[]
111     */
112    public function chartUrlAttributes(): array
113    {
114        return ['rel' => 'nofollow'];
115    }
116}
117