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\Services\HomePageService; 23*8e0e1b25SGreg Roachuse Fisharebest\Webtrees\Tree; 24*8e0e1b25SGreg Roachuse Psr\Http\Message\ResponseInterface; 25*8e0e1b25SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 26*8e0e1b25SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 27*8e0e1b25SGreg Roach 28*8e0e1b25SGreg Roachuse function assert; 29*8e0e1b25SGreg Roachuse function redirect; 30*8e0e1b25SGreg Roachuse function route; 31*8e0e1b25SGreg Roach 32*8e0e1b25SGreg Roach/** 33*8e0e1b25SGreg Roach * Controller for the user/tree's home page. 34*8e0e1b25SGreg Roach */ 35*8e0e1b25SGreg Roachclass UserPageBlockUpdate implements RequestHandlerInterface 36*8e0e1b25SGreg Roach{ 37*8e0e1b25SGreg Roach /** @var HomePageService */ 38*8e0e1b25SGreg Roach private $home_page_service; 39*8e0e1b25SGreg Roach 40*8e0e1b25SGreg Roach /** 41*8e0e1b25SGreg Roach * HomePageController constructor. 42*8e0e1b25SGreg Roach * 43*8e0e1b25SGreg Roach * @param HomePageService $home_page_service 44*8e0e1b25SGreg Roach */ 45*8e0e1b25SGreg Roach public function __construct(HomePageService $home_page_service) 46*8e0e1b25SGreg Roach { 47*8e0e1b25SGreg Roach $this->home_page_service = $home_page_service; 48*8e0e1b25SGreg Roach } 49*8e0e1b25SGreg Roach 50*8e0e1b25SGreg Roach /** 51*8e0e1b25SGreg Roach * Update block config options. 52*8e0e1b25SGreg Roach * 53*8e0e1b25SGreg Roach * @param ServerRequestInterface $request 54*8e0e1b25SGreg Roach * 55*8e0e1b25SGreg Roach * @return ResponseInterface 56*8e0e1b25SGreg Roach */ 57*8e0e1b25SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 58*8e0e1b25SGreg Roach { 59*8e0e1b25SGreg Roach $tree = $request->getAttribute('tree'); 60*8e0e1b25SGreg Roach assert($tree instanceof Tree); 61*8e0e1b25SGreg Roach 62*8e0e1b25SGreg Roach $user = $request->getAttribute('user'); 63*8e0e1b25SGreg Roach $block = $this->home_page_service->userBlock($request, $user); 64*8e0e1b25SGreg Roach $block_id = (int) $request->getQueryParams()['block_id']; 65*8e0e1b25SGreg Roach 66*8e0e1b25SGreg Roach $block->saveBlockConfiguration($request, $block_id); 67*8e0e1b25SGreg Roach 68*8e0e1b25SGreg Roach return redirect(route(UserPage::class, ['tree' => $tree->name()])); 69*8e0e1b25SGreg Roach } 70*8e0e1b25SGreg Roach} 71