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