xref: /webtrees/app/Http/RequestHandlers/SiteTagsAction.php (revision d11be7027e34e3121be11cc025421873364403f9)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Http\RequestHandlers;
21
22use Fisharebest\Webtrees\FlashMessages;
23use Fisharebest\Webtrees\Gedcom;
24use Fisharebest\Webtrees\I18N;
25use Fisharebest\Webtrees\Site;
26use Fisharebest\Webtrees\Validator;
27use Psr\Http\Message\ResponseInterface;
28use Psr\Http\Message\ServerRequestInterface;
29use Psr\Http\Server\RequestHandlerInterface;
30
31use function array_keys;
32use function implode;
33use function redirect;
34use function route;
35
36/**
37 * Edit the tree preferences.
38 */
39class SiteTagsAction implements RequestHandlerInterface
40{
41    /**
42     * @param ServerRequestInterface $request
43     *
44     * @return ResponseInterface
45     */
46    public function handle(ServerRequestInterface $request): ResponseInterface
47    {
48        foreach (array_keys(Gedcom::HIDDEN_TAGS) as $setting) {
49            $value = Validator::parsedBody($request)->boolean('HIDE_' . $setting, false);
50            Site::setPreference('HIDE_' . $setting, (string) $value);
51        }
52
53        $custom_family_tags     = Validator::parsedBody($request)->array('custom_family_tags');
54        $custom_individual_tags = Validator::parsedBody($request)->array('custom_individual_tags');
55        $custom_gedcom_l_tags   = Validator::parsedBody($request)->boolean('custom_gedcom_l_tags', false);
56        $custom_fam_fact        = Validator::parsedBody($request)->boolean('custom_fam_fact', false);
57        $custom_fam_nchi        = Validator::parsedBody($request)->boolean('custom_fam_nchi', false);
58        $custom_resi_value      = Validator::parsedBody($request)->boolean('custom_resi_value', false);
59        $custom_time_tags       = Validator::parsedBody($request)->boolean('custom_time_tags', false);
60
61        Site::setPreference('CUSTOM_FAMILY_TAGS', implode(',', $custom_family_tags));
62        Site::setPreference('CUSTOM_INDIVIDUAL_TAGS', implode(',', $custom_individual_tags));
63        Site::setPreference('CUSTOM_GEDCOM_L_TAGS', (string) $custom_gedcom_l_tags);
64        Site::setPreference('CUSTOM_FAM_FACT', (string) $custom_fam_fact);
65        Site::setPreference('CUSTOM_FAM_NCHI', (string) $custom_fam_nchi);
66        Site::setPreference('CUSTOM_RESI_VALUE', (string) $custom_resi_value);
67        Site::setPreference('CUSTOM_TIME_TAGS', (string) $custom_time_tags);
68
69        FlashMessages::addMessage(I18N::translate('The website preferences have been updated.'), 'success');
70
71        return redirect(route(ControlPanel::class));
72    }
73}
74