xref: /webtrees/app/Module/ModuleChartTrait.php (revision 7413816e6dd2d50e569034fb804f3dce7471bb94)
149a243cbSGreg Roach<?php
23976b470SGreg Roach
349a243cbSGreg Roach/**
449a243cbSGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
649a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
749a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
849a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
949a243cbSGreg Roach * (at your option) any later version.
1049a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1149a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1249a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1349a243cbSGreg Roach * GNU General Public License for more details.
1449a243cbSGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
1649a243cbSGreg Roach */
17fcfa147eSGreg Roach
1849a243cbSGreg Roachdeclare(strict_types=1);
1949a243cbSGreg Roach
2049a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
2149a243cbSGreg Roach
2249a243cbSGreg Roachuse Fisharebest\Webtrees\Individual;
2349a243cbSGreg Roachuse Fisharebest\Webtrees\Menu;
2449a243cbSGreg Roach
2549a243cbSGreg Roach/**
2649a243cbSGreg Roach * Trait ModuleChartTrait - default implementation of ModuleChartInterface
2749a243cbSGreg Roach */
2849a243cbSGreg Roachtrait ModuleChartTrait
2949a243cbSGreg Roach{
3049a243cbSGreg Roach    /**
31bfed30e4SGreg Roach     * A unique internal name for this module (based on the installation folder).
32bfed30e4SGreg Roach     *
33bfed30e4SGreg Roach     * @return string
34bfed30e4SGreg Roach     */
35bfed30e4SGreg Roach    abstract public function name(): string;
36bfed30e4SGreg Roach
37bfed30e4SGreg Roach    /**
38bfed30e4SGreg Roach     * How should this module be identified in the control panel, etc.?
39bfed30e4SGreg Roach     *
40bfed30e4SGreg Roach     * @return string
41bfed30e4SGreg Roach     */
42bfed30e4SGreg Roach    abstract public function title(): string;
43bfed30e4SGreg Roach
44bfed30e4SGreg Roach    /**
45377a2979SGreg Roach     * A menu item for this chart for an individual box in a chart.
46377a2979SGreg Roach     *
47377a2979SGreg Roach     * @param Individual $individual
48377a2979SGreg Roach     *
49377a2979SGreg Roach     * @return Menu|null
50377a2979SGreg Roach     */
51*1ff45046SGreg Roach    public function chartBoxMenu(Individual $individual): Menu|null
52377a2979SGreg Roach    {
53377a2979SGreg Roach        return null;
54377a2979SGreg Roach    }
55377a2979SGreg Roach
56377a2979SGreg Roach    /**
57e6562982SGreg Roach     * A main menu item for this chart.
5849a243cbSGreg Roach     *
5949a243cbSGreg Roach     * @param Individual $individual
6049a243cbSGreg Roach     *
61e6562982SGreg Roach     * @return Menu
6249a243cbSGreg Roach     */
6349528f2bSGreg Roach    public function chartMenu(Individual $individual): Menu
64e6562982SGreg Roach    {
65e6562982SGreg Roach        return new Menu(
66e6562982SGreg Roach            $this->title(),
67e6562982SGreg Roach            $this->chartUrl($individual),
68377a2979SGreg Roach            $this->chartMenuClass(),
69e6562982SGreg Roach            $this->chartUrlAttributes()
70e6562982SGreg Roach        );
71e6562982SGreg Roach    }
72e6562982SGreg Roach
73e6562982SGreg Roach    /**
74377a2979SGreg Roach     * CSS class for the menu.
75e6562982SGreg Roach     *
76377a2979SGreg Roach     * @return string
77e6562982SGreg Roach     */
78377a2979SGreg Roach    public function chartMenuClass(): string
7949a243cbSGreg Roach    {
80377a2979SGreg Roach        return '';
8149a243cbSGreg Roach    }
8249a243cbSGreg Roach
8349a243cbSGreg Roach    /**
84e6562982SGreg Roach     * The title for a specific instance of this chart.
8549a243cbSGreg Roach     *
8649a243cbSGreg Roach     * @param Individual $individual
8749a243cbSGreg Roach     *
88e6562982SGreg Roach     * @return string
8949a243cbSGreg Roach     */
9049528f2bSGreg Roach    public function chartTitle(Individual $individual): string
9149a243cbSGreg Roach    {
92e6562982SGreg Roach        return $this->title();
93e6562982SGreg Roach    }
94e6562982SGreg Roach
95e6562982SGreg Roach    /**
96e539f5c6SGreg Roach     * The URL for a page showing chart options.
97e6562982SGreg Roach     *
98e6562982SGreg Roach     * @param Individual                                $individual
9976d39c55SGreg Roach     * @param array<bool|int|string|array<string>|null> $parameters
100e6562982SGreg Roach     *
101e6562982SGreg Roach     * @return string
102e6562982SGreg Roach     */
103e6562982SGreg Roach    public function chartUrl(Individual $individual, array $parameters = []): string
104e6562982SGreg Roach    {
105e539f5c6SGreg Roach        return route('module', [
10626684e68SGreg Roach            'module' => $this->name(),
107e539f5c6SGreg Roach            'action' => 'Chart',
108e539f5c6SGreg Roach            'xref'   => $individual->xref(),
109d72b284aSGreg Roach            'tree'   => $individual->tree()->name(),
110e539f5c6SGreg Roach        ] + $parameters);
111e6562982SGreg Roach    }
112e6562982SGreg Roach
113e6562982SGreg Roach    /**
114e6562982SGreg Roach     * Attributes for the URL.
115e6562982SGreg Roach     *
11624f2a3afSGreg Roach     * @return array<string>
117e6562982SGreg Roach     */
118e6562982SGreg Roach    public function chartUrlAttributes(): array
119e6562982SGreg Roach    {
120e6562982SGreg Roach        return ['rel' => 'nofollow'];
121e6562982SGreg Roach    }
12249a243cbSGreg Roach}
123