149a243cbSGreg Roach<?php 23976b470SGreg 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 */ 17fcfa147eSGreg Roach 1849a243cbSGreg Roachdeclare(strict_types=1); 1949a243cbSGreg Roach 2049a243cbSGreg Roachnamespace Fisharebest\Webtrees\Module; 2149a243cbSGreg Roach 22ade503dfSGreg Roachuse Fisharebest\Webtrees\Auth; 23ade503dfSGreg Roachuse Fisharebest\Webtrees\Fact; 24ade503dfSGreg Roachuse Fisharebest\Webtrees\Gedcom; 25ade503dfSGreg Roachuse Fisharebest\Webtrees\GedcomTag; 26a49d0e3fSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\AccountEdit; 270c0910bfSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel; 2856f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\LoginPage; 2956f9a9c1SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\Logout; 3022e73debSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\PendingChanges; 317adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectLanguage; 327adfb8e5SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SelectTheme; 33ade503dfSGreg Roachuse Fisharebest\Webtrees\I18N; 34ade503dfSGreg Roachuse Fisharebest\Webtrees\Individual; 35ade503dfSGreg Roachuse Fisharebest\Webtrees\Menu; 364ca7e03cSGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 37ade503dfSGreg Roachuse Fisharebest\Webtrees\Tree; 387c4add84SGreg Roachuse Fisharebest\Webtrees\User; 39f397d0fdSGreg Roachuse Fisharebest\Webtrees\Webtrees; 406ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 413976b470SGreg Roach 426ccdf4f0SGreg Roachuse function app; 4390a2f718SGreg Roachuse function assert; 447adfb8e5SGreg Roachuse function route; 45ade503dfSGreg Roach 4649a243cbSGreg Roach/** 4749a243cbSGreg Roach * Trait ModuleThemeTrait - default implementation of ModuleThemeInterface 4849a243cbSGreg Roach */ 4949a243cbSGreg Roachtrait ModuleThemeTrait 5049a243cbSGreg Roach{ 51ade503dfSGreg Roach /** 52962ead51SGreg Roach * @return string 53962ead51SGreg Roach */ 54962ead51SGreg Roach abstract public function name(): string; 55962ead51SGreg Roach 56962ead51SGreg Roach /** 57962ead51SGreg Roach * @return string 58962ead51SGreg Roach */ 59962ead51SGreg Roach abstract public function title(): string; 60962ead51SGreg Roach 61962ead51SGreg Roach /** 623d8b2a8eSGreg Roach * A sentence describing what this module does. 633d8b2a8eSGreg Roach * 643d8b2a8eSGreg Roach * @return string 653d8b2a8eSGreg Roach */ 663d8b2a8eSGreg Roach public function description(): string 673d8b2a8eSGreg Roach { 683d8b2a8eSGreg Roach return I18N::translate('Theme') . ' — ' . $this->title(); 693d8b2a8eSGreg Roach } 703d8b2a8eSGreg Roach 713d8b2a8eSGreg Roach /** 72ade503dfSGreg Roach * Generate the facts, for display in charts. 73ade503dfSGreg Roach * 74ade503dfSGreg Roach * @param Individual $individual 75ade503dfSGreg Roach * 76ade503dfSGreg Roach * @return string 77ade503dfSGreg Roach */ 78ade503dfSGreg Roach public function individualBoxFacts(Individual $individual): string 79ade503dfSGreg Roach { 80ade503dfSGreg Roach $html = ''; 81ade503dfSGreg Roach 82ade503dfSGreg Roach $opt_tags = preg_split('/\W/', $individual->tree()->getPreference('CHART_BOX_TAGS'), 0, PREG_SPLIT_NO_EMPTY); 83ade503dfSGreg Roach // Show BIRT or equivalent event 84ade503dfSGreg Roach foreach (Gedcom::BIRTH_EVENTS as $birttag) { 8522d65e5aSGreg Roach if (!in_array($birttag, $opt_tags, true)) { 86820b62dfSGreg Roach $event = $individual->facts([$birttag])->first(); 87820b62dfSGreg Roach if ($event instanceof Fact) { 88ade503dfSGreg Roach $html .= $event->summary(); 89ade503dfSGreg Roach break; 90ade503dfSGreg Roach } 91ade503dfSGreg Roach } 92ade503dfSGreg Roach } 93ade503dfSGreg Roach // Show optional events (before death) 94ade503dfSGreg Roach foreach ($opt_tags as $key => $tag) { 9522d65e5aSGreg Roach if (!in_array($tag, Gedcom::DEATH_EVENTS, true)) { 96820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 97820b62dfSGreg Roach if ($event instanceof Fact) { 98ade503dfSGreg Roach $html .= $event->summary(); 99ade503dfSGreg Roach unset($opt_tags[$key]); 100ade503dfSGreg Roach } 101ade503dfSGreg Roach } 102ade503dfSGreg Roach } 103ade503dfSGreg Roach // Show DEAT or equivalent event 104ade503dfSGreg Roach foreach (Gedcom::DEATH_EVENTS as $deattag) { 105820b62dfSGreg Roach $event = $individual->facts([$deattag])->first(); 106820b62dfSGreg Roach if ($event instanceof Fact) { 107ade503dfSGreg Roach $html .= $event->summary(); 10822d65e5aSGreg Roach if (in_array($deattag, $opt_tags, true)) { 10922d65e5aSGreg Roach unset($opt_tags[array_search($deattag, $opt_tags, true)]); 110ade503dfSGreg Roach } 111ade503dfSGreg Roach break; 112ade503dfSGreg Roach } 113ade503dfSGreg Roach } 114ade503dfSGreg Roach // Show remaining optional events (after death) 115ade503dfSGreg Roach foreach ($opt_tags as $tag) { 116820b62dfSGreg Roach $event = $individual->facts([$tag])->first(); 117820b62dfSGreg Roach if ($event instanceof Fact) { 118ade503dfSGreg Roach $html .= $event->summary(); 119ade503dfSGreg Roach } 120ade503dfSGreg Roach } 121ade503dfSGreg Roach 122ade503dfSGreg Roach return $html; 123ade503dfSGreg Roach } 124ade503dfSGreg Roach 125ade503dfSGreg Roach /** 126ade503dfSGreg Roach * Links, to show in chart boxes; 127ade503dfSGreg Roach * 128ade503dfSGreg Roach * @param Individual $individual 129ade503dfSGreg Roach * 130ade503dfSGreg Roach * @return Menu[] 131ade503dfSGreg Roach */ 132ade503dfSGreg Roach public function individualBoxMenu(Individual $individual): array 133ade503dfSGreg Roach { 134ade503dfSGreg Roach $menus = array_merge( 135ade503dfSGreg Roach $this->individualBoxMenuCharts($individual), 136ade503dfSGreg Roach $this->individualBoxMenuFamilyLinks($individual) 137ade503dfSGreg Roach ); 138ade503dfSGreg Roach 139ade503dfSGreg Roach return $menus; 140ade503dfSGreg Roach } 141ade503dfSGreg Roach 142ade503dfSGreg Roach /** 143ade503dfSGreg Roach * Chart links, to show in chart boxes; 144ade503dfSGreg Roach * 145ade503dfSGreg Roach * @param Individual $individual 146ade503dfSGreg Roach * 147ade503dfSGreg Roach * @return Menu[] 148ade503dfSGreg Roach */ 149ade503dfSGreg Roach public function individualBoxMenuCharts(Individual $individual): array 150ade503dfSGreg Roach { 151ade503dfSGreg Roach $menus = []; 152f39638cfSGreg Roach foreach (app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $individual->tree(), Auth::user()) as $chart) { 153ade503dfSGreg Roach $menu = $chart->chartBoxMenu($individual); 154ade503dfSGreg Roach if ($menu) { 155ade503dfSGreg Roach $menus[] = $menu; 156ade503dfSGreg Roach } 157ade503dfSGreg Roach } 158ade503dfSGreg Roach 1590b93976aSGreg Roach usort($menus, static function (Menu $x, Menu $y): int { 160ade503dfSGreg Roach return I18N::strcasecmp($x->getLabel(), $y->getLabel()); 161ade503dfSGreg Roach }); 162ade503dfSGreg Roach 163ade503dfSGreg Roach return $menus; 164ade503dfSGreg Roach } 165ade503dfSGreg Roach 166ade503dfSGreg Roach /** 167ade503dfSGreg Roach * Family links, to show in chart boxes. 168ade503dfSGreg Roach * 169ade503dfSGreg Roach * @param Individual $individual 170ade503dfSGreg Roach * 171ade503dfSGreg Roach * @return Menu[] 172ade503dfSGreg Roach */ 173ade503dfSGreg Roach public function individualBoxMenuFamilyLinks(Individual $individual): array 174ade503dfSGreg Roach { 175ade503dfSGreg Roach $menus = []; 176ade503dfSGreg Roach 17739ca88baSGreg Roach foreach ($individual->spouseFamilies() as $family) { 178ade503dfSGreg Roach $menus[] = new Menu('<strong>' . I18N::translate('Family with spouse') . '</strong>', $family->url()); 17939ca88baSGreg Roach $spouse = $family->spouse($individual); 180ade503dfSGreg Roach if ($spouse && $spouse->canShowName()) { 18139ca88baSGreg Roach $menus[] = new Menu($spouse->fullName(), $spouse->url()); 182ade503dfSGreg Roach } 18339ca88baSGreg Roach foreach ($family->children() as $child) { 184ade503dfSGreg Roach if ($child->canShowName()) { 18539ca88baSGreg Roach $menus[] = new Menu($child->fullName(), $child->url()); 186ade503dfSGreg Roach } 187ade503dfSGreg Roach } 188ade503dfSGreg Roach } 189ade503dfSGreg Roach 190ade503dfSGreg Roach return $menus; 191ade503dfSGreg Roach } 192ade503dfSGreg Roach 193ade503dfSGreg Roach /** 194f567c3d8SGreg Roach * Generate a menu item to change the blocks on the current tree/user page. 195ade503dfSGreg Roach * 1960c8c69d4SGreg Roach * @param Tree $tree 1970c8c69d4SGreg Roach * 198ade503dfSGreg Roach * @return Menu|null 199ade503dfSGreg Roach */ 200e364afe4SGreg Roach public function menuChangeBlocks(Tree $tree): ?Menu 201ade503dfSGreg Roach { 202eb235819SGreg Roach /** @var ServerRequestInterface $request */ 2036ccdf4f0SGreg Roach $request = app(ServerRequestInterface::class); 204e6bcfa02SGreg Roach 2050d7461faSGreg Roach $route = $request->getAttribute('route'); 206eb235819SGreg Roach 207eb235819SGreg Roach if (Auth::check() && $route === 'user-page') { 208d72b284aSGreg Roach return new Menu(I18N::translate('Customize this page'), route('user-page-edit', ['tree' => $tree->name()]), 'menu-change-blocks'); 209ade503dfSGreg Roach } 210ade503dfSGreg Roach 211eb235819SGreg Roach if (Auth::isManager($tree) && $route === 'tree-page') { 212d72b284aSGreg Roach return new Menu(I18N::translate('Customize this page'), route('tree-page-edit', ['tree' => $tree->name()]), 'menu-change-blocks'); 213ade503dfSGreg Roach } 214ade503dfSGreg Roach 215ade503dfSGreg Roach return null; 216ade503dfSGreg Roach } 217ade503dfSGreg Roach 218ade503dfSGreg Roach /** 219ade503dfSGreg Roach * Generate a menu item for the control panel. 220ade503dfSGreg Roach * 2210c8c69d4SGreg Roach * @param Tree $tree 2220c8c69d4SGreg Roach * 223ade503dfSGreg Roach * @return Menu|null 224ade503dfSGreg Roach */ 225e364afe4SGreg Roach public function menuControlPanel(Tree $tree): ?Menu 226ade503dfSGreg Roach { 227ade503dfSGreg Roach if (Auth::isAdmin()) { 2280c0910bfSGreg Roach return new Menu(I18N::translate('Control panel'), route(ControlPanel::class), 'menu-admin'); 229ade503dfSGreg Roach } 230ade503dfSGreg Roach 2310c8c69d4SGreg Roach if (Auth::isManager($tree)) { 232*6f414251SGreg Roach return new Menu(I18N::translate('Control panel'), route('manage-trees', ['tree' => $tree->name()]), 'menu-admin'); 233ade503dfSGreg Roach } 234ade503dfSGreg Roach 235ade503dfSGreg Roach return null; 236ade503dfSGreg Roach } 237ade503dfSGreg Roach 238ade503dfSGreg Roach /** 239ade503dfSGreg Roach * A menu to show a list of available languages. 240ade503dfSGreg Roach * 241ade503dfSGreg Roach * @return Menu|null 242ade503dfSGreg Roach */ 243e364afe4SGreg Roach public function menuLanguages(): ?Menu 244ade503dfSGreg Roach { 245ade503dfSGreg Roach $menu = new Menu(I18N::translate('Language'), '#', 'menu-language'); 246ade503dfSGreg Roach 24790a2f718SGreg Roach foreach (I18N::activeLocales() as $active_locale) { 24890a2f718SGreg Roach $language_tag = $active_locale->languageTag(); 24965cf5706SGreg Roach $class = 'menu-language-' . $language_tag . (I18N::languageTag() === $language_tag ? ' active' : ''); 25090a2f718SGreg Roach $menu->addSubmenu(new Menu($active_locale->endonym(), '#', $class, [ 2517adfb8e5SGreg Roach 'data-post-url' => route(SelectLanguage::class, ['language' => $language_tag]), 252ade503dfSGreg Roach ])); 253ade503dfSGreg Roach } 254ade503dfSGreg Roach 255ade503dfSGreg Roach if (count($menu->getSubmenus()) > 1) { 256ade503dfSGreg Roach return $menu; 257ade503dfSGreg Roach } 258ade503dfSGreg Roach 259ade503dfSGreg Roach return null; 260ade503dfSGreg Roach } 261ade503dfSGreg Roach 262ade503dfSGreg Roach /** 263ade503dfSGreg Roach * A login menu option (or null if we are already logged in). 264ade503dfSGreg Roach * 265ade503dfSGreg Roach * @return Menu|null 266ade503dfSGreg Roach */ 267e364afe4SGreg Roach public function menuLogin(): ?Menu 268ade503dfSGreg Roach { 269ade503dfSGreg Roach if (Auth::check()) { 270ade503dfSGreg Roach return null; 271ade503dfSGreg Roach } 272ade503dfSGreg Roach 27386661454SGreg Roach $request = app(ServerRequestInterface::class); 27486661454SGreg Roach 275ade503dfSGreg Roach // Return to this page after login... 276b6c0b825SGreg Roach $redirect = $request->getQueryParams()['url'] ?? (string) $request->getUri(); 277ade503dfSGreg Roach 278ade503dfSGreg Roach // ...but switch from the tree-page to the user-page 27991c514e5SGreg Roach if ($request->getAttribute('route') === 'tree-page') { 28091c514e5SGreg Roach $tree = $request->getAttribute('tree'); 28175964c75SGreg Roach assert($tree instanceof Tree); 28291c514e5SGreg Roach $redirect = route('user-page', ['tree' => $tree->name()]); 28391c514e5SGreg Roach } 284ade503dfSGreg Roach 28586661454SGreg Roach // Stay on the same tree page 28686661454SGreg Roach $tree = $request->getAttribute('tree'); 28791c514e5SGreg Roach $url = route(LoginPage::class, ['tree' => $tree instanceof Tree ? $tree->name() : null, 'url' => $redirect]); 28886661454SGreg Roach 28986661454SGreg Roach return new Menu(I18N::translate('Sign in'), $url, 'menu-login', ['rel' => 'nofollow']); 290ade503dfSGreg Roach } 291ade503dfSGreg Roach 292ade503dfSGreg Roach /** 293ade503dfSGreg Roach * A logout menu option (or null if we are already logged out). 294ade503dfSGreg Roach * 295ade503dfSGreg Roach * @return Menu|null 296ade503dfSGreg Roach */ 297e364afe4SGreg Roach public function menuLogout(): ?Menu 298ade503dfSGreg Roach { 299ade503dfSGreg Roach if (Auth::check()) { 3009b541e4aSGreg Roach $parameters = [ 3019b541e4aSGreg Roach 'data-post-url' => route(Logout::class), 3029b541e4aSGreg Roach ]; 3039b541e4aSGreg Roach 3049b541e4aSGreg Roach return new Menu(I18N::translate('Sign out'), '#', 'menu-logout', $parameters); 305ade503dfSGreg Roach } 306ade503dfSGreg Roach 307ade503dfSGreg Roach return null; 308ade503dfSGreg Roach } 309ade503dfSGreg Roach 310ade503dfSGreg Roach /** 311ade503dfSGreg Roach * A link to allow users to edit their account settings. 312ade503dfSGreg Roach * 31365aec466SGreg Roach * @param Tree|null $tree 314a49d0e3fSGreg Roach * 315a49d0e3fSGreg Roach * @return Menu 316ade503dfSGreg Roach */ 317a49d0e3fSGreg Roach public function menuMyAccount(?Tree $tree): Menu 318ade503dfSGreg Roach { 319a49d0e3fSGreg Roach $url = route(AccountEdit::class, ['tree' => $tree instanceof Tree ? $tree->name() : null]); 320ade503dfSGreg Roach 321a49d0e3fSGreg Roach return new Menu(I18N::translate('My account'), $url); 322ade503dfSGreg Roach } 323ade503dfSGreg Roach 324ade503dfSGreg Roach /** 325ade503dfSGreg Roach * A link to the user's individual record (individual.php). 326ade503dfSGreg Roach * 3270c8c69d4SGreg Roach * @param Tree $tree 3280c8c69d4SGreg Roach * 329ade503dfSGreg Roach * @return Menu|null 330ade503dfSGreg Roach */ 331e364afe4SGreg Roach public function menuMyIndividualRecord(Tree $tree): ?Menu 332ade503dfSGreg Roach { 3337c4add84SGreg Roach $record = Individual::getInstance($tree->getUserPreference(Auth::user(), User::PREF_TREE_ACCOUNT_XREF), $tree); 334ade503dfSGreg Roach 335ade503dfSGreg Roach if ($record) { 336ade503dfSGreg Roach return new Menu(I18N::translate('My individual record'), $record->url(), 'menu-myrecord'); 337ade503dfSGreg Roach } 338ade503dfSGreg Roach 339ade503dfSGreg Roach return null; 340ade503dfSGreg Roach } 341ade503dfSGreg Roach 342ade503dfSGreg Roach /** 343ade503dfSGreg Roach * A link to the user's personal home page. 344ade503dfSGreg Roach * 3450c8c69d4SGreg Roach * @param Tree $tree 3460c8c69d4SGreg Roach * 347ade503dfSGreg Roach * @return Menu 348ade503dfSGreg Roach */ 3490c8c69d4SGreg Roach public function menuMyPage(Tree $tree): Menu 350ade503dfSGreg Roach { 351d72b284aSGreg Roach return new Menu(I18N::translate('My page'), route('user-page', ['tree' => $tree->name()]), 'menu-mypage'); 352ade503dfSGreg Roach } 353ade503dfSGreg Roach 354ade503dfSGreg Roach /** 355ade503dfSGreg Roach * A menu for the user's personal pages. 356ade503dfSGreg Roach * 3570c8c69d4SGreg Roach * @param Tree|null $tree 3580c8c69d4SGreg Roach * 359ade503dfSGreg Roach * @return Menu|null 360ade503dfSGreg Roach */ 361e364afe4SGreg Roach public function menuMyPages(?Tree $tree): ?Menu 362ade503dfSGreg Roach { 363a49d0e3fSGreg Roach if (Auth::id()) { 364a49d0e3fSGreg Roach if ($tree instanceof Tree) { 365ade503dfSGreg Roach return new Menu(I18N::translate('My pages'), '#', 'menu-mymenu', [], array_filter([ 3660c8c69d4SGreg Roach $this->menuMyPage($tree), 3670c8c69d4SGreg Roach $this->menuMyIndividualRecord($tree), 3680c8c69d4SGreg Roach $this->menuMyPedigree($tree), 369a49d0e3fSGreg Roach $this->menuMyAccount($tree), 3700c8c69d4SGreg Roach $this->menuControlPanel($tree), 3710c8c69d4SGreg Roach $this->menuChangeBlocks($tree), 372ade503dfSGreg Roach ])); 373ade503dfSGreg Roach } 374ade503dfSGreg Roach 375a49d0e3fSGreg Roach return $this->menuMyAccount($tree); 376a49d0e3fSGreg Roach } 377a49d0e3fSGreg Roach 378ade503dfSGreg Roach return null; 379ade503dfSGreg Roach } 380ade503dfSGreg Roach 381ade503dfSGreg Roach /** 382ade503dfSGreg Roach * A link to the user's individual record. 383ade503dfSGreg Roach * 3840c8c69d4SGreg Roach * @param Tree $tree 3850c8c69d4SGreg Roach * 386ade503dfSGreg Roach * @return Menu|null 387ade503dfSGreg Roach */ 388e364afe4SGreg Roach public function menuMyPedigree(Tree $tree): ?Menu 389ade503dfSGreg Roach { 3907c4add84SGreg Roach $gedcomid = $tree->getUserPreference(Auth::user(), User::PREF_TREE_ACCOUNT_XREF); 391ade503dfSGreg Roach 3920c8c69d4SGreg Roach $pedigree_chart = app(ModuleService::class)->findByComponent(ModuleChartInterface::class, $tree, Auth::user()) 3930b5fd0a6SGreg Roach ->filter(static function (ModuleInterface $module): bool { 394ade503dfSGreg Roach return $module instanceof PedigreeChartModule; 395ade503dfSGreg Roach }); 396ade503dfSGreg Roach 397ade503dfSGreg Roach if ($gedcomid !== '' && $pedigree_chart instanceof PedigreeChartModule) { 398ade503dfSGreg Roach return new Menu( 399ade503dfSGreg Roach I18N::translate('My pedigree'), 400ade503dfSGreg Roach route('pedigree', [ 401ade503dfSGreg Roach 'xref' => $gedcomid, 4029022ab66SGreg Roach 'tree' => $tree->name(), 403ade503dfSGreg Roach ]), 404ade503dfSGreg Roach 'menu-mypedigree' 405ade503dfSGreg Roach ); 406ade503dfSGreg Roach } 407ade503dfSGreg Roach 408ade503dfSGreg Roach return null; 409ade503dfSGreg Roach } 410ade503dfSGreg Roach 411ade503dfSGreg Roach /** 412ade503dfSGreg Roach * Create a pending changes menu. 413ade503dfSGreg Roach * 4140c8c69d4SGreg Roach * @param Tree|null $tree 4150c8c69d4SGreg Roach * 416ade503dfSGreg Roach * @return Menu|null 417ade503dfSGreg Roach */ 418e364afe4SGreg Roach public function menuPendingChanges(?Tree $tree): ?Menu 419ade503dfSGreg Roach { 4200c8c69d4SGreg Roach if ($tree instanceof Tree && $tree->hasPendingEdit() && Auth::isModerator($tree)) { 42122e73debSGreg Roach $url = route(PendingChanges::class, [ 4229022ab66SGreg Roach 'tree' => $tree->name(), 423cf8c0692SGreg Roach 'url' => (string) app(ServerRequestInterface::class)->getUri(), 424ade503dfSGreg Roach ]); 425ade503dfSGreg Roach 426ade503dfSGreg Roach return new Menu(I18N::translate('Pending changes'), $url, 'menu-pending'); 427ade503dfSGreg Roach } 428ade503dfSGreg Roach 429ade503dfSGreg Roach return null; 430ade503dfSGreg Roach } 431ade503dfSGreg Roach 432ade503dfSGreg Roach /** 433ade503dfSGreg Roach * Themes menu. 434ade503dfSGreg Roach * 435ade503dfSGreg Roach * @return Menu|null 436ade503dfSGreg Roach */ 437e364afe4SGreg Roach public function menuThemes(): ?Menu 438ade503dfSGreg Roach { 439b668782fSGreg Roach $themes = app(ModuleService::class)->findByInterface(ModuleThemeInterface::class, false, true); 440df8baf00SGreg Roach 441cab242e7SGreg Roach $current_theme = app(ModuleThemeInterface::class); 4428136679eSGreg Roach 4438136679eSGreg Roach if ($themes->count() > 1) { 4440b5fd0a6SGreg Roach $submenus = $themes->map(static function (ModuleThemeInterface $theme) use ($current_theme): Menu { 4458136679eSGreg Roach $active = $theme->name() === $current_theme->name(); 4468136679eSGreg Roach $class = 'menu-theme-' . $theme->name() . ($active ? ' active' : ''); 4478136679eSGreg Roach 4488136679eSGreg Roach return new Menu($theme->title(), '#', $class, [ 4497adfb8e5SGreg Roach 'data-post-url' => route(SelectTheme::class, ['theme' => $theme->name()]), 450ade503dfSGreg Roach ]); 451ade503dfSGreg Roach }); 452ade503dfSGreg Roach 4538136679eSGreg Roach return new Menu(I18N::translate('Theme'), '#', 'menu-theme', [], $submenus->all()); 454ade503dfSGreg Roach } 455ade503dfSGreg Roach 456ade503dfSGreg Roach return null; 457ade503dfSGreg Roach } 458ade503dfSGreg Roach 459ade503dfSGreg Roach /** 460ade503dfSGreg Roach * Misecellaneous dimensions, fonts, styles, etc. 461ade503dfSGreg Roach * 462ade503dfSGreg Roach * @param string $parameter_name 463ade503dfSGreg Roach * 464ade503dfSGreg Roach * @return string|int|float 465ade503dfSGreg Roach */ 466ade503dfSGreg Roach public function parameter($parameter_name) 467ade503dfSGreg Roach { 468ade503dfSGreg Roach return ''; 469ade503dfSGreg Roach } 470ade503dfSGreg Roach 471ade503dfSGreg Roach /** 472ade503dfSGreg Roach * Generate a list of items for the main menu. 473ade503dfSGreg Roach * 4740c8c69d4SGreg Roach * @param Tree|null $tree 4750c8c69d4SGreg Roach * 476ade503dfSGreg Roach * @return Menu[] 477ade503dfSGreg Roach */ 4780c8c69d4SGreg Roach public function genealogyMenu(?Tree $tree): array 479ade503dfSGreg Roach { 4800c8c69d4SGreg Roach if ($tree === null) { 4810c8c69d4SGreg Roach return []; 4820c8c69d4SGreg Roach } 4830c8c69d4SGreg Roach 4840c8c69d4SGreg Roach return app(ModuleService::class)->findByComponent(ModuleMenuInterface::class, $tree, Auth::user()) 4850b5fd0a6SGreg Roach ->map(static function (ModuleMenuInterface $menu) use ($tree): ?Menu { 4860c8c69d4SGreg Roach return $menu->getMenu($tree); 487ade503dfSGreg Roach }) 488ade503dfSGreg Roach ->filter() 489ade503dfSGreg Roach ->all(); 490ade503dfSGreg Roach } 491ade503dfSGreg Roach 492ade503dfSGreg Roach /** 4930c8c69d4SGreg Roach * Create the genealogy menu. 494ade503dfSGreg Roach * 495ade503dfSGreg Roach * @param Menu[] $menus 496ade503dfSGreg Roach * 497ade503dfSGreg Roach * @return string 498ade503dfSGreg Roach */ 4990c8c69d4SGreg Roach public function genealogyMenuContent(array $menus): string 500ade503dfSGreg Roach { 5010b5fd0a6SGreg Roach return implode('', array_map(static function (Menu $menu): string { 502ade503dfSGreg Roach return $menu->bootstrap4(); 503ade503dfSGreg Roach }, $menus)); 504ade503dfSGreg Roach } 505ade503dfSGreg Roach 506ade503dfSGreg Roach /** 507ade503dfSGreg Roach * Generate a list of items for the user menu. 508ade503dfSGreg Roach * 5090c8c69d4SGreg Roach * @param Tree|null $tree 5100c8c69d4SGreg Roach * 511ade503dfSGreg Roach * @return Menu[] 512ade503dfSGreg Roach */ 5130c8c69d4SGreg Roach public function userMenu(?Tree $tree): array 514ade503dfSGreg Roach { 515ade503dfSGreg Roach return array_filter([ 5160c8c69d4SGreg Roach $this->menuPendingChanges($tree), 5170c8c69d4SGreg Roach $this->menuMyPages($tree), 518ade503dfSGreg Roach $this->menuThemes(), 519ade503dfSGreg Roach $this->menuLanguages(), 520ade503dfSGreg Roach $this->menuLogin(), 521ade503dfSGreg Roach $this->menuLogout(), 522ade503dfSGreg Roach ]); 523ade503dfSGreg Roach } 524ade503dfSGreg Roach 525ade503dfSGreg Roach /** 526ade503dfSGreg Roach * A list of CSS files to include for this page. 527ade503dfSGreg Roach * 528ade503dfSGreg Roach * @return string[] 529ade503dfSGreg Roach */ 530ade503dfSGreg Roach public function stylesheets(): array 531ade503dfSGreg Roach { 532ade503dfSGreg Roach return []; 533ade503dfSGreg Roach } 53449a243cbSGreg Roach} 535