xref: /webtrees/app/Module/ModuleChartTrait.php (revision 26684e686fb5ab50ecb57e7e6c6a0a55852d2203)
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    /**
295227b202SGreg Roach     * @return string
305227b202SGreg Roach     */
31*26684e68SGreg Roach    abstract public function name(): string;
325227b202SGreg Roach
335227b202SGreg Roach    /**
34377a2979SGreg Roach     * A menu item for this chart for an individual box in a chart.
35377a2979SGreg Roach     *
36377a2979SGreg Roach     * @param Individual $individual
37377a2979SGreg Roach     *
38377a2979SGreg Roach     * @return Menu|null
39377a2979SGreg Roach     */
40377a2979SGreg Roach    public function chartBoxMenu(Individual $individual): ?Menu
41377a2979SGreg Roach    {
42377a2979SGreg Roach        return null;
43377a2979SGreg Roach    }
44377a2979SGreg Roach
45377a2979SGreg Roach    /**
46e6562982SGreg Roach     * A main menu item for this chart.
4749a243cbSGreg Roach     *
4849a243cbSGreg Roach     * @param Individual $individual
4949a243cbSGreg Roach     *
50e6562982SGreg Roach     * @return Menu
5149a243cbSGreg Roach     */
52e6562982SGreg Roach    public function chartMenu(Individual $individual): Menu
53e6562982SGreg Roach    {
54e6562982SGreg Roach        return new Menu(
55e6562982SGreg Roach            $this->title(),
56e6562982SGreg Roach            $this->chartUrl($individual),
57377a2979SGreg Roach            $this->chartMenuClass(),
58e6562982SGreg Roach            $this->chartUrlAttributes()
59e6562982SGreg Roach        );
60e6562982SGreg Roach    }
61e6562982SGreg Roach
62e6562982SGreg Roach    /**
63377a2979SGreg Roach     * CSS class for the menu.
64e6562982SGreg Roach     *
65377a2979SGreg Roach     * @return string
66e6562982SGreg Roach     */
67377a2979SGreg Roach    public function chartMenuClass(): string
6849a243cbSGreg Roach    {
69377a2979SGreg Roach        return '';
7049a243cbSGreg Roach    }
7149a243cbSGreg Roach
7249a243cbSGreg Roach    /**
73e6562982SGreg Roach     * The title for a specific instance of this chart.
7449a243cbSGreg Roach     *
7549a243cbSGreg Roach     * @param Individual $individual
7649a243cbSGreg Roach     *
77e6562982SGreg Roach     * @return string
7849a243cbSGreg Roach     */
79e6562982SGreg Roach    public function chartTitle(Individual $individual): string
8049a243cbSGreg Roach    {
81e6562982SGreg Roach        return $this->title();
82e6562982SGreg Roach    }
83e6562982SGreg Roach
84e6562982SGreg Roach    /**
85e539f5c6SGreg Roach     * The URL for a page showing chart options.
86e6562982SGreg Roach     *
87e6562982SGreg Roach     * @param Individual $individual
88e6562982SGreg Roach     * @param string[]   $parameters
89e6562982SGreg Roach     *
90e6562982SGreg Roach     * @return string
91e6562982SGreg Roach     */
92e6562982SGreg Roach    public function chartUrl(Individual $individual, array $parameters = []): string
93e6562982SGreg Roach    {
94e539f5c6SGreg Roach        return route('module', [
95*26684e68SGreg Roach                'module' => $this->name(),
96e539f5c6SGreg Roach                'action' => 'Chart',
97e539f5c6SGreg Roach                'xref'   => $individual->xref(),
98e539f5c6SGreg Roach                'ged'    => $individual->tree()->name(),
99e539f5c6SGreg Roach        ] + $parameters);
100e6562982SGreg Roach    }
101e6562982SGreg Roach
102e6562982SGreg Roach    /**
103e6562982SGreg Roach     * Attributes for the URL.
104e6562982SGreg Roach     *
105e6562982SGreg Roach     * @return string[]
106e6562982SGreg Roach     */
107e6562982SGreg Roach    public function chartUrlAttributes(): array
108e6562982SGreg Roach    {
109e6562982SGreg Roach        return ['rel' => 'nofollow'];
110e6562982SGreg Roach    }
11149a243cbSGreg Roach}
112