167992b6aSRichard Cissee<?php 23976b470SGreg Roach 367992b6aSRichard Cissee/** 467992b6aSRichard Cissee * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 1667992b6aSRichard Cissee */ 17fcfa147eSGreg Roach 1867992b6aSRichard Cisseedeclare(strict_types=1); 1967992b6aSRichard Cissee 2067992b6aSRichard Cisseenamespace Fisharebest\Webtrees\Module; 2167992b6aSRichard Cissee 2267992b6aSRichard Cisseeuse Fisharebest\Webtrees\Auth; 2306a438b4SGreg Roachuse Fisharebest\Webtrees\I18N; 2452288ec7SGreg Roachuse Fisharebest\Webtrees\Registry; 25b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 266ccdf4f0SGreg Roachuse Psr\Http\Message\ResponseInterface; 276ccdf4f0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 28f3874e19SGreg Roach 2967992b6aSRichard Cissee/** 3067992b6aSRichard Cissee * Class FamilyListModule 3167992b6aSRichard Cissee */ 3206a438b4SGreg Roachclass FamilyListModule extends IndividualListModule 3367992b6aSRichard Cissee{ 3406a438b4SGreg Roach protected const ROUTE_URL = '/tree/{tree}/family-list'; 3567992b6aSRichard Cissee 3667992b6aSRichard Cissee /** 370cfd6963SGreg Roach * How should this module be identified in the control panel, etc.? 3867992b6aSRichard Cissee * 3967992b6aSRichard Cissee * @return string 4067992b6aSRichard Cissee */ 4167992b6aSRichard Cissee public function title(): string 4267992b6aSRichard Cissee { 4367992b6aSRichard Cissee /* I18N: Name of a module/list */ 4467992b6aSRichard Cissee return I18N::translate('Families'); 4567992b6aSRichard Cissee } 4667992b6aSRichard Cissee 4767992b6aSRichard Cissee /** 4867992b6aSRichard Cissee * A sentence describing what this module does. 4967992b6aSRichard Cissee * 5067992b6aSRichard Cissee * @return string 5167992b6aSRichard Cissee */ 5267992b6aSRichard Cissee public function description(): string 5367992b6aSRichard Cissee { 54b5e8e56bSGreg Roach /* I18N: Description of the “Families” module */ 5567992b6aSRichard Cissee return I18N::translate('A list of families.'); 5667992b6aSRichard Cissee } 5767992b6aSRichard Cissee 5867992b6aSRichard Cissee /** 5967992b6aSRichard Cissee * CSS class for the URL. 6067992b6aSRichard Cissee * 6167992b6aSRichard Cissee * @return string 6267992b6aSRichard Cissee */ 6367992b6aSRichard Cissee public function listMenuClass(): string 6467992b6aSRichard Cissee { 6567992b6aSRichard Cissee return 'menu-list-fam'; 6667992b6aSRichard Cissee } 6767992b6aSRichard Cissee 684db4b4a9SGreg Roach /** 696ccdf4f0SGreg Roach * @param ServerRequestInterface $request 704db4b4a9SGreg Roach * 716ccdf4f0SGreg Roach * @return ResponseInterface 724db4b4a9SGreg Roach */ 7306a438b4SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 7467992b6aSRichard Cissee { 75b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 76b55cbc6bSGreg Roach $user = Validator::attributes($request)->user(); 7757ab2231SGreg Roach 7896d794e7SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 7967992b6aSRichard Cissee 8052288ec7SGreg Roach $surname_param = Validator::queryParams($request)->string('surname', ''); 8152288ec7SGreg Roach $surname = I18N::strtoupper(I18N::language()->normalize($surname_param)); 8252288ec7SGreg Roach 83748dbe15SGreg Roach $params = [ 84748dbe15SGreg Roach 'alpha' => Validator::queryParams($request)->string('alpha', ''), 85748dbe15SGreg Roach 'falpha' => Validator::queryParams($request)->string('falpha', ''), 86748dbe15SGreg Roach 'show' => Validator::queryParams($request)->string('show', 'surn'), 87748dbe15SGreg Roach 'show_all' => Validator::queryParams($request)->string('show_all', 'no'), 88748dbe15SGreg Roach 'show_all_firstnames' => Validator::queryParams($request)->string('show_all_firstnames', 'no'), 89748dbe15SGreg Roach 'show_marnm' => Validator::queryParams($request)->string('show_marnm', ''), 9052288ec7SGreg Roach 'surname' => $surname, 91748dbe15SGreg Roach ]; 92748dbe15SGreg Roach 9352288ec7SGreg Roach if ($surname_param !== $surname) { 9452288ec7SGreg Roach return Registry::responseFactory()->redirectUrl($this->listUrl($tree, $params)); 9552288ec7SGreg Roach } 9652288ec7SGreg Roach 97748dbe15SGreg Roach return $this->createResponse($tree, $user, $params, true); 9867992b6aSRichard Cissee } 9967992b6aSRichard Cissee} 100