167992b6aSRichard Cissee<?php 23976b470SGreg Roach 367992b6aSRichard Cissee/** 467992b6aSRichard Cissee * webtrees: online genealogy 567992b6aSRichard Cissee * Copyright (C) 2019 webtrees development team 667992b6aSRichard Cissee * This program is free software: you can redistribute it and/or modify 767992b6aSRichard Cissee * it under the terms of the GNU General Public License as published by 867992b6aSRichard Cissee * the Free Software Foundation, either version 3 of the License, or 967992b6aSRichard Cissee * (at your option) any later version. 1067992b6aSRichard Cissee * This program is distributed in the hope that it will be useful, 1167992b6aSRichard Cissee * but WITHOUT ANY WARRANTY; without even the implied warranty of 1267992b6aSRichard Cissee * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1367992b6aSRichard Cissee * GNU General Public License for more details. 1467992b6aSRichard Cissee * You should have received a copy of the GNU General Public License 1567992b6aSRichard Cissee * along with this program. If not, see <http://www.gnu.org/licenses/>. 1667992b6aSRichard Cissee */ 17fcfa147eSGreg Roach 1867992b6aSRichard Cisseedeclare(strict_types=1); 1967992b6aSRichard Cissee 2067992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module; 2167992b6aSRichard Cissee 22808ea2d4SGreg Roachuse Fisharebest\Webtrees\Auth; 2367992b6aSRichard Cisseeuse Fisharebest\Webtrees\Http\Controllers\BranchesController; 2467992b6aSRichard Cisseeuse Fisharebest\Webtrees\I18N; 2567992b6aSRichard Cisseeuse Fisharebest\Webtrees\Services\ModuleService; 2667992b6aSRichard Cisseeuse Fisharebest\Webtrees\Tree; 276ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 286ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29f3874e19SGreg Roach 305229eadeSGreg Roachuse function assert; 31808ea2d4SGreg Roachuse function redirect; 32808ea2d4SGreg Roachuse function route; 3367992b6aSRichard Cissee 3467992b6aSRichard Cissee/** 3567992b6aSRichard Cissee * Class BranchesListModule 3667992b6aSRichard Cissee */ 3767992b6aSRichard Cisseeclass BranchesListModule extends AbstractModule implements ModuleListInterface 3867992b6aSRichard Cissee{ 3967992b6aSRichard Cissee use ModuleListTrait; 4067992b6aSRichard Cissee 4167992b6aSRichard Cissee /** 420cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 4367992b6aSRichard Cissee * 4467992b6aSRichard Cissee * @return string 4567992b6aSRichard Cissee */ 4667992b6aSRichard Cissee public function title(): string 4767992b6aSRichard Cissee { 4867992b6aSRichard Cissee /* I18N: Name of a module/list */ 4967992b6aSRichard Cissee return I18N::translate('Branches'); 5067992b6aSRichard Cissee } 5167992b6aSRichard Cissee 5267992b6aSRichard Cissee /** 5367992b6aSRichard Cissee * A sentence describing what this module does. 5467992b6aSRichard Cissee * 5567992b6aSRichard Cissee * @return string 5667992b6aSRichard Cissee */ 5767992b6aSRichard Cissee public function description(): string 5867992b6aSRichard Cissee { 5967992b6aSRichard Cissee /* I18N: Description of the “BranchesListModule” module */ 6067992b6aSRichard Cissee return I18N::translate('A list of branches of a family.'); 6167992b6aSRichard Cissee } 6267992b6aSRichard Cissee 6367992b6aSRichard Cissee /** 6467992b6aSRichard Cissee * CSS class for the URL. 6567992b6aSRichard Cissee * 6667992b6aSRichard Cissee * @return string 6767992b6aSRichard Cissee */ 6867992b6aSRichard Cissee public function listMenuClass(): string 6967992b6aSRichard Cissee { 7067992b6aSRichard Cissee return 'menu-branches'; 7167992b6aSRichard Cissee } 7267992b6aSRichard Cissee 734db4b4a9SGreg Roach /** 744db4b4a9SGreg Roach * @param Tree $tree 7559597b37SGreg Roach * @param mixed[] $parameters 764db4b4a9SGreg Roach * 774db4b4a9SGreg Roach * @return string 784db4b4a9SGreg Roach */ 7967992b6aSRichard Cissee public function listUrl(Tree $tree, array $parameters = []): string 8067992b6aSRichard Cissee { 8167992b6aSRichard Cissee return route('module', [ 8267992b6aSRichard Cissee 'module' => $this->name(), 8367992b6aSRichard Cissee 'action' => 'Page', 849022ab66SGreg Roach 'tree' => $tree->name(), 8567992b6aSRichard Cissee ] + $parameters); 8667992b6aSRichard Cissee } 8767992b6aSRichard Cissee 884db4b4a9SGreg Roach /** 896ccdf4f0SGreg Roach * @param ServerRequestInterface $request 904db4b4a9SGreg Roach * 916ccdf4f0SGreg Roach * @return ResponseInterface 924db4b4a9SGreg Roach */ 9357ab2231SGreg Roach public function getPageAction(ServerRequestInterface $request): ResponseInterface 9467992b6aSRichard Cissee { 9557ab2231SGreg Roach $tree = $request->getAttribute('tree'); 96*75964c75SGreg Roach assert($tree instanceof Tree); 975229eadeSGreg Roach 9857ab2231SGreg Roach $user = $request->getAttribute('user'); 9957ab2231SGreg Roach 10096d794e7SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 10167992b6aSRichard Cissee 10267992b6aSRichard Cissee $listController = new BranchesController(app(ModuleService::class)); 10367992b6aSRichard Cissee return $listController->page($request); 10467992b6aSRichard Cissee } 10567992b6aSRichard Cissee 1064db4b4a9SGreg Roach /** 1076ccdf4f0SGreg Roach * @param ServerRequestInterface $request 1084db4b4a9SGreg Roach * 1096ccdf4f0SGreg Roach * @return ResponseInterface 1104db4b4a9SGreg Roach */ 111808ea2d4SGreg Roach public function postPageAction(ServerRequestInterface $request): ResponseInterface 112808ea2d4SGreg Roach { 113808ea2d4SGreg Roach $tree = $request->getAttribute('tree'); 114*75964c75SGreg Roach assert($tree instanceof Tree); 115808ea2d4SGreg Roach 116808ea2d4SGreg Roach return redirect(route('module', [ 117808ea2d4SGreg Roach 'module' => $this->name(), 118808ea2d4SGreg Roach 'action' => 'Page', 119808ea2d4SGreg Roach 'surname' => $request->getParsedBody()['surname'] ?? '', 120808ea2d4SGreg Roach 'soundex_dm' => $request->getParsedBody()['soundex_dm'] ?? '', 121808ea2d4SGreg Roach 'soundex_std' => $request->getParsedBody()['soundex_std'] ?? '', 122808ea2d4SGreg Roach 'tree' => $tree->name(), 123808ea2d4SGreg Roach ])); 124808ea2d4SGreg Roach } 125808ea2d4SGreg Roach 126808ea2d4SGreg Roach /** 127808ea2d4SGreg Roach * @param ServerRequestInterface $request 128808ea2d4SGreg Roach * 129808ea2d4SGreg Roach * @return ResponseInterface 130808ea2d4SGreg Roach */ 13157ab2231SGreg Roach public function getListAction(ServerRequestInterface $request): ResponseInterface 13267992b6aSRichard Cissee { 13357ab2231SGreg Roach $tree = $request->getAttribute('tree'); 134*75964c75SGreg Roach assert($tree instanceof Tree); 1355229eadeSGreg Roach 13657ab2231SGreg Roach $user = $request->getAttribute('user'); 13757ab2231SGreg Roach 13896d794e7SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 13967992b6aSRichard Cissee 14057ab2231SGreg Roach return app(BranchesController::class)->list($request); 14167992b6aSRichard Cissee } 14267992b6aSRichard Cissee 1434db4b4a9SGreg Roach /** 1444db4b4a9SGreg Roach * @return string[] 1454db4b4a9SGreg Roach */ 14667992b6aSRichard Cissee public function listUrlAttributes(): array 14767992b6aSRichard Cissee { 14867992b6aSRichard Cissee return []; 14967992b6aSRichard Cissee } 15067992b6aSRichard Cissee} 151