1*8e0e1b25SGreg Roach<?php 2*8e0e1b25SGreg Roach 3*8e0e1b25SGreg Roach/** 4*8e0e1b25SGreg Roach * webtrees: online genealogy 5*8e0e1b25SGreg Roach * Copyright (C) 2019 webtrees development team 6*8e0e1b25SGreg Roach * This program is free software: you can redistribute it and/or modify 7*8e0e1b25SGreg Roach * it under the terms of the GNU General Public License as published by 8*8e0e1b25SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*8e0e1b25SGreg Roach * (at your option) any later version. 10*8e0e1b25SGreg Roach * This program is distributed in the hope that it will be useful, 11*8e0e1b25SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*8e0e1b25SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*8e0e1b25SGreg Roach * GNU General Public License for more details. 14*8e0e1b25SGreg Roach * You should have received a copy of the GNU General Public License 15*8e0e1b25SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*8e0e1b25SGreg Roach */ 17*8e0e1b25SGreg Roach 18*8e0e1b25SGreg Roachdeclare(strict_types=1); 19*8e0e1b25SGreg Roach 20*8e0e1b25SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*8e0e1b25SGreg Roach 22*8e0e1b25SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 23*8e0e1b25SGreg Roachuse Fisharebest\Webtrees\I18N; 24*8e0e1b25SGreg Roachuse Fisharebest\Webtrees\Services\HomePageService; 25*8e0e1b25SGreg Roachuse Fisharebest\Webtrees\Tree; 26*8e0e1b25SGreg Roachuse Psr\Http\Message\ResponseInterface; 27*8e0e1b25SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 28*8e0e1b25SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 29*8e0e1b25SGreg Roach 30*8e0e1b25SGreg Roachuse function assert; 31*8e0e1b25SGreg Roachuse function route; 32*8e0e1b25SGreg Roach 33*8e0e1b25SGreg Roach/** 34*8e0e1b25SGreg Roach * Controller for the user/tree's home page. 35*8e0e1b25SGreg Roach */ 36*8e0e1b25SGreg Roachclass UserPageBlockEdit implements RequestHandlerInterface 37*8e0e1b25SGreg Roach{ 38*8e0e1b25SGreg Roach use ViewResponseTrait; 39*8e0e1b25SGreg Roach 40*8e0e1b25SGreg Roach /** @var HomePageService */ 41*8e0e1b25SGreg Roach private $home_page_service; 42*8e0e1b25SGreg Roach 43*8e0e1b25SGreg Roach /** 44*8e0e1b25SGreg Roach * HomePageController constructor. 45*8e0e1b25SGreg Roach * 46*8e0e1b25SGreg Roach * @param HomePageService $home_page_service 47*8e0e1b25SGreg Roach */ 48*8e0e1b25SGreg Roach public function __construct(HomePageService $home_page_service) 49*8e0e1b25SGreg Roach { 50*8e0e1b25SGreg Roach $this->home_page_service = $home_page_service; 51*8e0e1b25SGreg Roach } 52*8e0e1b25SGreg Roach 53*8e0e1b25SGreg Roach /** 54*8e0e1b25SGreg Roach * Show a form to edit block config options. 55*8e0e1b25SGreg Roach * 56*8e0e1b25SGreg Roach * @param ServerRequestInterface $request 57*8e0e1b25SGreg Roach * 58*8e0e1b25SGreg Roach * @return ResponseInterface 59*8e0e1b25SGreg Roach */ 60*8e0e1b25SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 61*8e0e1b25SGreg Roach { 62*8e0e1b25SGreg Roach $tree = $request->getAttribute('tree'); 63*8e0e1b25SGreg Roach assert($tree instanceof Tree); 64*8e0e1b25SGreg Roach 65*8e0e1b25SGreg Roach $user = $request->getAttribute('user'); 66*8e0e1b25SGreg Roach $block_id = (int) $request->getQueryParams()['block_id']; 67*8e0e1b25SGreg Roach $block = $this->home_page_service->userBlock($request, $user); 68*8e0e1b25SGreg Roach $title = $block->title() . ' — ' . I18N::translate('Preferences'); 69*8e0e1b25SGreg Roach 70*8e0e1b25SGreg Roach return $this->viewResponse('modules/edit-block-config', [ 71*8e0e1b25SGreg Roach 'block' => $block, 72*8e0e1b25SGreg Roach 'block_id' => $block_id, 73*8e0e1b25SGreg Roach 'cancel_url' => route(UserPage::class, ['tree' => $tree->name()]), 74*8e0e1b25SGreg Roach 'title' => $title, 75*8e0e1b25SGreg Roach 'tree' => $tree, 76*8e0e1b25SGreg Roach ]); 77*8e0e1b25SGreg Roach } 78*8e0e1b25SGreg Roach} 79