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; 29*b55cbc6bSGreg 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 { 5806a438b4SGreg Roach $router_container = app(RouterContainer::class); 5906a438b4SGreg Roach assert($router_container instanceof RouterContainer); 6006a438b4SGreg Roach 6106a438b4SGreg Roach $router_container->getMap() 6206a438b4SGreg Roach ->get(static::class, static::ROUTE_URL, $this); 6306a438b4SGreg Roach } 6406a438b4SGreg Roach 6506a438b4SGreg Roach /** 66e72c24d6SGreg Roach * How should this module be identified in the control panel, etc.? 67e72c24d6SGreg Roach * 68e72c24d6SGreg Roach * @return string 69e72c24d6SGreg Roach */ 70e72c24d6SGreg Roach public function title(): string 71e72c24d6SGreg Roach { 72e72c24d6SGreg Roach /* I18N: Name of a module/list */ 73e72c24d6SGreg Roach return I18N::translate('Submitters'); 74e72c24d6SGreg Roach } 75e72c24d6SGreg Roach 76e72c24d6SGreg Roach /** 77e72c24d6SGreg Roach * A sentence describing what this module does. 78e72c24d6SGreg Roach * 79e72c24d6SGreg Roach * @return string 80e72c24d6SGreg Roach */ 81e72c24d6SGreg Roach public function description(): string 82e72c24d6SGreg Roach { 83f1c3484cSGreg Roach /* I18N: Description of the “Submitters” module */ 84e72c24d6SGreg Roach return I18N::translate('A list of submitters.'); 85e72c24d6SGreg Roach } 86e72c24d6SGreg Roach 87e72c24d6SGreg Roach /** 88e72c24d6SGreg Roach * Should this module be enabled when it is first installed? 89e72c24d6SGreg Roach * 90e72c24d6SGreg Roach * @return bool 91e72c24d6SGreg Roach */ 92e72c24d6SGreg Roach public function isEnabledByDefault(): bool 93e72c24d6SGreg Roach { 94e72c24d6SGreg Roach return false; 95e72c24d6SGreg Roach } 96e72c24d6SGreg Roach 97e72c24d6SGreg Roach /** 98e72c24d6SGreg Roach * CSS class for the URL. 99e72c24d6SGreg Roach * 100e72c24d6SGreg Roach * @return string 101e72c24d6SGreg Roach */ 102e72c24d6SGreg Roach public function listMenuClass(): string 103e72c24d6SGreg Roach { 104e72c24d6SGreg Roach return 'menu-list-subm'; 105e72c24d6SGreg Roach } 106e72c24d6SGreg Roach 107e72c24d6SGreg Roach /** 10806a438b4SGreg Roach * @param Tree $tree 10976d39c55SGreg Roach * @param array<bool|int|string|array<string>|null> $parameters 110e72c24d6SGreg Roach * 11106a438b4SGreg Roach * @return string 112e72c24d6SGreg Roach */ 11306a438b4SGreg Roach public function listUrl(Tree $tree, array $parameters = []): string 114e72c24d6SGreg Roach { 11506a438b4SGreg Roach $parameters['tree'] = $tree->name(); 116e72c24d6SGreg Roach 11706a438b4SGreg Roach return route(static::class, $parameters); 118e72c24d6SGreg Roach } 119e72c24d6SGreg Roach 120e72c24d6SGreg Roach /** 12124f2a3afSGreg Roach * @return array<string> 122e72c24d6SGreg Roach */ 123e72c24d6SGreg Roach public function listUrlAttributes(): array 124e72c24d6SGreg Roach { 125e72c24d6SGreg Roach return []; 126e72c24d6SGreg Roach } 127e72c24d6SGreg Roach 128e72c24d6SGreg Roach /** 129e72c24d6SGreg Roach * @param Tree $tree 130e72c24d6SGreg Roach * 131e72c24d6SGreg Roach * @return bool 132e72c24d6SGreg Roach */ 133e72c24d6SGreg Roach public function listIsEmpty(Tree $tree): bool 134e72c24d6SGreg Roach { 135e72c24d6SGreg Roach return !DB::table('other') 136e72c24d6SGreg Roach ->where('o_file', '=', $tree->id()) 137e72c24d6SGreg Roach ->where('o_type', '=', Submitter::RECORD_TYPE) 138e72c24d6SGreg Roach ->exists(); 139e72c24d6SGreg Roach } 14006a438b4SGreg Roach 14106a438b4SGreg Roach /** 14206a438b4SGreg Roach * Handle URLs generated by older versions of webtrees 14306a438b4SGreg Roach * 14406a438b4SGreg Roach * @param ServerRequestInterface $request 14506a438b4SGreg Roach * 14606a438b4SGreg Roach * @return ResponseInterface 14706a438b4SGreg Roach */ 14806a438b4SGreg Roach public function getListAction(ServerRequestInterface $request): ResponseInterface 14906a438b4SGreg Roach { 150*b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 151*b55cbc6bSGreg Roach 152*b55cbc6bSGreg Roach return redirect($this->listUrl($tree, $request->getQueryParams())); 15306a438b4SGreg Roach } 15406a438b4SGreg Roach 15506a438b4SGreg Roach /** 15606a438b4SGreg Roach * @param ServerRequestInterface $request 15706a438b4SGreg Roach * 15806a438b4SGreg Roach * @return ResponseInterface 15906a438b4SGreg Roach */ 16006a438b4SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 16106a438b4SGreg Roach { 162*b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 163*b55cbc6bSGreg Roach $user = Validator::attributes($request)->user(); 16406a438b4SGreg Roach 16506a438b4SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 16606a438b4SGreg Roach 16706a438b4SGreg Roach $submitters = DB::table('other') 16806a438b4SGreg Roach ->where('o_file', '=', $tree->id()) 16906a438b4SGreg Roach ->where('o_type', '=', Submitter::RECORD_TYPE) 17006a438b4SGreg Roach ->get() 1716b9cb339SGreg Roach ->map(Registry::submitterFactory()->mapper($tree)) 17206a438b4SGreg Roach ->filter(GedcomRecord::accessFilter()); 17306a438b4SGreg Roach 17406a438b4SGreg Roach return $this->viewResponse('modules/submitter-list/page', [ 17506a438b4SGreg Roach 'submitters' => $submitters, 17606a438b4SGreg Roach 'title' => I18N::translate('Submitters'), 17706a438b4SGreg Roach 'tree' => $tree, 17806a438b4SGreg Roach ]); 17906a438b4SGreg Roach } 180e72c24d6SGreg Roach} 181