146295629SGreg Roach<?php 23976b470SGreg Roach 346295629SGreg Roach/** 446295629SGreg Roach * webtrees: online genealogy 546295629SGreg Roach * Copyright (C) 2019 webtrees development team 646295629SGreg Roach * This program is free software: you can redistribute it and/or modify 746295629SGreg Roach * it under the terms of the GNU General Public License as published by 846295629SGreg Roach * the Free Software Foundation, either version 3 of the License, or 946295629SGreg Roach * (at your option) any later version. 1046295629SGreg Roach * This program is distributed in the hope that it will be useful, 1146295629SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1246295629SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1346295629SGreg Roach * GNU General Public License for more details. 1446295629SGreg Roach * You should have received a copy of the GNU General Public License 1546295629SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1646295629SGreg Roach */ 17fcfa147eSGreg Roach 1846295629SGreg Roachdeclare(strict_types=1); 1946295629SGreg Roach 2046295629SGreg Roachnamespace Fisharebest\Webtrees\Module; 2146295629SGreg Roach 2246295629SGreg Roachuse Fisharebest\Webtrees\Auth; 23f5402f3dSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SearchAdvancedPage; 24f5402f3dSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SearchGeneralPage; 25f5402f3dSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SearchPhoneticPage; 26f5402f3dSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\SearchReplacePage; 2746295629SGreg Roachuse Fisharebest\Webtrees\I18N; 2846295629SGreg Roachuse Fisharebest\Webtrees\Menu; 2946295629SGreg Roachuse Fisharebest\Webtrees\Tree; 3046295629SGreg Roach 31f5402f3dSGreg Roachuse function route; 32f5402f3dSGreg Roach 3346295629SGreg Roach/** 3446295629SGreg Roach * Class SearchMenuModule - provide a menu option for the search options 3546295629SGreg Roach */ 3637eb8894SGreg Roachclass SearchMenuModule extends AbstractModule implements ModuleMenuInterface 3746295629SGreg Roach{ 3846295629SGreg Roach use ModuleMenuTrait; 3946295629SGreg Roach 40961ec755SGreg Roach /** 410cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 42961ec755SGreg Roach * 43961ec755SGreg Roach * @return string 44961ec755SGreg Roach */ 4546295629SGreg Roach public function title(): string 4646295629SGreg Roach { 4746295629SGreg Roach /* I18N: Name of a module */ 4846295629SGreg Roach return I18N::translate('Search'); 4946295629SGreg Roach } 5046295629SGreg Roach 51961ec755SGreg Roach /** 52961ec755SGreg Roach * A sentence describing what this module does. 53961ec755SGreg Roach * 54961ec755SGreg Roach * @return string 55961ec755SGreg Roach */ 5646295629SGreg Roach public function description(): string 5746295629SGreg Roach { 58*9e0868cbSGreg Roach /* I18N: Description of the “Search” module */ 5946295629SGreg Roach return I18N::translate('The search menu.'); 6046295629SGreg Roach } 6146295629SGreg Roach 6246295629SGreg Roach /** 6346295629SGreg Roach * The default position for this menu. It can be changed in the control panel. 6446295629SGreg Roach * 6546295629SGreg Roach * @return int 6646295629SGreg Roach */ 6746295629SGreg Roach public function defaultMenuOrder(): int 6846295629SGreg Roach { 69353b36abSGreg Roach return 6; 7046295629SGreg Roach } 7146295629SGreg Roach 7246295629SGreg Roach /** 7346295629SGreg Roach * A menu, to be added to the main application menu. 7446295629SGreg Roach * 7546295629SGreg Roach * @param Tree $tree 7646295629SGreg Roach * 7746295629SGreg Roach * @return Menu|null 7846295629SGreg Roach */ 7946295629SGreg Roach public function getMenu(Tree $tree): ?Menu 8046295629SGreg Roach { 8146295629SGreg Roach $submenu = [ 8246295629SGreg Roach $this->menuSearchGeneral($tree), 8346295629SGreg Roach $this->menuSearchPhonetic($tree), 8446295629SGreg Roach $this->menuSearchAdvanced($tree), 8546295629SGreg Roach $this->menuSearchAndReplace($tree), 8646295629SGreg Roach ]; 8746295629SGreg Roach 8846295629SGreg Roach $submenu = array_filter($submenu); 8946295629SGreg Roach 9046295629SGreg Roach return new Menu(I18N::translate('Search'), '#', 'menu-search', ['rel' => 'nofollow'], $submenu); 9146295629SGreg Roach } 9246295629SGreg Roach 9346295629SGreg Roach /** 9446295629SGreg Roach * @param Tree $tree 9546295629SGreg Roach * 9646295629SGreg Roach * @return Menu 9746295629SGreg Roach */ 9846295629SGreg Roach protected function menuSearchGeneral(Tree $tree): Menu 9946295629SGreg Roach { 100f5402f3dSGreg Roach return new Menu(I18N::translate('General search'), route(SearchGeneralPage::class, ['tree' => $tree->name()]), 'menu-search-general', ['rel' => 'nofollow']); 10146295629SGreg Roach } 10246295629SGreg Roach 10346295629SGreg Roach /** 10446295629SGreg Roach * @param Tree $tree 10546295629SGreg Roach * 10646295629SGreg Roach * @return Menu 10746295629SGreg Roach */ 10846295629SGreg Roach protected function menuSearchPhonetic(Tree $tree): Menu 10946295629SGreg Roach { 110f5402f3dSGreg Roach $url = route(SearchPhoneticPage::class, ['tree' => $tree->name()]); 111f5402f3dSGreg Roach 11246295629SGreg Roach /* I18N: search using “sounds like”, rather than exact spelling */ 113f5402f3dSGreg Roach return new Menu(I18N::translate('Phonetic search'), $url, 'menu-search-soundex', ['rel' => 'nofollow']); 11446295629SGreg Roach } 11546295629SGreg Roach 11646295629SGreg Roach /** 11746295629SGreg Roach * @param Tree $tree 11846295629SGreg Roach * 11946295629SGreg Roach * @return Menu 12046295629SGreg Roach */ 12146295629SGreg Roach protected function menuSearchAdvanced(Tree $tree): Menu 12246295629SGreg Roach { 123f5402f3dSGreg Roach $url = route(SearchAdvancedPage::class, ['tree' => $tree->name()]); 124f5402f3dSGreg Roach 125f5402f3dSGreg Roach return new Menu(I18N::translate('Advanced search'), $url, 'menu-search-advanced', ['rel' => 'nofollow']); 12646295629SGreg Roach } 12746295629SGreg Roach 12846295629SGreg Roach /** 12946295629SGreg Roach * @param Tree $tree 13046295629SGreg Roach * 13146295629SGreg Roach * @return Menu|null 13246295629SGreg Roach */ 13346295629SGreg Roach protected function menuSearchAndReplace(Tree $tree): ?Menu 13446295629SGreg Roach { 13546295629SGreg Roach if (Auth::isEditor($tree)) { 136f5402f3dSGreg Roach $url = route(SearchReplacePage::class, ['tree' => $tree->name()]); 137f5402f3dSGreg Roach 138f5402f3dSGreg Roach return new Menu(I18N::translate('Search and replace'), $url, 'menu-search-replace'); 13946295629SGreg Roach } 14046295629SGreg Roach 14146295629SGreg Roach return null; 14246295629SGreg Roach } 14346295629SGreg Roach} 144