149a243cbSGreg Roach<?php 2*3976b470SGreg Roach 349a243cbSGreg Roach/** 449a243cbSGreg Roach * webtrees: online genealogy 549a243cbSGreg Roach * Copyright (C) 2019 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 1549a243cbSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1649a243cbSGreg Roach */ 1749a243cbSGreg Roachdeclare(strict_types=1); 1849a243cbSGreg Roach 1949a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module; 2049a243cbSGreg Roach 21ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth; 22ade503dfSGreg Roachuse Fisharebest\Webtrees\Fact; 23ade503dfSGreg Roachuse Fisharebest\Webtrees\Gedcom; 24ade503dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag; 25ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N; 26ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual; 27ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu; 284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 29ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree; 30f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees; 316ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 32*3976b470SGreg Roach 336ccdf4f0SGreg Roachuse function app; 34ade503dfSGreg Roach 3549a243cbSGreg Roach/** 3649a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface 3749a243cbSGreg Roach */ 3849a243cbSGreg Roachtrait ModuleThemeTrait 3949a243cbSGreg Roach{ 40ade503dfSGreg Roach /** 413d8b2a8eSGreg Roach * A sentence describing what this module does. 423d8b2a8eSGreg Roach * 433d8b2a8eSGreg Roach * @return string 443d8b2a8eSGreg Roach */ 453d8b2a8eSGreg Roach public function description(): string 463d8b2a8eSGreg Roach { 473d8b2a8eSGreg Roach return I18N::translate('Theme') . ' — ' . $this->title(); 483d8b2a8eSGreg Roach } 493d8b2a8eSGreg Roach 503d8b2a8eSGreg Roach /** 51ade503dfSGreg Roach * Display an icon for this fact. 52ade503dfSGreg Roach * 53e837ff07SGreg Roach * @TODO use CSS for this 54e837ff07SGreg Roach * 55ade503dfSGreg Roach * @param Fact $fact 56ade503dfSGreg Roach * 57ade503dfSGreg Roach * @return string 58ade503dfSGreg Roach */ 59ade503dfSGreg Roach public function icon(Fact $fact): string 60ade503dfSGreg Roach { 61e837ff07SGreg Roach $asset = 'public/css/' . $this->name() . '/images/facts/' . $fact->getTag() . '.png'; 62f397d0fdSGreg Roach if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) { 63e837ff07SGreg Roach return '<img src="' . e(asset($asset)) . '" title="' . GedcomTag::getLabel($fact->getTag()) . '">'; 64ade503dfSGreg Roach } 65ade503dfSGreg Roach 66ade503dfSGreg Roach // Spacer image - for alignment - until we move to a sprite. 67e837ff07SGreg Roach $asset = 'public/css/' . $this->name() . '/images/facts/NULL.png'; 68f397d0fdSGreg Roach if (file_exists(Webtrees::ROOT_DIR . 'public' . $asset)) { 69e837ff07SGreg Roach return '<img src="' . e(asset($asset)) . '">'; 70ade503dfSGreg Roach } 71ade503dfSGreg Roach 72ade503dfSGreg Roach return ''; 73ade503dfSGreg Roach } 74ade503dfSGreg Roach 75ade503dfSGreg Roach /** 76ade503dfSGreg Roach * Generate the facts, for display in charts. 77ade503dfSGreg Roach * 78ade503dfSGreg Roach * @param Individual $individual 79ade503dfSGreg Roach * 80ade503dfSGreg Roach * @return string 81ade503dfSGreg Roach */ 82ade503dfSGreg Roach public function individualBoxFacts(Individual $individual): string 83ade503dfSGreg Roach { 84ade503dfSGreg Roach $html = ''; 85ade503dfSGreg Roach 86ade503dfSGreg Roach $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY); 87ade503dfSGreg Roach // Show BIRT or equivalent event 88ade503dfSGreg Roach foreach (Gedcom::BIRTH_EVENTS as $birttag) { 8922d65e5aSGreg Roach if (!in_array($birttag, $opt_tags, true)) { 90820b62dfSGreg Roach $event = $individual->facts([$birttag])->first(); 91820b62dfSGreg Roach if ($event instanceof Fact) { 92ade503dfSGreg Roach $html .= $event->summary(); 93ade503dfSGreg Roach break; 94ade503dfSGreg Roach } 95ade503dfSGreg Roach } 96ade503dfSGreg Roach } 97ade503dfSGreg Roach // Show optional events (before death) 98ade503dfSGreg Roach foreach ($opt_tags as $key => $tag) { 9922d65e5aSGreg Roach if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) { 100820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 101820b62dfSGreg Roach if ($event instanceof Fact) { 102ade503dfSGreg Roach $html .= $event->summary(); 103ade503dfSGreg Roach unset($opt_tags[$key]); 104ade503dfSGreg Roach } 105ade503dfSGreg Roach } 106ade503dfSGreg Roach } 107ade503dfSGreg Roach // Show DEAT or equivalent event 108ade503dfSGreg Roach foreach (Gedcom::DEATH_EVENTS as $deattag) { 109820b62dfSGreg Roach $event = $individual->facts([$deattag])->first(); 110820b62dfSGreg Roach if ($event instanceof Fact) { 111ade503dfSGreg Roach $html .= $event->summary(); 11222d65e5aSGreg Roach if (in_array($deattag, $opt_tags, true)) { 11322d65e5aSGreg Roach unset($opt_tags[array_search($deattag, $opt_tags, true)]); 114ade503dfSGreg Roach } 115ade503dfSGreg Roach break; 116ade503dfSGreg Roach } 117ade503dfSGreg Roach } 118ade503dfSGreg Roach // Show remaining optional events (after death) 119ade503dfSGreg Roach foreach ($opt_tags as $tag) { 120820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 121820b62dfSGreg Roach if ($event instanceof Fact) { 122ade503dfSGreg Roach $html .= $event->summary(); 123ade503dfSGreg Roach } 124ade503dfSGreg Roach } 125ade503dfSGreg Roach 126ade503dfSGreg Roach return $html; 127ade503dfSGreg Roach } 128ade503dfSGreg Roach 129ade503dfSGreg Roach /** 130ade503dfSGreg Roach * Links, to show in chart boxes; 131ade503dfSGreg Roach * 132ade503dfSGreg Roach * @param Individual $individual 133ade503dfSGreg Roach * 134ade503dfSGreg Roach * @return Menu[] 135ade503dfSGreg Roach */ 136ade503dfSGreg Roach public function individualBoxMenu(Individual $individual): array 137ade503dfSGreg Roach { 138ade503dfSGreg Roach $menus = array_merge( 139ade503dfSGreg Roach $this->individualBoxMenuCharts($individual), 140ade503dfSGreg Roach $this->individualBoxMenuFamilyLinks($individual) 141ade503dfSGreg Roach ); 142ade503dfSGreg Roach 143ade503dfSGreg Roach return $menus; 144ade503dfSGreg Roach } 145ade503dfSGreg Roach 146ade503dfSGreg Roach /** 147ade503dfSGreg Roach * Chart links, to show in chart boxes; 148ade503dfSGreg Roach * 149ade503dfSGreg Roach * @param Individual $individual 150ade503dfSGreg Roach * 151ade503dfSGreg Roach * @return Menu[] 152ade503dfSGreg Roach */ 153ade503dfSGreg Roach public function individualBoxMenuCharts(Individual $individual): array 154ade503dfSGreg Roach { 155ade503dfSGreg Roach $menus = []; 156f39638cfSGreg Roach foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) { 157ade503dfSGreg Roach $menu = $chart->chartBoxMenu($individual); 158ade503dfSGreg Roach if ($menu) { 159ade503dfSGreg Roach $menus[] = $menu; 160ade503dfSGreg Roach } 161ade503dfSGreg Roach } 162ade503dfSGreg Roach 1630b93976aSGreg Roach usort($menus, static function (Menu $x, Menu $y): int { 164ade503dfSGreg Roach return I18N::strcasecmp($x->getLabel(), $y->getLabel()); 165ade503dfSGreg Roach }); 166ade503dfSGreg Roach 167ade503dfSGreg Roach return $menus; 168ade503dfSGreg Roach } 169ade503dfSGreg Roach 170ade503dfSGreg Roach /** 171ade503dfSGreg Roach * Family links, to show in chart boxes. 172ade503dfSGreg Roach * 173ade503dfSGreg Roach * @param Individual $individual 174ade503dfSGreg Roach * 175ade503dfSGreg Roach * @return Menu[] 176ade503dfSGreg Roach */ 177ade503dfSGreg Roach public function individualBoxMenuFamilyLinks(Individual $individual): array 178ade503dfSGreg Roach { 179ade503dfSGreg Roach $menus = []; 180ade503dfSGreg Roach 18139ca88baSGreg Roach foreach ($individual->spouseFamilies() as $family) { 182ade503dfSGreg Roach $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()); 18339ca88baSGreg Roach $spouse = $family->spouse($individual); 184ade503dfSGreg Roach if ($spouse && $spouse->canShowName()) { 18539ca88baSGreg Roach $menus[] = new Menu($spouse->fullName(), $spouse->url()); 186ade503dfSGreg Roach } 18739ca88baSGreg Roach foreach ($family->children() as $child) { 188ade503dfSGreg Roach if ($child->canShowName()) { 18939ca88baSGreg Roach $menus[] = new Menu($child->fullName(), $child->url()); 190ade503dfSGreg Roach } 191ade503dfSGreg Roach } 192ade503dfSGreg Roach } 193ade503dfSGreg Roach 194ade503dfSGreg Roach return $menus; 195ade503dfSGreg Roach } 196ade503dfSGreg Roach 197ade503dfSGreg Roach /** 198ade503dfSGreg Roach * Generate a menu item to change the blocks on the current (index.php) page. 199ade503dfSGreg Roach * 2000c8c69d4SGreg Roach * @param Tree $tree 2010c8c69d4SGreg Roach * 202ade503dfSGreg Roach * @return Menu|null 203ade503dfSGreg Roach */ 204e364afe4SGreg Roach public function menuChangeBlocks(Tree $tree): ?Menu 205ade503dfSGreg Roach { 206eb235819SGreg Roach /** @var ServerRequestInterface $request */ 2076ccdf4f0SGreg Roach $request = app(ServerRequestInterface::class); 208e6bcfa02SGreg Roach 209eb235819SGreg Roach $route = $request->getQueryParams()['route'] ?? ''; 210eb235819SGreg Roach 211eb235819SGreg Roach if (Auth::check() && $route === 'user-page') { 2120c8c69d4SGreg Roach return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks'); 213ade503dfSGreg Roach } 214ade503dfSGreg Roach 215eb235819SGreg Roach if (Auth::isManager($tree) && $route === 'tree-page') { 2160c8c69d4SGreg Roach return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['ged' => $tree->name()]), 'menu-change-blocks'); 217ade503dfSGreg Roach } 218ade503dfSGreg Roach 219ade503dfSGreg Roach return null; 220ade503dfSGreg Roach } 221ade503dfSGreg Roach 222ade503dfSGreg Roach /** 223ade503dfSGreg Roach * Generate a menu item for the control panel. 224ade503dfSGreg Roach * 2250c8c69d4SGreg Roach * @param Tree $tree 2260c8c69d4SGreg Roach * 227ade503dfSGreg Roach * @return Menu|null 228ade503dfSGreg Roach */ 229e364afe4SGreg Roach public function menuControlPanel(Tree $tree): ?Menu 230ade503dfSGreg Roach { 231ade503dfSGreg Roach if (Auth::isAdmin()) { 232ade503dfSGreg Roach return new Menu(I18N::translate('Control panel'), route('admin-control-panel'), 'menu-admin'); 233ade503dfSGreg Roach } 234ade503dfSGreg Roach 2350c8c69d4SGreg Roach if (Auth::isManager($tree)) { 236ade503dfSGreg Roach return new Menu(I18N::translate('Control panel'), route('admin-control-panel-manager'), 'menu-admin'); 237ade503dfSGreg Roach } 238ade503dfSGreg Roach 239ade503dfSGreg Roach return null; 240ade503dfSGreg Roach } 241ade503dfSGreg Roach 242ade503dfSGreg Roach /** 243ade503dfSGreg Roach * A menu to show a list of available languages. 244ade503dfSGreg Roach * 245ade503dfSGreg Roach * @return Menu|null 246ade503dfSGreg Roach */ 247e364afe4SGreg Roach public function menuLanguages(): ?Menu 248ade503dfSGreg Roach { 249ade503dfSGreg Roach $menu = new Menu(I18N::translate('Language'), '#', 'menu-language'); 250ade503dfSGreg Roach 251ade503dfSGreg Roach foreach (I18N::activeLocales() as $locale) { 252ade503dfSGreg Roach $language_tag = $locale->languageTag(); 253ade503dfSGreg Roach $class = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : ''); 254ade503dfSGreg Roach $menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [ 255ade503dfSGreg Roach 'onclick' => 'return false;', 256ade503dfSGreg Roach 'data-language' => $language_tag, 257ade503dfSGreg Roach ])); 258ade503dfSGreg Roach } 259ade503dfSGreg Roach 260ade503dfSGreg Roach if (count($menu->getSubmenus()) > 1) { 261ade503dfSGreg Roach return $menu; 262ade503dfSGreg Roach } 263ade503dfSGreg Roach 264ade503dfSGreg Roach return null; 265ade503dfSGreg Roach } 266ade503dfSGreg Roach 267ade503dfSGreg Roach /** 268ade503dfSGreg Roach * A login menu option (or null if we are already logged in). 269ade503dfSGreg Roach * 270ade503dfSGreg Roach * @return Menu|null 271ade503dfSGreg Roach */ 272e364afe4SGreg Roach public function menuLogin(): ?Menu 273ade503dfSGreg Roach { 274ade503dfSGreg Roach if (Auth::check()) { 275ade503dfSGreg Roach return null; 276ade503dfSGreg Roach } 277ade503dfSGreg Roach 278ade503dfSGreg Roach // Return to this page after login... 279add3fa41SGreg Roach $url = app(ServerRequestInterface::class)->getAttribute('request_uri'); 280ade503dfSGreg Roach 281ade503dfSGreg Roach // ...but switch from the tree-page to the user-page 282ade503dfSGreg Roach $url = str_replace('route=tree-page', 'route=user-page', $url); 283ade503dfSGreg Roach 284ade503dfSGreg Roach return new Menu(I18N::translate('Sign in'), route('login', ['url' => $url]), 'menu-login', ['rel' => 'nofollow']); 285ade503dfSGreg Roach } 286ade503dfSGreg Roach 287ade503dfSGreg Roach /** 288ade503dfSGreg Roach * A logout menu option (or null if we are already logged out). 289ade503dfSGreg Roach * 290ade503dfSGreg Roach * @return Menu|null 291ade503dfSGreg Roach */ 292e364afe4SGreg Roach public function menuLogout(): ?Menu 293ade503dfSGreg Roach { 294ade503dfSGreg Roach if (Auth::check()) { 295ade503dfSGreg Roach return new Menu(I18N::translate('Sign out'), route('logout'), 'menu-logout'); 296ade503dfSGreg Roach } 297ade503dfSGreg Roach 298ade503dfSGreg Roach return null; 299ade503dfSGreg Roach } 300ade503dfSGreg Roach 301ade503dfSGreg Roach /** 302ade503dfSGreg Roach * A link to allow users to edit their account settings. 303ade503dfSGreg Roach * 304ade503dfSGreg Roach * @return Menu|null 305ade503dfSGreg Roach */ 306e364afe4SGreg Roach public function menuMyAccount(): ?Menu 307ade503dfSGreg Roach { 308ade503dfSGreg Roach if (Auth::check()) { 309ade503dfSGreg Roach return new Menu(I18N::translate('My account'), route('my-account')); 310ade503dfSGreg Roach } 311ade503dfSGreg Roach 312ade503dfSGreg Roach return null; 313ade503dfSGreg Roach } 314ade503dfSGreg Roach 315ade503dfSGreg Roach /** 316ade503dfSGreg Roach * A link to the user's individual record (individual.php). 317ade503dfSGreg Roach * 3180c8c69d4SGreg Roach * @param Tree $tree 3190c8c69d4SGreg Roach * 320ade503dfSGreg Roach * @return Menu|null 321ade503dfSGreg Roach */ 322e364afe4SGreg Roach public function menuMyIndividualRecord(Tree $tree): ?Menu 323ade503dfSGreg Roach { 3240c8c69d4SGreg Roach $record = Individual::getInstance($tree->getUserPreference(Auth::user(), 'gedcomid'), $tree); 325ade503dfSGreg Roach 326ade503dfSGreg Roach if ($record) { 327ade503dfSGreg Roach return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord'); 328ade503dfSGreg Roach } 329ade503dfSGreg Roach 330ade503dfSGreg Roach return null; 331ade503dfSGreg Roach } 332ade503dfSGreg Roach 333ade503dfSGreg Roach /** 334ade503dfSGreg Roach * A link to the user's personal home page. 335ade503dfSGreg Roach * 3360c8c69d4SGreg Roach * @param Tree $tree 3370c8c69d4SGreg Roach * 338ade503dfSGreg Roach * @return Menu 339ade503dfSGreg Roach */ 3400c8c69d4SGreg Roach public function menuMyPage(Tree $tree): Menu 341ade503dfSGreg Roach { 3420c8c69d4SGreg Roach return new Menu(I18N::translate('My page'), route('user-page', ['ged' => $tree->name()]), 'menu-mypage'); 343ade503dfSGreg Roach } 344ade503dfSGreg Roach 345ade503dfSGreg Roach /** 346ade503dfSGreg Roach * A menu for the user's personal pages. 347ade503dfSGreg Roach * 3480c8c69d4SGreg Roach * @param Tree|null $tree 3490c8c69d4SGreg Roach * 350ade503dfSGreg Roach * @return Menu|null 351ade503dfSGreg Roach */ 352e364afe4SGreg Roach public function menuMyPages(?Tree $tree): ?Menu 353ade503dfSGreg Roach { 3540c8c69d4SGreg Roach if ($tree instanceof Tree && Auth::id()) { 355ade503dfSGreg Roach return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([ 3560c8c69d4SGreg Roach $this->menuMyPage($tree), 3570c8c69d4SGreg Roach $this->menuMyIndividualRecord($tree), 3580c8c69d4SGreg Roach $this->menuMyPedigree($tree), 359ade503dfSGreg Roach $this->menuMyAccount(), 3600c8c69d4SGreg Roach $this->menuControlPanel($tree), 3610c8c69d4SGreg Roach $this->menuChangeBlocks($tree), 362ade503dfSGreg Roach ])); 363ade503dfSGreg Roach } 364ade503dfSGreg Roach 365ade503dfSGreg Roach return null; 366ade503dfSGreg Roach } 367ade503dfSGreg Roach 368ade503dfSGreg Roach /** 369ade503dfSGreg Roach * A link to the user's individual record. 370ade503dfSGreg Roach * 3710c8c69d4SGreg Roach * @param Tree $tree 3720c8c69d4SGreg Roach * 373ade503dfSGreg Roach * @return Menu|null 374ade503dfSGreg Roach */ 375e364afe4SGreg Roach public function menuMyPedigree(Tree $tree): ?Menu 376ade503dfSGreg Roach { 3770c8c69d4SGreg Roach $gedcomid = $tree->getUserPreference(Auth::user(), 'gedcomid'); 378ade503dfSGreg Roach 3790c8c69d4SGreg Roach $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 3800b5fd0a6SGreg Roach ->filter(static function (ModuleInterface $module): bool { 381ade503dfSGreg Roach return $module instanceof PedigreeChartModule; 382ade503dfSGreg Roach }); 383ade503dfSGreg Roach 384ade503dfSGreg Roach if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) { 385ade503dfSGreg Roach return new Menu( 386ade503dfSGreg Roach I18N::translate('My pedigree'), 387ade503dfSGreg Roach route('pedigree', [ 388ade503dfSGreg Roach 'xref' => $gedcomid, 3890c8c69d4SGreg Roach 'ged' => $tree->name(), 390ade503dfSGreg Roach ]), 391ade503dfSGreg Roach 'menu-mypedigree' 392ade503dfSGreg Roach ); 393ade503dfSGreg Roach } 394ade503dfSGreg Roach 395ade503dfSGreg Roach return null; 396ade503dfSGreg Roach } 397ade503dfSGreg Roach 398ade503dfSGreg Roach /** 399ade503dfSGreg Roach * Create a pending changes menu. 400ade503dfSGreg Roach * 4010c8c69d4SGreg Roach * @param Tree|null $tree 4020c8c69d4SGreg Roach * 403ade503dfSGreg Roach * @return Menu|null 404ade503dfSGreg Roach */ 405e364afe4SGreg Roach public function menuPendingChanges(?Tree $tree): ?Menu 406ade503dfSGreg Roach { 4070c8c69d4SGreg Roach if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) { 408ade503dfSGreg Roach $url = route('show-pending', [ 4090c8c69d4SGreg Roach 'ged' => $tree->name(), 410cf8c0692SGreg Roach 'url' => (string) app(ServerRequestInterface::class)->getUri(), 411ade503dfSGreg Roach ]); 412ade503dfSGreg Roach 413ade503dfSGreg Roach return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending'); 414ade503dfSGreg Roach } 415ade503dfSGreg Roach 416ade503dfSGreg Roach return null; 417ade503dfSGreg Roach } 418ade503dfSGreg Roach 419ade503dfSGreg Roach /** 420ade503dfSGreg Roach * Themes menu. 421ade503dfSGreg Roach * 422ade503dfSGreg Roach * @return Menu|null 423ade503dfSGreg Roach */ 424e364afe4SGreg Roach public function menuThemes(): ?Menu 425ade503dfSGreg Roach { 426b668782fSGreg Roach $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true); 427df8baf00SGreg Roach 428cab242e7SGreg Roach $current_theme = app(ModuleThemeInterface::class); 4298136679eSGreg Roach 4308136679eSGreg Roach if ($themes->count() > 1) { 4310b5fd0a6SGreg Roach $submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu { 4328136679eSGreg Roach $active = $theme->name() === $current_theme->name(); 4338136679eSGreg Roach $class = 'menu-theme-' . $theme->name() . ($active ? ' active' : ''); 4348136679eSGreg Roach 4358136679eSGreg Roach return new Menu($theme->title(), '#', $class, [ 436ade503dfSGreg Roach 'onclick' => 'return false;', 437ade503dfSGreg Roach 'data-theme' => $theme->name(), 438ade503dfSGreg Roach ]); 439ade503dfSGreg Roach }); 440ade503dfSGreg Roach 4418136679eSGreg Roach return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all()); 442ade503dfSGreg Roach } 443ade503dfSGreg Roach 444ade503dfSGreg Roach return null; 445ade503dfSGreg Roach } 446ade503dfSGreg Roach 447ade503dfSGreg Roach /** 448ade503dfSGreg Roach * Misecellaneous dimensions, fonts, styles, etc. 449ade503dfSGreg Roach * 450ade503dfSGreg Roach * @param string $parameter_name 451ade503dfSGreg Roach * 452ade503dfSGreg Roach * @return string|int|float 453ade503dfSGreg Roach */ 454ade503dfSGreg Roach public function parameter($parameter_name) 455ade503dfSGreg Roach { 456ade503dfSGreg Roach return ''; 457ade503dfSGreg Roach } 458ade503dfSGreg Roach 459ade503dfSGreg Roach /** 460ade503dfSGreg Roach * Generate a list of items for the main menu. 461ade503dfSGreg Roach * 4620c8c69d4SGreg Roach * @param Tree|null $tree 4630c8c69d4SGreg Roach * 464ade503dfSGreg Roach * @return Menu[] 465ade503dfSGreg Roach */ 4660c8c69d4SGreg Roach public function genealogyMenu(?Tree $tree): array 467ade503dfSGreg Roach { 4680c8c69d4SGreg Roach if ($tree === null) { 4690c8c69d4SGreg Roach return []; 4700c8c69d4SGreg Roach } 4710c8c69d4SGreg Roach 4720c8c69d4SGreg Roach return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user()) 4730b5fd0a6SGreg Roach ->map(static function (ModuleMenuInterface $menu) use ($tree): ?Menu { 4740c8c69d4SGreg Roach return $menu->getMenu($tree); 475ade503dfSGreg Roach }) 476ade503dfSGreg Roach ->filter() 477ade503dfSGreg Roach ->all(); 478ade503dfSGreg Roach } 479ade503dfSGreg Roach 480ade503dfSGreg Roach /** 4810c8c69d4SGreg Roach * Create the genealogy menu. 482ade503dfSGreg Roach * 483ade503dfSGreg Roach * @param Menu[] $menus 484ade503dfSGreg Roach * 485ade503dfSGreg Roach * @return string 486ade503dfSGreg Roach */ 4870c8c69d4SGreg Roach public function genealogyMenuContent(array $menus): string 488ade503dfSGreg Roach { 4890b5fd0a6SGreg Roach return implode('', array_map(static function (Menu $menu): string { 490ade503dfSGreg Roach return $menu->bootstrap4(); 491ade503dfSGreg Roach }, $menus)); 492ade503dfSGreg Roach } 493ade503dfSGreg Roach 494ade503dfSGreg Roach /** 495ade503dfSGreg Roach * Generate a list of items for the user menu. 496ade503dfSGreg Roach * 4970c8c69d4SGreg Roach * @param Tree|null $tree 4980c8c69d4SGreg Roach * 499ade503dfSGreg Roach * @return Menu[] 500ade503dfSGreg Roach */ 5010c8c69d4SGreg Roach public function userMenu(?Tree $tree): array 502ade503dfSGreg Roach { 503ade503dfSGreg Roach return array_filter([ 5040c8c69d4SGreg Roach $this->menuPendingChanges($tree), 5050c8c69d4SGreg Roach $this->menuMyPages($tree), 506ade503dfSGreg Roach $this->menuThemes(), 507ade503dfSGreg Roach $this->menuLanguages(), 508ade503dfSGreg Roach $this->menuLogin(), 509ade503dfSGreg Roach $this->menuLogout(), 510ade503dfSGreg Roach ]); 511ade503dfSGreg Roach } 512ade503dfSGreg Roach 513ade503dfSGreg Roach /** 514ade503dfSGreg Roach * A list of CSS files to include for this page. 515ade503dfSGreg Roach * 516ade503dfSGreg Roach * @return string[] 517ade503dfSGreg Roach */ 518ade503dfSGreg Roach public function stylesheets(): array 519ade503dfSGreg Roach { 520ade503dfSGreg Roach return []; 521ade503dfSGreg Roach } 52249a243cbSGreg Roach} 523