1e72c24d6SGreg Roach<?php 2e72c24d6SGreg Roach 3e72c24d6SGreg Roach/** 4e72c24d6SGreg Roach * webtrees: online genealogy 589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6e72c24d6SGreg Roach * This program is free software: you can redistribute it and/or modify 7e72c24d6SGreg Roach * it under the terms of the GNU General Public License as published by 8e72c24d6SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9e72c24d6SGreg Roach * (at your option) any later version. 10e72c24d6SGreg Roach * This program is distributed in the hope that it will be useful, 11e72c24d6SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12e72c24d6SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13e72c24d6SGreg Roach * GNU General Public License for more details. 14e72c24d6SGreg Roach * 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/>. 16e72c24d6SGreg Roach */ 17e72c24d6SGreg Roach 18e72c24d6SGreg Roachdeclare(strict_types=1); 19e72c24d6SGreg Roach 20e72c24d6SGreg Roachnamespace Fisharebest\Webtrees\Module; 21e72c24d6SGreg Roach 2206a438b4SGreg Roachuse Aura\Router\RouterContainer; 2309482a55SGreg Roachuse Fisharebest\Webtrees\Auth; 2406a438b4SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 25e72c24d6SGreg Roachuse Fisharebest\Webtrees\I18N; 2609482a55SGreg Roachuse Fisharebest\Webtrees\Registry; 27e72c24d6SGreg Roachuse Fisharebest\Webtrees\Submitter; 28e72c24d6SGreg Roachuse Fisharebest\Webtrees\Tree; 29b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator; 30e72c24d6SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 31e72c24d6SGreg Roachuse Psr\Http\Message\ResponseInterface; 32e72c24d6SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 3306a438b4SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 34e72c24d6SGreg Roach 3506a438b4SGreg Roachuse function app; 36e72c24d6SGreg Roachuse function assert; 3706a438b4SGreg Roachuse function redirect; 38e72c24d6SGreg Roach 39e72c24d6SGreg Roach/** 40e72c24d6SGreg Roach * Class SubmitterListModule 41e72c24d6SGreg Roach */ 4206a438b4SGreg Roachclass SubmitterListModule extends AbstractModule implements ModuleListInterface, RequestHandlerInterface 43e72c24d6SGreg Roach{ 44e72c24d6SGreg Roach use ModuleListTrait; 45e72c24d6SGreg Roach 4606a438b4SGreg Roach protected const ROUTE_URL = '/tree/{tree}/submitter-list'; 4706a438b4SGreg Roach 48e72c24d6SGreg Roach /** @var int The default access level for this module. It can be changed in the control panel. */ 4933c746f1SGreg Roach protected int $access_level = Auth::PRIV_NONE; 50e72c24d6SGreg Roach 51e72c24d6SGreg Roach /** 5206a438b4SGreg Roach * Initialization. 5306a438b4SGreg Roach * 5406a438b4SGreg Roach * @return void 5506a438b4SGreg Roach */ 5606a438b4SGreg Roach public function boot(): void 5706a438b4SGreg Roach { 58*158900c2SGreg Roach Registry::routeFactory()->routeMap() 5906a438b4SGreg Roach ->get(static::class, static::ROUTE_URL, $this); 6006a438b4SGreg Roach } 6106a438b4SGreg Roach 6206a438b4SGreg Roach /** 63e72c24d6SGreg Roach * How should this module be identified in the control panel, etc.? 64e72c24d6SGreg Roach * 65e72c24d6SGreg Roach * @return string 66e72c24d6SGreg Roach */ 67e72c24d6SGreg Roach public function title(): string 68e72c24d6SGreg Roach { 69e72c24d6SGreg Roach /* I18N: Name of a module/list */ 70e72c24d6SGreg Roach return I18N::translate('Submitters'); 71e72c24d6SGreg Roach } 72e72c24d6SGreg Roach 73e72c24d6SGreg Roach /** 74e72c24d6SGreg Roach * A sentence describing what this module does. 75e72c24d6SGreg Roach * 76e72c24d6SGreg Roach * @return string 77e72c24d6SGreg Roach */ 78e72c24d6SGreg Roach public function description(): string 79e72c24d6SGreg Roach { 80f1c3484cSGreg Roach /* I18N: Description of the “Submitters” module */ 81e72c24d6SGreg Roach return I18N::translate('A list of submitters.'); 82e72c24d6SGreg Roach } 83e72c24d6SGreg Roach 84e72c24d6SGreg Roach /** 85e72c24d6SGreg Roach * Should this module be enabled when it is first installed? 86e72c24d6SGreg Roach * 87e72c24d6SGreg Roach * @return bool 88e72c24d6SGreg Roach */ 89e72c24d6SGreg Roach public function isEnabledByDefault(): bool 90e72c24d6SGreg Roach { 91e72c24d6SGreg Roach return false; 92e72c24d6SGreg Roach } 93e72c24d6SGreg Roach 94e72c24d6SGreg Roach /** 95e72c24d6SGreg Roach * CSS class for the URL. 96e72c24d6SGreg Roach * 97e72c24d6SGreg Roach * @return string 98e72c24d6SGreg Roach */ 99e72c24d6SGreg Roach public function listMenuClass(): string 100e72c24d6SGreg Roach { 101e72c24d6SGreg Roach return 'menu-list-subm'; 102e72c24d6SGreg Roach } 103e72c24d6SGreg Roach 104e72c24d6SGreg Roach /** 10506a438b4SGreg Roach * @param Tree $tree 10676d39c55SGreg Roach * @param array<bool|int|string|array<string>|null> $parameters 107e72c24d6SGreg Roach * 10806a438b4SGreg Roach * @return string 109e72c24d6SGreg Roach */ 11006a438b4SGreg Roach public function listUrl(Tree $tree, array $parameters = []): string 111e72c24d6SGreg Roach { 11206a438b4SGreg Roach $parameters['tree'] = $tree->name(); 113e72c24d6SGreg Roach 11406a438b4SGreg Roach return route(static::class, $parameters); 115e72c24d6SGreg Roach } 116e72c24d6SGreg Roach 117e72c24d6SGreg Roach /** 11824f2a3afSGreg Roach * @return array<string> 119e72c24d6SGreg Roach */ 120e72c24d6SGreg Roach public function listUrlAttributes(): array 121e72c24d6SGreg Roach { 122e72c24d6SGreg Roach return []; 123e72c24d6SGreg Roach } 124e72c24d6SGreg Roach 125e72c24d6SGreg Roach /** 126e72c24d6SGreg Roach * @param Tree $tree 127e72c24d6SGreg Roach * 128e72c24d6SGreg Roach * @return bool 129e72c24d6SGreg Roach */ 130e72c24d6SGreg Roach public function listIsEmpty(Tree $tree): bool 131e72c24d6SGreg Roach { 132e72c24d6SGreg Roach return !DB::table('other') 133e72c24d6SGreg Roach ->where('o_file', '=', $tree->id()) 134e72c24d6SGreg Roach ->where('o_type', '=', Submitter::RECORD_TYPE) 135e72c24d6SGreg Roach ->exists(); 136e72c24d6SGreg Roach } 13706a438b4SGreg Roach 13806a438b4SGreg Roach /** 13906a438b4SGreg Roach * Handle URLs generated by older versions of webtrees 14006a438b4SGreg Roach * 14106a438b4SGreg Roach * @param ServerRequestInterface $request 14206a438b4SGreg Roach * 14306a438b4SGreg Roach * @return ResponseInterface 14406a438b4SGreg Roach */ 14506a438b4SGreg Roach public function getListAction(ServerRequestInterface $request): ResponseInterface 14606a438b4SGreg Roach { 147b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 148b55cbc6bSGreg Roach 149b55cbc6bSGreg Roach return redirect($this->listUrl($tree, $request->getQueryParams())); 15006a438b4SGreg Roach } 15106a438b4SGreg Roach 15206a438b4SGreg Roach /** 15306a438b4SGreg Roach * @param ServerRequestInterface $request 15406a438b4SGreg Roach * 15506a438b4SGreg Roach * @return ResponseInterface 15606a438b4SGreg Roach */ 15706a438b4SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 15806a438b4SGreg Roach { 159b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 160b55cbc6bSGreg Roach $user = Validator::attributes($request)->user(); 16106a438b4SGreg Roach 16206a438b4SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 16306a438b4SGreg Roach 16406a438b4SGreg Roach $submitters = DB::table('other') 16506a438b4SGreg Roach ->where('o_file', '=', $tree->id()) 16606a438b4SGreg Roach ->where('o_type', '=', Submitter::RECORD_TYPE) 16706a438b4SGreg Roach ->get() 1686b9cb339SGreg Roach ->map(Registry::submitterFactory()->mapper($tree)) 16906a438b4SGreg Roach ->filter(GedcomRecord::accessFilter()); 17006a438b4SGreg Roach 17106a438b4SGreg Roach return $this->viewResponse('modules/submitter-list/page', [ 17206a438b4SGreg Roach 'submitters' => $submitters, 17306a438b4SGreg Roach 'title' => I18N::translate('Submitters'), 17406a438b4SGreg Roach 'tree' => $tree, 17506a438b4SGreg Roach ]); 17606a438b4SGreg Roach } 177e72c24d6SGreg Roach} 178