1*4c3563c0SGreg Roach<?php 2*4c3563c0SGreg Roach 3*4c3563c0SGreg Roach/** 4*4c3563c0SGreg Roach * webtrees: online genealogy 5*4c3563c0SGreg Roach * Copyright (C) 2021 webtrees development team 6*4c3563c0SGreg Roach * This program is free software: you can redistribute it and/or modify 7*4c3563c0SGreg Roach * it under the terms of the GNU General Public License as published by 8*4c3563c0SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*4c3563c0SGreg Roach * (at your option) any later version. 10*4c3563c0SGreg Roach * This program is distributed in the hope that it will be useful, 11*4c3563c0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*4c3563c0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*4c3563c0SGreg Roach * GNU General Public License for more details. 14*4c3563c0SGreg Roach * You should have received a copy of the GNU General Public License 15*4c3563c0SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*4c3563c0SGreg Roach */ 17*4c3563c0SGreg Roach 18*4c3563c0SGreg Roachdeclare(strict_types=1); 19*4c3563c0SGreg Roach 20*4c3563c0SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*4c3563c0SGreg Roach 22*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 23*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Exceptions\HttpNotFoundException; 24*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 25*4c3563c0SGreg Roachuse Fisharebest\Webtrees\I18N; 26*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Module\ModuleLanguageInterface; 27*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 28*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\MessageService; 29*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\ModuleService; 30*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 31*4c3563c0SGreg Roachuse Fisharebest\Webtrees\Services\UserService; 32*4c3563c0SGreg Roachuse Psr\Http\Message\ResponseInterface; 33*4c3563c0SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 34*4c3563c0SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 35*4c3563c0SGreg Roach 36*4c3563c0SGreg Roach/** 37*4c3563c0SGreg Roach * Edit a user. 38*4c3563c0SGreg Roach */ 39*4c3563c0SGreg Roachclass UserEditPage implements RequestHandlerInterface 40*4c3563c0SGreg Roach{ 41*4c3563c0SGreg Roach use ViewResponseTrait; 42*4c3563c0SGreg Roach 43*4c3563c0SGreg Roach /** @var MessageService */ 44*4c3563c0SGreg Roach private $message_service; 45*4c3563c0SGreg Roach 46*4c3563c0SGreg Roach /** @var ModuleService */ 47*4c3563c0SGreg Roach private $module_service; 48*4c3563c0SGreg Roach 49*4c3563c0SGreg Roach /** @var UserService */ 50*4c3563c0SGreg Roach private $user_service; 51*4c3563c0SGreg Roach 52*4c3563c0SGreg Roach /** @var TreeService */ 53*4c3563c0SGreg Roach private $tree_service; 54*4c3563c0SGreg Roach 55*4c3563c0SGreg Roach /** 56*4c3563c0SGreg Roach * UserEditPage constructor. 57*4c3563c0SGreg Roach * 58*4c3563c0SGreg Roach * @param MessageService $message_service 59*4c3563c0SGreg Roach * @param ModuleService $module_service 60*4c3563c0SGreg Roach * @param TreeService $tree_service 61*4c3563c0SGreg Roach * @param UserService $user_service 62*4c3563c0SGreg Roach */ 63*4c3563c0SGreg Roach public function __construct( 64*4c3563c0SGreg Roach MessageService $message_service, 65*4c3563c0SGreg Roach ModuleService $module_service, 66*4c3563c0SGreg Roach TreeService $tree_service, 67*4c3563c0SGreg Roach UserService $user_service 68*4c3563c0SGreg Roach ) { 69*4c3563c0SGreg Roach $this->message_service = $message_service; 70*4c3563c0SGreg Roach $this->module_service = $module_service; 71*4c3563c0SGreg Roach $this->tree_service = $tree_service; 72*4c3563c0SGreg Roach $this->user_service = $user_service; 73*4c3563c0SGreg Roach } 74*4c3563c0SGreg Roach 75*4c3563c0SGreg Roach /** 76*4c3563c0SGreg Roach * @param ServerRequestInterface $request 77*4c3563c0SGreg Roach * 78*4c3563c0SGreg Roach * @return ResponseInterface 79*4c3563c0SGreg Roach */ 80*4c3563c0SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 81*4c3563c0SGreg Roach { 82*4c3563c0SGreg Roach $this->layout = 'layouts/administration'; 83*4c3563c0SGreg Roach 84*4c3563c0SGreg Roach $user_id = (int) $request->getQueryParams()['user_id']; 85*4c3563c0SGreg Roach $user = $this->user_service->find($user_id); 86*4c3563c0SGreg Roach 87*4c3563c0SGreg Roach if ($user === null) { 88*4c3563c0SGreg Roach throw new HttpNotFoundException(I18N::translate('%1$s does not exist.', 'user_id:' . $user_id)); 89*4c3563c0SGreg Roach } 90*4c3563c0SGreg Roach 91*4c3563c0SGreg Roach $languages = $this->module_service->findByInterface(ModuleLanguageInterface::class, true, true) 92*4c3563c0SGreg Roach ->mapWithKeys(static function (ModuleLanguageInterface $module): array { 93*4c3563c0SGreg Roach $locale = $module->locale(); 94*4c3563c0SGreg Roach 95*4c3563c0SGreg Roach return [$locale->languageTag() => $locale->endonym()]; 96*4c3563c0SGreg Roach }); 97*4c3563c0SGreg Roach 98*4c3563c0SGreg Roach $roles = [ 99*4c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 100*4c3563c0SGreg Roach UserInterface::ROLE_VISITOR => I18N::translate('Visitor'), 101*4c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 102*4c3563c0SGreg Roach UserInterface::ROLE_MEMBER => I18N::translate('Member'), 103*4c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 104*4c3563c0SGreg Roach UserInterface::ROLE_EDITOR => I18N::translate('Editor'), 105*4c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 106*4c3563c0SGreg Roach UserInterface::ROLE_MODERATOR => I18N::translate('Moderator'), 107*4c3563c0SGreg Roach /* I18N: Listbox entry; name of a role */ 108*4c3563c0SGreg Roach UserInterface::ROLE_MANAGER => I18N::translate('Manager'), 109*4c3563c0SGreg Roach ]; 110*4c3563c0SGreg Roach 111*4c3563c0SGreg Roach $theme_options = $this->module_service 112*4c3563c0SGreg Roach ->findByInterface(ModuleThemeInterface::class) 113*4c3563c0SGreg Roach ->map($this->module_service->titleMapper()) 114*4c3563c0SGreg Roach ->prepend(I18N::translate('<default theme>'), ''); 115*4c3563c0SGreg Roach 116*4c3563c0SGreg Roach return $this->viewResponse('admin/users-edit', [ 117*4c3563c0SGreg Roach 'contact_methods' => $this->message_service->contactMethods(), 118*4c3563c0SGreg Roach 'default_language' => I18N::languageTag(), 119*4c3563c0SGreg Roach 'languages' => $languages->all(), 120*4c3563c0SGreg Roach 'roles' => $roles, 121*4c3563c0SGreg Roach 'trees' => $this->tree_service->all(), 122*4c3563c0SGreg Roach 'theme_options' => $theme_options, 123*4c3563c0SGreg Roach 'title' => I18N::translate('Edit the user'), 124*4c3563c0SGreg Roach 'user' => $user, 125*4c3563c0SGreg Roach ]); 126*4c3563c0SGreg Roach } 127*4c3563c0SGreg Roach} 128