14c3563c0SGreg Roach<?php 24c3563c0SGreg Roach 34c3563c0SGreg Roach/** 44c3563c0SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 64c3563c0SGreg Roach * This program is free software: you can redistribute it and/or modify 74c3563c0SGreg Roach * it under the terms of the GNU General Public License as published by 84c3563c0SGreg Roach * the Free Software Foundation, either version 3 of the License, or 94c3563c0SGreg Roach * (at your option) any later version. 104c3563c0SGreg Roach * This program is distributed in the hope that it will be useful, 114c3563c0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 124c3563c0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134c3563c0SGreg Roach * GNU General Public License for more details. 144c3563c0SGreg 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/>. 164c3563c0SGreg Roach */ 174c3563c0SGreg Roach 184c3563c0SGreg Roachdeclare(strict_types=1); 194c3563c0SGreg Roach 204c3563c0SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 214c3563c0SGreg Roach 224c3563c0SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 2381b729d3SGreg Roachuse Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException; 244c3563c0SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 254c3563c0SGreg Roachuse Fisharebest\Webtrees\I18N; 264c3563c0SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface; 274c3563c0SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 284c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\MessageService; 294c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 304c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 314c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 32748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator; 334c3563c0SGreg Roachuse Psr\Http\Message\ResponseInterface; 344c3563c0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 354c3563c0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 364c3563c0SGreg Roach 374c3563c0SGreg Roach/** 384c3563c0SGreg Roach * Edit a user. 394c3563c0SGreg Roach */ 404c3563c0SGreg Roachclass UserEditPage implements RequestHandlerInterface 414c3563c0SGreg Roach{ 424c3563c0SGreg Roach use ViewResponseTrait; 434c3563c0SGreg Roach 44c4943cffSGreg Roach private MessageService $message_service; 454c3563c0SGreg Roach 46c4943cffSGreg Roach private ModuleService $module_service; 474c3563c0SGreg Roach 48c4943cffSGreg Roach private UserService $user_service; 494c3563c0SGreg Roach 50c4943cffSGreg Roach private TreeService $tree_service; 514c3563c0SGreg Roach 524c3563c0SGreg Roach /** 534c3563c0SGreg Roach * @param MessageService $message_service 544c3563c0SGreg Roach * @param ModuleService $module_service 554c3563c0SGreg Roach * @param TreeService $tree_service 564c3563c0SGreg Roach * @param UserService $user_service 574c3563c0SGreg Roach */ 584c3563c0SGreg Roach public function __construct( 594c3563c0SGreg Roach MessageService $message_service, 604c3563c0SGreg Roach ModuleService $module_service, 614c3563c0SGreg Roach TreeService $tree_service, 624c3563c0SGreg Roach UserService $user_service 634c3563c0SGreg Roach ) { 644c3563c0SGreg Roach $this->message_service = $message_service; 654c3563c0SGreg Roach $this->module_service = $module_service; 664c3563c0SGreg Roach $this->tree_service = $tree_service; 674c3563c0SGreg Roach $this->user_service = $user_service; 684c3563c0SGreg Roach } 694c3563c0SGreg Roach 704c3563c0SGreg Roach /** 714c3563c0SGreg Roach * @param ServerRequestInterface $request 724c3563c0SGreg Roach * 734c3563c0SGreg Roach * @return ResponseInterface 744c3563c0SGreg Roach */ 754c3563c0SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 764c3563c0SGreg Roach { 774c3563c0SGreg Roach $this->layout = 'layouts/administration'; 784c3563c0SGreg Roach 79748dbe15SGreg Roach $user_id = Validator::queryParams($request)->integer('user_id'); 804c3563c0SGreg Roach $user = $this->user_service->find($user_id); 814c3563c0SGreg Roach 824c3563c0SGreg Roach if ($user === null) { 834566681eSGreg Roach throw new HttpNotFoundException(I18N::translate('%s does not exist.', 'user_id:' . $user_id)); 844c3563c0SGreg Roach } 854c3563c0SGreg Roach 864c3563c0SGreg Roach $languages = $this->module_service->findByInterface(ModuleLanguageInterface::class, true, true) 874c3563c0SGreg Roach ->mapWithKeys(static function (ModuleLanguageInterface $module): array { 884c3563c0SGreg Roach $locale = $module->locale(); 894c3563c0SGreg Roach 904c3563c0SGreg Roach return [$locale->languageTag() => $locale->endonym()]; 914c3563c0SGreg Roach }); 924c3563c0SGreg Roach 934c3563c0SGreg Roach $roles = [ 944c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 954c3563c0SGreg Roach UserInterface::ROLE_VISITOR => I18N::translate('Visitor'), 964c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 974c3563c0SGreg Roach UserInterface::ROLE_MEMBER => I18N::translate('Member'), 984c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 994c3563c0SGreg Roach UserInterface::ROLE_EDITOR => I18N::translate('Editor'), 1004c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 1014c3563c0SGreg Roach UserInterface::ROLE_MODERATOR => I18N::translate('Moderator'), 1024c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 1034c3563c0SGreg Roach UserInterface::ROLE_MANAGER => I18N::translate('Manager'), 1044c3563c0SGreg Roach ]; 1054c3563c0SGreg Roach 1064c3563c0SGreg Roach $theme_options = $this->module_service 1074c3563c0SGreg Roach ->findByInterface(ModuleThemeInterface::class) 1084c3563c0SGreg Roach ->map($this->module_service->titleMapper()) 1094c3563c0SGreg Roach ->prepend(I18N::translate('<default theme>'), ''); 1104c3563c0SGreg Roach 1114c3563c0SGreg Roach return $this->viewResponse('admin/users-edit', [ 1124c3563c0SGreg Roach 'contact_methods' => $this->message_service->contactMethods(), 1134c3563c0SGreg Roach 'default_language' => I18N::languageTag(), 1144c3563c0SGreg Roach 'languages' => $languages->all(), 1154c3563c0SGreg Roach 'roles' => $roles, 1164c3563c0SGreg Roach 'trees' => $this->tree_service->all(), 1174c3563c0SGreg Roach 'theme_options' => $theme_options, 1184c3563c0SGreg Roach 'title' => I18N::translate('Edit the user'), 1194c3563c0SGreg Roach 'user' => $user, 1204c3563c0SGreg Roach ]); 1214c3563c0SGreg Roach } 1224c3563c0SGreg Roach} 123