1a25f0a04SGreg Roach<?php 23976b470SGreg Roach 3a25f0a04SGreg Roach/** 4a25f0a04SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6a25f0a04SGreg Roach * This program is free software: you can redistribute it and/or modify 7a25f0a04SGreg Roach * it under the terms of the GNU General Public License as published by 8a25f0a04SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9a25f0a04SGreg Roach * (at your option) any later version. 10a25f0a04SGreg Roach * This program is distributed in the hope that it will be useful, 11a25f0a04SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12a25f0a04SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13a25f0a04SGreg Roach * GNU General Public License for more details. 14a25f0a04SGreg 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/>. 16a25f0a04SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 19e7f56f2aSGreg Roach 2076692c8bSGreg Roachnamespace Fisharebest\Webtrees; 21a25f0a04SGreg Roach 22a25f0a04SGreg Roach/** 2376692c8bSGreg Roach * System for generating menus. 24a25f0a04SGreg Roach */ 25c1010edaSGreg Roachclass Menu 26c1010edaSGreg Roach{ 27fceda430SGreg Roach /** @var string The text to be displayed in the menu */ 28a25f0a04SGreg Roach private $label; 29a25f0a04SGreg Roach 30a25f0a04SGreg Roach /** @var string The target URL or href */ 31a25f0a04SGreg Roach private $link; 32a25f0a04SGreg Roach 333d0a6fa1SGreg Roach /** @var string The CSS class used to style this menu item */ 343d0a6fa1SGreg Roach private $class; 35a25f0a04SGreg Roach 36*09482a55SGreg Roach /** @var array<string> A list of optional HTML attributes, such as onclick or data-xxx */ 373cf92ae2SGreg Roach private $attrs; 38a25f0a04SGreg Roach 39*09482a55SGreg Roach /** @var array<Menu> An optional list of sub-menus. */ 40a25f0a04SGreg Roach private $submenus; 41a25f0a04SGreg Roach 42a25f0a04SGreg Roach /** 43a25f0a04SGreg Roach * Constructor for the menu class 44a25f0a04SGreg Roach * 45a25f0a04SGreg Roach * @param string $label The label for the menu item 46a25f0a04SGreg Roach * @param string $link The target URL 473cf92ae2SGreg Roach * @param string $class A CSS class 48*09482a55SGreg Roach * @param array<string> $attrs Optional attributes, such as onclick or data-xxx 49*09482a55SGreg Roach * @param array<Menu> $submenus Any submenus 50a25f0a04SGreg Roach */ 5124f2a3afSGreg Roach public function __construct( 5224f2a3afSGreg Roach string $label, 5324f2a3afSGreg Roach string $link = '#', 5424f2a3afSGreg Roach string $class = '', 5524f2a3afSGreg Roach array $attrs = [], 5624f2a3afSGreg Roach array $submenus = [] 5724f2a3afSGreg Roach ) { 58a25f0a04SGreg Roach $this 59a25f0a04SGreg Roach ->setLabel($label) 60a25f0a04SGreg Roach ->setLink($link) 613d0a6fa1SGreg Roach ->setClass($class) 623cf92ae2SGreg Roach ->setAttrs($attrs) 63a25f0a04SGreg Roach ->setSubmenus($submenus); 64a25f0a04SGreg Roach } 65a25f0a04SGreg Roach 66a25f0a04SGreg Roach /** 673cf92ae2SGreg Roach * Get the optional attributes. 683cf92ae2SGreg Roach * 6924f2a3afSGreg Roach * @return array<string> 703cf92ae2SGreg Roach */ 718f53f488SRico Sonntag public function getAttrs(): array 72c1010edaSGreg Roach { 733cf92ae2SGreg Roach return $this->attrs; 743cf92ae2SGreg Roach } 753cf92ae2SGreg Roach 763cf92ae2SGreg Roach /** 773cf92ae2SGreg Roach * Set the optional attributes. 783cf92ae2SGreg Roach * 79*09482a55SGreg Roach * @param array<string> $attrs 803cf92ae2SGreg Roach * 813cf92ae2SGreg Roach * @return $this 823cf92ae2SGreg Roach */ 838f53f488SRico Sonntag public function setAttrs(array $attrs): self 84c1010edaSGreg Roach { 853cf92ae2SGreg Roach $this->attrs = $attrs; 863cf92ae2SGreg Roach 873cf92ae2SGreg Roach return $this; 883cf92ae2SGreg Roach } 893cf92ae2SGreg Roach 903cf92ae2SGreg Roach /** 9176692c8bSGreg Roach * Get the class. 9276692c8bSGreg Roach * 93a25f0a04SGreg Roach * @return string 94a25f0a04SGreg Roach */ 958f53f488SRico Sonntag public function getClass(): string 96c1010edaSGreg Roach { 973d0a6fa1SGreg Roach return $this->class; 98a25f0a04SGreg Roach } 99a25f0a04SGreg Roach 100a25f0a04SGreg Roach /** 10176692c8bSGreg Roach * Set the class. 10276692c8bSGreg Roach * 1033d0a6fa1SGreg Roach * @param string $class 104a25f0a04SGreg Roach * 105a25f0a04SGreg Roach * @return $this 106a25f0a04SGreg Roach */ 10724f2a3afSGreg Roach public function setClass(string $class): self 108c1010edaSGreg Roach { 1093d0a6fa1SGreg Roach $this->class = $class; 110a25f0a04SGreg Roach 111a25f0a04SGreg Roach return $this; 112a25f0a04SGreg Roach } 113a25f0a04SGreg Roach 114a25f0a04SGreg Roach /** 11576692c8bSGreg Roach * Get the label. 11676692c8bSGreg Roach * 117a25f0a04SGreg Roach * @return string 118a25f0a04SGreg Roach */ 1198f53f488SRico Sonntag public function getLabel(): string 120c1010edaSGreg Roach { 121a25f0a04SGreg Roach return $this->label; 122a25f0a04SGreg Roach } 123a25f0a04SGreg Roach 124a25f0a04SGreg Roach /** 12576692c8bSGreg Roach * Set the label. 12676692c8bSGreg Roach * 127a25f0a04SGreg Roach * @param string $label 128a25f0a04SGreg Roach * 129a25f0a04SGreg Roach * @return $this 130a25f0a04SGreg Roach */ 13124f2a3afSGreg Roach public function setLabel(string $label): self 132c1010edaSGreg Roach { 133a25f0a04SGreg Roach $this->label = $label; 134a25f0a04SGreg Roach 135a25f0a04SGreg Roach return $this; 136a25f0a04SGreg Roach } 137a25f0a04SGreg Roach 138a25f0a04SGreg Roach /** 13976692c8bSGreg Roach * Get the link. 1403cf92ae2SGreg Roach * 141a25f0a04SGreg Roach * @return string 142a25f0a04SGreg Roach */ 1438f53f488SRico Sonntag public function getLink(): string 144c1010edaSGreg Roach { 145a25f0a04SGreg Roach return $this->link; 146a25f0a04SGreg Roach } 147a25f0a04SGreg Roach 148a25f0a04SGreg Roach /** 14976692c8bSGreg Roach * Set the link. 15076692c8bSGreg Roach * 151a25f0a04SGreg Roach * @param string $link 152a25f0a04SGreg Roach * 153a25f0a04SGreg Roach * @return $this 154a25f0a04SGreg Roach */ 15524f2a3afSGreg Roach public function setLink(string $link): self 156c1010edaSGreg Roach { 157a25f0a04SGreg Roach $this->link = $link; 158a25f0a04SGreg Roach 159a25f0a04SGreg Roach return $this; 160a25f0a04SGreg Roach } 161a25f0a04SGreg Roach 162a25f0a04SGreg Roach /** 163a25f0a04SGreg Roach * Add a submenu to this menu 164a25f0a04SGreg Roach * 165ecb5b5e9SGreg Roach * @param Menu $menu 166ecb5b5e9SGreg Roach * 167ecb5b5e9SGreg Roach * @return $this 168a25f0a04SGreg Roach */ 16924f2a3afSGreg Roach public function addSubmenu(Menu $menu): self 170c1010edaSGreg Roach { 171a25f0a04SGreg Roach $this->submenus[] = $menu; 172ecb5b5e9SGreg Roach 173ecb5b5e9SGreg Roach return $this; 174a25f0a04SGreg Roach } 175a25f0a04SGreg Roach 176a25f0a04SGreg Roach /** 17776692c8bSGreg Roach * Get the sub-menus. 17876692c8bSGreg Roach * 179*09482a55SGreg Roach * @return array<Menu> 180a25f0a04SGreg Roach */ 1818f53f488SRico Sonntag public function getSubmenus(): array 182c1010edaSGreg Roach { 183a25f0a04SGreg Roach return $this->submenus; 184a25f0a04SGreg Roach } 185a25f0a04SGreg Roach 186a25f0a04SGreg Roach /** 18776692c8bSGreg Roach * Set the sub-menus. 18876692c8bSGreg Roach * 189*09482a55SGreg Roach * @param array<Menu> $submenus 190a25f0a04SGreg Roach * 191a25f0a04SGreg Roach * @return $this 192a25f0a04SGreg Roach */ 1938f53f488SRico Sonntag public function setSubmenus(array $submenus): self 194c1010edaSGreg Roach { 195a25f0a04SGreg Roach $this->submenus = $submenus; 196a25f0a04SGreg Roach 197a25f0a04SGreg Roach return $this; 198a25f0a04SGreg Roach } 199a25f0a04SGreg Roach} 200