xref: /webtrees/app/Elements/RestrictionNotice.php (revision 35e7ad0c309aa084344904fc9471036d7c215055)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 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\Elements;
21
22use Fisharebest\Webtrees\I18N;
23
24use function strtoupper;
25
26/**
27 * RESTRICTION_NOTICE := {Size=6:7}
28 * [confidential | locked | privacy ]
29 * The restriction notice is defined for Ancestral File usage. Ancestral File
30 * download GEDCOM files may contain this data.
31 * Where:
32 * confidential = This data was marked as confidential by the user. In some systems data marked as
33 *                confidential will be treated differently, for example, there might be an option
34 *                that would stop confidential data from appearing on printed reports or would
35 *                prevent that information from being exported.
36 * locked       = Some records in Ancestral File have been satisfactorily proven by evidence, but
37 *                because of source conflicts or incorrect traditions, there are repeated attempts
38 *                to change this record. By arrangement, the Ancestral File Custodian can lock a
39 *                record so that it cannot be changed without an agreement from the person assigned
40 *                as the steward of such a record. The assigned steward is either the submitter
41 *                listed for the record or Family History Support when no submitter is listed.
42 * privacy      = Indicate that information concerning this record is not present due to rights of
43 *                or an approved request for privacy. For example, data from requested downloads of
44 *                the Ancestral File may have individuals marked with ‘privacy’ if they are assumed
45 *                living, that is they were born within the last 110 years and there isn’t a death
46 *                date. In certain cases family records may also be marked with the RESN tag of
47 *                privacy if either individual acting in the role of HUSB or WIFE is assumed living.
48 */
49class RestrictionNotice extends AbstractElement
50{
51    public const VALUE_NONE         = 'NONE';
52    public const VALUE_PRIVACY      = 'PRIVACY';
53    public const VALUE_CONFIDENTIAL = 'CONFIDENTIAL';
54    public const VALUE_LOCKED       = 'LOCKED';
55
56    private const CANONICAL = [
57        // Store the locked value after the privacy value.
58        self::VALUE_LOCKED . ', ' . self::VALUE_NONE         => self::VALUE_NONE . ', ' . self::VALUE_LOCKED,
59        self::VALUE_LOCKED . ', ' . self::VALUE_PRIVACY      => self::VALUE_PRIVACY . ', ' . self::VALUE_LOCKED,
60        self::VALUE_LOCKED . ', ' . self::VALUE_CONFIDENTIAL => self::VALUE_CONFIDENTIAL . ', ' . self::VALUE_LOCKED,
61        // Old versions of Legacy
62        'invisible'                                          => self::VALUE_PRIVACY,
63    ];
64
65    /**
66     * Convert a value to a canonical form.
67     *
68     * @param string $value
69     *
70     * @return string
71     */
72    public function canonical(string $value): string
73    {
74        $value = strtoupper(parent::canonical($value));
75        $value = trim($value, ', ');
76        $value = preg_replace('/[, ]+/', ', ', $value);
77
78        return self::CANONICAL[$value] ?? $value;
79    }
80
81    /**
82     * A list of controlled values for this element
83     *
84     * @return array<int|string,string>
85     */
86    public function values(): array
87    {
88        // Note: "1 RESN none" is not valid gedcom.
89        // However, webtrees privacy rules will interpret it as "show an otherwise private record to public".
90
91        return [
92            ''                                                   => '',
93            self::VALUE_NONE                                     => '<i class="icon-resn-none"></i> ' . I18N::translate('Show to visitors'),
94            self::VALUE_NONE . ', ' . self::VALUE_LOCKED         => '<i class="icon-resn-none"><i class="icon-resn-locked"></i> ' . I18N::translate('Show to visitors') . ' — ' . I18N::translate('Only managers can edit'),
95            self::VALUE_PRIVACY                                  => '<i class="icon-resn-privacy"></i> ' . I18N::translate('Show to members'),
96            self::VALUE_PRIVACY . ', ' . self::VALUE_LOCKED      => '<i class="icon-resn-privacy"><i class="icon-resn-locked"></i> ' . I18N::translate('Show to members') . ' — ' . I18N::translate('Only managers can edit'),
97            self::VALUE_CONFIDENTIAL                             => '<i class="icon-resn-confidential"></i> ' . I18N::translate('Show to managers'),
98            self::VALUE_CONFIDENTIAL . ', ' . self::VALUE_LOCKED => '<i class="icon-resn-confidential"><i class="icon-resn-locked"></i> ' . I18N::translate('Show to managers') . ' — ' . I18N::translate('Only managers can edit'),
99            self::VALUE_LOCKED                                   => '<i class="icon-resn-locked"></i> ' . I18N::translate('Only managers can edit'),
100        ];
101    }
102}
103