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