xref: /webtrees/app/Elements/RestrictionNotice.php (revision 88a035604b5083c54cbfbe51294b65fe8cf9a5ed)
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 strtolower;
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    // Store the locked value after the privacy value.
57    private const CANONICAL = [
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    ];
62
63    /**
64     * Convert a value to a canonical form.
65     *
66     * @param string $value
67     *
68     * @return string
69     */
70    public function canonical(string $value): string
71    {
72        $value = strtolower(parent::canonical($value));
73        $value = trim($value, ', ');
74        $value = preg_replace('/[, ]+/', ', ', $value);
75
76        return self::CANONICAL[$value] ?? $value;
77    }
78
79    /**
80     * A list of controlled values for this element
81     *
82     * @return array<int|string,string>
83     */
84    public function values(): array
85    {
86        // Note: "1 RESN none" is not valid gedcom.
87        // However, webtrees privacy rules will interpret it as "show an otherwise private record to public".
88
89        return [
90            ''                       => '',
91            self::VALUE_NONE         => '<i class="icon-resn-none"></i> ' . I18N::translate('Show to visitors'),
92            self::VALUE_PRIVACY      => '<i class="icon-resn-privacy"></i> ' . I18N::translate('Show to members'),
93            self::VALUE_CONFIDENTIAL => '<i class="icon-resn-confidential"></i> ' . I18N::translate('Show to managers'),
94            self::VALUE_LOCKED       => '<i class="icon-resn-locked"></i> ' . I18N::translate('Only managers can edit'),
95        ];
96    }
97}
98