xref: /webtrees/app/Module/ModuleListTrait.php (revision e284d69fc9deb04360ff30d06caba590fe7cecbf)
167992b6aSRichard Cissee<?php
267992b6aSRichard Cissee/**
367992b6aSRichard Cissee * webtrees: online genealogy
467992b6aSRichard Cissee * Copyright (C) 2019 webtrees development team
567992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify
667992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by
767992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or
867992b6aSRichard Cissee * (at your option) any later version.
967992b6aSRichard Cissee * This program is distributed in the hope that it will be useful,
1067992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of
1167992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1267992b6aSRichard Cissee * GNU General Public License for more details.
1367992b6aSRichard Cissee * You should have received a copy of the GNU General Public License
1467992b6aSRichard Cissee * along with this program. If not, see <http://www.gnu.org/licenses/>.
1567992b6aSRichard Cissee */
1667992b6aSRichard Cisseedeclare(strict_types=1);
1767992b6aSRichard Cissee
1867992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module;
1967992b6aSRichard Cissee
2067992b6aSRichard Cisseeuse Fisharebest\Webtrees\Menu;
2167992b6aSRichard Cisseeuse Fisharebest\Webtrees\Tree;
2267992b6aSRichard Cissee
2367992b6aSRichard Cissee/**
2467992b6aSRichard Cissee * Trait ModuleListTrait - default implementation of ModuleListInterface
2567992b6aSRichard Cissee */
2667992b6aSRichard Cisseetrait ModuleListTrait
2767992b6aSRichard Cissee{
2867992b6aSRichard Cissee    /**
29*e284d69fSGreg Roach     * @return string
30*e284d69fSGreg Roach     */
31*e284d69fSGreg Roach    abstract public function name(): string;
32*e284d69fSGreg Roach
33*e284d69fSGreg Roach    /**
34*e284d69fSGreg Roach     * @return string
35*e284d69fSGreg Roach     */
36*e284d69fSGreg Roach    abstract public function title(): string;
37*e284d69fSGreg Roach
38*e284d69fSGreg Roach    /**
3967992b6aSRichard Cissee     * A main menu item for this list, or null if the list is empty.
4067992b6aSRichard Cissee     *
4167992b6aSRichard Cissee     * @param Tree $tree
4267992b6aSRichard Cissee     *
4367992b6aSRichard Cissee     * @return Menu|null
4467992b6aSRichard Cissee     */
4567992b6aSRichard Cissee    public function listMenu(Tree $tree): ?Menu
4667992b6aSRichard Cissee    {
4767992b6aSRichard Cissee        if ($this->listIsEmpty($tree)) {
4867992b6aSRichard Cissee            return null;
4967992b6aSRichard Cissee        }
5067992b6aSRichard Cissee
5167992b6aSRichard Cissee        return new Menu(
5255f111b1SRichard Cissée            $this->listTitle(),
5367992b6aSRichard Cissee            $this->listUrl($tree),
5467992b6aSRichard Cissee            $this->listMenuClass(),
5567992b6aSRichard Cissee            $this->listUrlAttributes()
5667992b6aSRichard Cissee        );
5767992b6aSRichard Cissee    }
5867992b6aSRichard Cissee
5967992b6aSRichard Cissee    /**
6067992b6aSRichard Cissee     * CSS class for the menu.
6167992b6aSRichard Cissee     *
6267992b6aSRichard Cissee     * @return string
6367992b6aSRichard Cissee     */
6467992b6aSRichard Cissee    public function listMenuClass(): string
6567992b6aSRichard Cissee    {
6667992b6aSRichard Cissee        return '';
6767992b6aSRichard Cissee    }
6867992b6aSRichard Cissee
6967992b6aSRichard Cissee    /**
7067992b6aSRichard Cissee     * The title for a specific instance of this list.
7167992b6aSRichard Cissee     *
7267992b6aSRichard Cissee     * @return string
7367992b6aSRichard Cissee     */
7467992b6aSRichard Cissee    public function listTitle(): string
7567992b6aSRichard Cissee    {
7667992b6aSRichard Cissee        return $this->title();
7767992b6aSRichard Cissee    }
7867992b6aSRichard Cissee
7967992b6aSRichard Cissee    /**
8067992b6aSRichard Cissee     * The URL for a page showing list options.
8167992b6aSRichard Cissee     *
8267992b6aSRichard Cissee     * @param Tree       $tree
8367992b6aSRichard Cissee     * @param string[]   $parameters
8467992b6aSRichard Cissee     *
8567992b6aSRichard Cissee     * @return string
8667992b6aSRichard Cissee     */
8767992b6aSRichard Cissee    public function listUrl(Tree $tree, array $parameters = []): string
8867992b6aSRichard Cissee    {
8967992b6aSRichard Cissee        return route('module', [
9067992b6aSRichard Cissee                'module' => $this->name(),
9167992b6aSRichard Cissee                'action' => 'List',
9267992b6aSRichard Cissee                'ged'    => $tree->name(),
9367992b6aSRichard Cissee        ] + $parameters);
9467992b6aSRichard Cissee    }
9567992b6aSRichard Cissee
9667992b6aSRichard Cissee    /**
9767992b6aSRichard Cissee     * Attributes for the URL.
9867992b6aSRichard Cissee     *
9967992b6aSRichard Cissee     * @return string[]
10067992b6aSRichard Cissee     */
10167992b6aSRichard Cissee    public function listUrlAttributes(): array
10267992b6aSRichard Cissee    {
10367992b6aSRichard Cissee        return ['rel' => 'nofollow'];
10467992b6aSRichard Cissee    }
10567992b6aSRichard Cissee
1064db4b4a9SGreg Roach    /**
1074db4b4a9SGreg Roach     * @param Tree $tree
1084db4b4a9SGreg Roach     *
1094db4b4a9SGreg Roach     * @return bool
1104db4b4a9SGreg Roach     */
11167992b6aSRichard Cissee    public function listIsEmpty(Tree $tree): bool
11267992b6aSRichard Cissee    {
11367992b6aSRichard Cissee        return false;
11467992b6aSRichard Cissee    }
11567992b6aSRichard Cissee}
116