1da1c67ccSGreg Roach<?php 2da1c67ccSGreg Roach 3da1c67ccSGreg Roach/** 4da1c67ccSGreg Roach * webtrees: online genealogy 5da1c67ccSGreg Roach * Copyright (C) 2019 webtrees development team 6da1c67ccSGreg Roach * This program is free software: you can redistribute it and/or modify 7da1c67ccSGreg Roach * it under the terms of the GNU General Public License as published by 8da1c67ccSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9da1c67ccSGreg Roach * (at your option) any later version. 10da1c67ccSGreg Roach * This program is distributed in the hope that it will be useful, 11da1c67ccSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12da1c67ccSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13da1c67ccSGreg Roach * GNU General Public License for more details. 14da1c67ccSGreg Roach * You should have received a copy of the GNU General Public License 15da1c67ccSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16da1c67ccSGreg Roach */ 17fcfa147eSGreg Roach 18da1c67ccSGreg Roachdeclare(strict_types=1); 19da1c67ccSGreg Roach 20da1c67ccSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21da1c67ccSGreg Roach 22da1c67ccSGreg Roachuse Fig\Http\Message\StatusCodeInterface; 23da1c67ccSGreg Roachuse Fisharebest\Webtrees\FlashMessages; 24da1c67ccSGreg Roachuse Fisharebest\Webtrees\I18N; 25da1c67ccSGreg Roachuse Fisharebest\Webtrees\Site; 26da1c67ccSGreg Roachuse Fisharebest\Webtrees\Tree; 27da1c67ccSGreg Roachuse Psr\Http\Message\ResponseInterface; 28da1c67ccSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29da1c67ccSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30da1c67ccSGreg Roach 31da1c67ccSGreg Roachuse function assert; 32da1c67ccSGreg Roachuse function e; 33da1c67ccSGreg Roachuse function redirect; 34da1c67ccSGreg Roachuse function route; 35da1c67ccSGreg Roach 36da1c67ccSGreg Roach/** 37da1c67ccSGreg Roach * Set the default tree. 38da1c67ccSGreg Roach */ 39da1c67ccSGreg Roachclass SelectDefaultTree implements RequestHandlerInterface, StatusCodeInterface 40da1c67ccSGreg Roach{ 41da1c67ccSGreg Roach /** 42da1c67ccSGreg Roach * @param ServerRequestInterface $request 43da1c67ccSGreg Roach * 44da1c67ccSGreg Roach * @return ResponseInterface 45da1c67ccSGreg Roach */ 46da1c67ccSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 47da1c67ccSGreg Roach { 48da1c67ccSGreg Roach $tree = $request->getAttribute('tree'); 49*75964c75SGreg Roach assert($tree instanceof Tree); 50da1c67ccSGreg Roach 51da1c67ccSGreg Roach Site::setPreference('DEFAULT_GEDCOM', $tree->name()); 52da1c67ccSGreg Roach 53da1c67ccSGreg Roach /* I18N: %s is the name of a family tree */ 54da1c67ccSGreg Roach $message = I18N::translate('The family tree “%s” will be shown to visitors when they first arrive at this website.', e($tree->title())); 55da1c67ccSGreg Roach 56da1c67ccSGreg Roach FlashMessages::addMessage($message, 'success'); 57da1c67ccSGreg Roach 58da1c67ccSGreg Roach $url = route('manage-trees', ['tree' => $tree->name()]); 59da1c67ccSGreg Roach 60da1c67ccSGreg Roach return redirect($url); 61da1c67ccSGreg Roach } 62da1c67ccSGreg Roach} 63