1e72c24d6SGreg Roach<?php 2e72c24d6SGreg Roach 3e72c24d6SGreg Roach/** 4e72c24d6SGreg Roach * webtrees: online genealogy 5*89f7189bSGreg 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 15*89f7189bSGreg 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; 2306a438b4SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 246b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry; 2506a438b4SGreg Roachuse Fisharebest\Webtrees\GedcomRecord; 26e72c24d6SGreg Roachuse Fisharebest\Webtrees\I18N; 27e72c24d6SGreg Roachuse Fisharebest\Webtrees\Submitter; 28e72c24d6SGreg Roachuse Fisharebest\Webtrees\Tree; 29e72c24d6SGreg Roachuse Fisharebest\Webtrees\Auth; 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. */ 49e72c24d6SGreg Roach protected $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 { 83e72c24d6SGreg Roach /* I18N: Description of the “Shared 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 10906a438b4SGreg Roach * @param mixed[] $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 /** 121e72c24d6SGreg Roach * @return 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 { 15006a438b4SGreg Roach return redirect($this->listUrl($request->getAttribute('tree'), $request->getQueryParams())); 15106a438b4SGreg Roach } 15206a438b4SGreg Roach 15306a438b4SGreg Roach /** 15406a438b4SGreg Roach * @param ServerRequestInterface $request 15506a438b4SGreg Roach * 15606a438b4SGreg Roach * @return ResponseInterface 15706a438b4SGreg Roach */ 15806a438b4SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 15906a438b4SGreg Roach { 16006a438b4SGreg Roach $tree = $request->getAttribute('tree'); 16106a438b4SGreg Roach assert($tree instanceof Tree); 16206a438b4SGreg Roach 16306a438b4SGreg Roach $user = $request->getAttribute('user'); 16406a438b4SGreg Roach assert($user instanceof UserInterface); 16506a438b4SGreg Roach 16606a438b4SGreg Roach Auth::checkComponentAccess($this, ModuleListInterface::class, $tree, $user); 16706a438b4SGreg Roach 16806a438b4SGreg Roach $submitters = DB::table('other') 16906a438b4SGreg Roach ->where('o_file', '=', $tree->id()) 17006a438b4SGreg Roach ->where('o_type', '=', Submitter::RECORD_TYPE) 17106a438b4SGreg Roach ->get() 1726b9cb339SGreg Roach ->map(Registry::submitterFactory()->mapper($tree)) 17306a438b4SGreg Roach ->filter(GedcomRecord::accessFilter()); 17406a438b4SGreg Roach 17506a438b4SGreg Roach return $this->viewResponse('modules/submitter-list/page', [ 17606a438b4SGreg Roach 'submitters' => $submitters, 17706a438b4SGreg Roach 'title' => I18N::translate('Submitters'), 17806a438b4SGreg Roach 'tree' => $tree, 17906a438b4SGreg Roach ]); 18006a438b4SGreg Roach } 181e72c24d6SGreg Roach} 182