xref: /webtrees/app/Elements/RestrictionNotice.php (revision d11be7027e34e3121be11cc025421873364403f9)
1c2ed51d1SGreg Roach<?php
2c2ed51d1SGreg Roach
3c2ed51d1SGreg Roach/**
4c2ed51d1SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6c2ed51d1SGreg Roach * This program is free software: you can redistribute it and/or modify
7c2ed51d1SGreg Roach * it under the terms of the GNU General Public License as published by
8c2ed51d1SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9c2ed51d1SGreg Roach * (at your option) any later version.
10c2ed51d1SGreg Roach * This program is distributed in the hope that it will be useful,
11c2ed51d1SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12c2ed51d1SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13c2ed51d1SGreg Roach * GNU General Public License for more details.
14c2ed51d1SGreg Roach * You should have received a copy of the GNU General Public License
15c2ed51d1SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16c2ed51d1SGreg Roach */
17c2ed51d1SGreg Roach
18c2ed51d1SGreg Roachdeclare(strict_types=1);
19c2ed51d1SGreg Roach
20c2ed51d1SGreg Roachnamespace Fisharebest\Webtrees\Elements;
21c2ed51d1SGreg Roach
22c2ed51d1SGreg Roachuse Fisharebest\Webtrees\I18N;
23c2ed51d1SGreg Roach
24da7adf56SGreg Roachuse function strtoupper;
25c2ed51d1SGreg Roach
26c2ed51d1SGreg Roach/**
27c2ed51d1SGreg Roach * RESTRICTION_NOTICE := {Size=6:7}
28c2ed51d1SGreg Roach * [confidential | locked | privacy ]
29c2ed51d1SGreg Roach * The restriction notice is defined for Ancestral File usage. Ancestral File
30c2ed51d1SGreg Roach * download GEDCOM files may contain this data.
31c2ed51d1SGreg Roach * Where:
32c2ed51d1SGreg Roach * confidential = This data was marked as confidential by the user. In some systems data marked as
33c2ed51d1SGreg Roach *                confidential will be treated differently, for example, there might be an option
34c2ed51d1SGreg Roach *                that would stop confidential data from appearing on printed reports or would
35c2ed51d1SGreg Roach *                prevent that information from being exported.
36c2ed51d1SGreg Roach * locked       = Some records in Ancestral File have been satisfactorily proven by evidence, but
37c2ed51d1SGreg Roach *                because of source conflicts or incorrect traditions, there are repeated attempts
38c2ed51d1SGreg Roach *                to change this record. By arrangement, the Ancestral File Custodian can lock a
39c2ed51d1SGreg Roach *                record so that it cannot be changed without an agreement from the person assigned
40c2ed51d1SGreg Roach *                as the steward of such a record. The assigned steward is either the submitter
41c2ed51d1SGreg Roach *                listed for the record or Family History Support when no submitter is listed.
42c2ed51d1SGreg Roach * privacy      = Indicate that information concerning this record is not present due to rights of
43c2ed51d1SGreg Roach *                or an approved request for privacy. For example, data from requested downloads of
44c2ed51d1SGreg Roach *                the Ancestral File may have individuals marked with ‘privacy’ if they are assumed
45c2ed51d1SGreg Roach *                living, that is they were born within the last 110 years and there isn’t a death
46c2ed51d1SGreg Roach *                date. In certain cases family records may also be marked with the RESN tag of
47c2ed51d1SGreg Roach *                privacy if either individual acting in the role of HUSB or WIFE is assumed living.
48c2ed51d1SGreg Roach */
49c2ed51d1SGreg Roachclass RestrictionNotice extends AbstractElement
50c2ed51d1SGreg Roach{
51da7adf56SGreg Roach    public const VALUE_NONE         = 'NONE';
52da7adf56SGreg Roach    public const VALUE_PRIVACY      = 'PRIVACY';
53da7adf56SGreg Roach    public const VALUE_CONFIDENTIAL = 'CONFIDENTIAL';
54da7adf56SGreg Roach    public const VALUE_LOCKED       = 'LOCKED';
5529e1664cSGreg Roach
567503bfb6SGreg Roach    private const CANONICAL = [
5735e7ad0cSGreg Roach        // Store the locked value after the privacy value.
5888a03560SGreg Roach        self::VALUE_LOCKED . ', ' . self::VALUE_NONE         => self::VALUE_NONE . ', ' . self::VALUE_LOCKED,
5988a03560SGreg Roach        self::VALUE_LOCKED . ', ' . self::VALUE_PRIVACY      => self::VALUE_PRIVACY . ', ' . self::VALUE_LOCKED,
6088a03560SGreg Roach        self::VALUE_LOCKED . ', ' . self::VALUE_CONFIDENTIAL => self::VALUE_CONFIDENTIAL . ', ' . self::VALUE_LOCKED,
6135e7ad0cSGreg Roach        // Old versions of Legacy
6235e7ad0cSGreg Roach        'invisible'                                          => self::VALUE_PRIVACY,
637503bfb6SGreg Roach    ];
647503bfb6SGreg Roach
6569e77fbeSGreg Roach    private const ICON_CONFIDENTIAL = '<i class="icon-resn-confidential"></i>';
6669e77fbeSGreg Roach    private const ICON_LOCKED       = '<i class="icon-resn-locked"></i> ';
6769e77fbeSGreg Roach    private const ICON_NONE         = '<i class="icon-resn-none"></i>';
68f99bbb61SGreg Roach    private const ICON_PRIVACY      = '<i class="icon-resn-privacy"></i>';
6969e77fbeSGreg Roach
70c2ed51d1SGreg Roach    /**
71c2ed51d1SGreg Roach     * Convert a value to a canonical form.
72c2ed51d1SGreg Roach     *
73c2ed51d1SGreg Roach     * @param string $value
74c2ed51d1SGreg Roach     *
75c2ed51d1SGreg Roach     * @return string
76c2ed51d1SGreg Roach     */
77c2ed51d1SGreg Roach    public function canonical(string $value): string
78c2ed51d1SGreg Roach    {
79da7adf56SGreg Roach        $value = strtoupper(parent::canonical($value));
807503bfb6SGreg Roach        $value = trim($value, ', ');
817503bfb6SGreg Roach        $value = preg_replace('/[, ]+/', ', ', $value);
827503bfb6SGreg Roach
837503bfb6SGreg Roach        return self::CANONICAL[$value] ?? $value;
84c2ed51d1SGreg Roach    }
85c2ed51d1SGreg Roach
86c2ed51d1SGreg Roach    /**
87c2ed51d1SGreg Roach     * A list of controlled values for this element
88c2ed51d1SGreg Roach     *
89c2ed51d1SGreg Roach     * @return array<int|string,string>
90c2ed51d1SGreg Roach     */
91c2ed51d1SGreg Roach    public function values(): array
92c2ed51d1SGreg Roach    {
93c2ed51d1SGreg Roach        // Note: "1 RESN none" is not valid gedcom.
94c2ed51d1SGreg Roach        // However, webtrees privacy rules will interpret it as "show an otherwise private record to public".
95c2ed51d1SGreg Roach
9669e77fbeSGreg Roach        $confidential = I18N::translate('Show to managers');
9769e77fbeSGreg Roach        $locked       = I18N::translate('Only managers can edit');
9869e77fbeSGreg Roach        $none         = I18N::translate('Show to visitors');
9969e77fbeSGreg Roach        $privacy      = I18N::translate('Show to members');
10069e77fbeSGreg Roach
101c2ed51d1SGreg Roach        return [
102c2ed51d1SGreg Roach            ''                                                   => '',
10369e77fbeSGreg Roach            self::VALUE_NONE                                     => self::ICON_NONE . ' ' . $none,
10469e77fbeSGreg Roach            self::VALUE_NONE . ', ' . self::VALUE_LOCKED         => self::ICON_NONE . self::ICON_LOCKED . ' ' . $none . ' — ' . $locked,
10569e77fbeSGreg Roach            self::VALUE_PRIVACY                                  => self::ICON_PRIVACY . ' ' . $privacy,
10669e77fbeSGreg Roach            self::VALUE_PRIVACY . ', ' . self::VALUE_LOCKED      => self::ICON_PRIVACY . self::ICON_LOCKED . ' ' . $privacy . ' — ' . $locked,
10769e77fbeSGreg Roach            self::VALUE_CONFIDENTIAL                             => self::ICON_CONFIDENTIAL . ' ' . $confidential,
10869e77fbeSGreg Roach            self::VALUE_CONFIDENTIAL . ', ' . self::VALUE_LOCKED => self::ICON_CONFIDENTIAL . ' ' . self::ICON_LOCKED . ' ' . $confidential . ' — ' . $locked,
10969e77fbeSGreg Roach            self::VALUE_LOCKED                                   => self::ICON_LOCKED . ' ' . $locked,
110c2ed51d1SGreg Roach        ];
111c2ed51d1SGreg Roach    }
112c2ed51d1SGreg Roach}
113