xref: /webtrees/app/Http/RequestHandlers/SelectDefaultTree.php (revision d11be7027e34e3121be11cc025421873364403f9)
1da1c67ccSGreg Roach<?php
2da1c67ccSGreg Roach
3da1c67ccSGreg Roach/**
4da1c67ccSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg Roach * along with this program. If not, see <https://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;
26b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator;
27da1c67ccSGreg Roachuse Psr\Http\Message\ResponseInterface;
28da1c67ccSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
29da1c67ccSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
30da1c67ccSGreg Roach
31da1c67ccSGreg Roachuse function e;
32da1c67ccSGreg Roachuse function redirect;
33da1c67ccSGreg Roachuse function route;
34da1c67ccSGreg Roach
35da1c67ccSGreg Roach/**
36da1c67ccSGreg Roach * Set the default tree.
37da1c67ccSGreg Roach */
38da1c67ccSGreg Roachclass SelectDefaultTree implements RequestHandlerInterface, StatusCodeInterface
39da1c67ccSGreg Roach{
40da1c67ccSGreg Roach    /**
41da1c67ccSGreg Roach     * @param ServerRequestInterface $request
42da1c67ccSGreg Roach     *
43da1c67ccSGreg Roach     * @return ResponseInterface
44da1c67ccSGreg Roach     */
45da1c67ccSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
46da1c67ccSGreg Roach    {
47b55cbc6bSGreg Roach        $tree = Validator::attributes($request)->tree();
48da1c67ccSGreg Roach
49da1c67ccSGreg Roach        Site::setPreference('DEFAULT_GEDCOM', $tree->name());
50da1c67ccSGreg Roach
51da1c67ccSGreg Roach        /* I18N: %s is the name of a family tree */
52da1c67ccSGreg Roach        $message = I18N::translate('The family tree “%s” will be shown to visitors when they first arrive at this website.', e($tree->title()));
53da1c67ccSGreg Roach
54da1c67ccSGreg Roach        FlashMessages::addMessage($message, 'success');
55da1c67ccSGreg Roach
566fd01894SGreg Roach        $url = route(ManageTrees::class, ['tree' => $tree->name()]);
57da1c67ccSGreg Roach
58da1c67ccSGreg Roach        return redirect($url);
59da1c67ccSGreg Roach    }
60da1c67ccSGreg Roach}
61