xref: /webtrees/app/Module/ModuleChartTrait.php (revision 5227b2029ea60eb92ec9219a6a8a7998ccaebdbc)
149a243cbSGreg Roach<?php
249a243cbSGreg Roach/**
349a243cbSGreg Roach * webtrees: online genealogy
449a243cbSGreg Roach * Copyright (C) 2019 webtrees development team
549a243cbSGreg Roach * This program is free software: you can redistribute it and/or modify
649a243cbSGreg Roach * it under the terms of the GNU General Public License as published by
749a243cbSGreg Roach * the Free Software Foundation, either version 3 of the License, or
849a243cbSGreg Roach * (at your option) any later version.
949a243cbSGreg Roach * This program is distributed in the hope that it will be useful,
1049a243cbSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1149a243cbSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1249a243cbSGreg Roach * GNU General Public License for more details.
1349a243cbSGreg Roach * You should have received a copy of the GNU General Public License
1449a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1549a243cbSGreg Roach */
1649a243cbSGreg Roachdeclare(strict_types=1);
1749a243cbSGreg Roach
1849a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module;
1949a243cbSGreg Roach
2049a243cbSGreg Roachuse Fisharebest\Webtrees\Individual;
2149a243cbSGreg Roachuse Fisharebest\Webtrees\Menu;
2249a243cbSGreg Roach
2349a243cbSGreg Roach/**
2449a243cbSGreg Roach * Trait ModuleChartTrait - default implementation of ModuleChartInterface
2549a243cbSGreg Roach */
2649a243cbSGreg Roachtrait ModuleChartTrait
2749a243cbSGreg Roach{
2849a243cbSGreg Roach    /**
29*5227b202SGreg Roach     * @return string
30*5227b202SGreg Roach     */
31*5227b202SGreg Roach    abstract function getName(): string;
32*5227b202SGreg Roach
33*5227b202SGreg Roach    /**
34e6562982SGreg Roach     * A main menu item for this chart.
3549a243cbSGreg Roach     *
3649a243cbSGreg Roach     * @param Individual $individual
3749a243cbSGreg Roach     *
38e6562982SGreg Roach     * @return Menu
3949a243cbSGreg Roach     */
40e6562982SGreg Roach    public function chartMenu(Individual $individual): Menu
41e6562982SGreg Roach    {
42e6562982SGreg Roach        return new Menu(
43e6562982SGreg Roach            $this->title(),
44e6562982SGreg Roach            $this->chartUrl($individual),
45e6562982SGreg Roach            $this->chartUrlClasss(),
46e6562982SGreg Roach            $this->chartUrlAttributes()
47e6562982SGreg Roach        );
48e6562982SGreg Roach    }
49e6562982SGreg Roach
50e6562982SGreg Roach    /**
51e6562982SGreg Roach     * A menu item for this chart for an individual box in a chart.
52e6562982SGreg Roach     *
53e6562982SGreg Roach     * @param Individual $individual
54e6562982SGreg Roach     *
55e6562982SGreg Roach     * @return Menu|null
56e6562982SGreg Roach     */
57e6562982SGreg Roach    public function chartMenuIndividual(Individual $individual): ?Menu
5849a243cbSGreg Roach    {
5949a243cbSGreg Roach        return null;
6049a243cbSGreg Roach    }
6149a243cbSGreg Roach
6249a243cbSGreg Roach    /**
63e6562982SGreg Roach     * The title for a specific instance of this chart.
6449a243cbSGreg Roach     *
6549a243cbSGreg Roach     * @param Individual $individual
6649a243cbSGreg Roach     *
67e6562982SGreg Roach     * @return string
6849a243cbSGreg Roach     */
69e6562982SGreg Roach    public function chartTitle(Individual $individual): string
7049a243cbSGreg Roach    {
71e6562982SGreg Roach        return $this->title();
72e6562982SGreg Roach    }
73e6562982SGreg Roach
74e6562982SGreg Roach    /**
75e539f5c6SGreg Roach     * The URL for a page showing chart options.
76e6562982SGreg Roach     *
77e6562982SGreg Roach     * @param Individual $individual
78e6562982SGreg Roach     * @param string[]   $parameters
79e6562982SGreg Roach     *
80e6562982SGreg Roach     * @return string
81e6562982SGreg Roach     */
82e6562982SGreg Roach    public function chartUrl(Individual $individual, array $parameters = []): string
83e6562982SGreg Roach    {
84e539f5c6SGreg Roach        return route('module', [
85e539f5c6SGreg Roach            'module' => $this->getName(),
86e539f5c6SGreg Roach            'action' => 'Chart',
87e539f5c6SGreg Roach            'xref'   => $individual->xref(),
88e539f5c6SGreg Roach            'ged'    => $individual->tree()->name(),
89e539f5c6SGreg Roach        ] + $parameters);
90e6562982SGreg Roach    }
91e6562982SGreg Roach
92e6562982SGreg Roach    /**
93e6562982SGreg Roach     * Attributes for the URL.
94e6562982SGreg Roach     *
95e6562982SGreg Roach     * @return string[]
96e6562982SGreg Roach     */
97e6562982SGreg Roach    public function chartUrlAttributes(): array
98e6562982SGreg Roach    {
99e6562982SGreg Roach        return ['rel' => 'nofollow'];
100e6562982SGreg Roach    }
101e6562982SGreg Roach
102e6562982SGreg Roach    /**
103e6562982SGreg Roach     * CSS class for the URL.
104e6562982SGreg Roach     *
105e6562982SGreg Roach     * @return string
106e6562982SGreg Roach     */
107e6562982SGreg Roach    public function chartUrlClasss(): string
108e6562982SGreg Roach    {
109e6562982SGreg Roach        return '';
11049a243cbSGreg Roach    }
11149a243cbSGreg Roach}
112