xref: /webtrees/app/Http/RequestHandlers/SiteTagsPage.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\Gedcom;
23use Fisharebest\Webtrees\Http\ViewResponseTrait;
24use Fisharebest\Webtrees\I18N;
25use Fisharebest\Webtrees\Registry;
26use Fisharebest\Webtrees\Site;
27use Illuminate\Support\Collection;
28use Psr\Http\Message\ResponseInterface;
29use Psr\Http\Message\ServerRequestInterface;
30use Psr\Http\Server\RequestHandlerInterface;
31
32use function explode;
33
34/**
35 * Edit the tree preferences.
36 */
37class SiteTagsPage implements RequestHandlerInterface
38{
39    use ViewResponseTrait;
40
41    /**
42     * @param ServerRequestInterface $request
43     *
44     * @return ResponseInterface
45     */
46    public function handle(ServerRequestInterface $request): ResponseInterface
47    {
48        $this->layout = 'layouts/administration';
49
50        $custom_family_tags      = explode(',', Site::getPreference('CUSTOM_FAMILY_TAGS'));
51        $custom_individual_tags  = explode(',', Site::getPreference('CUSTOM_INDIVIDUAL_TAGS'));
52
53        $all_family_tags = new Collection(Gedcom::CUSTOM_FAMILY_TAGS);
54        $all_individual_tags = new Collection(Gedcom::CUSTOM_INDIVIDUAL_TAGS);
55
56        $all_family_tags = $all_family_tags->mapWithKeys(
57            static fn (string $tag): array => [$tag => Registry::elementFactory()->make('FAM:' . $tag)->label() . ' - ' . $tag]
58        );
59
60        $all_individual_tags = $all_individual_tags->mapWithKeys(
61            static fn (string $tag): array => [$tag => Registry::elementFactory()->make('INDI:' . $tag)->label() . ' - ' . $tag]
62        );
63
64        $custom_gedcom_l_tags = (bool) Site::getPreference('CUSTOM_GEDCOM_L_TAGS');
65
66        // GEDCOM 7 extensions
67        $custom_fam_fact      = (bool) Site::getPreference('CUSTOM_FAM_FACT');
68        $custom_fam_nchi      = (bool) Site::getPreference('CUSTOM_FAM_NCHI');
69        $custom_resi_value    = (bool) Site::getPreference('CUSTOM_RESI_VALUE');
70        $custom_time_tags     = (bool) Site::getPreference('CUSTOM_TIME_TAGS');
71
72        return $this->viewResponse('admin/tags', [
73            'all_family_tags'        => $all_family_tags->sort()->all(),
74            'all_individual_tags'    => $all_individual_tags->sort()->all(),
75            'custom_family_tags'     => $custom_family_tags,
76            'custom_gedcom_l_tags'   => $custom_gedcom_l_tags,
77            'custom_individual_tags' => $custom_individual_tags,
78            'custom_fam_fact'        => $custom_fam_fact,
79            'custom_fam_nchi'        => $custom_fam_nchi,
80            'custom_resi_value'      => $custom_resi_value,
81            'custom_time_tags'       => $custom_time_tags,
82            'element_factory'        => Registry::elementFactory(),
83            'title'                  => I18N::translate('GEDCOM tags'),
84        ]);
85    }
86}
87