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\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 string VALUE_NONE = 'NONE'; 52 public const string VALUE_PRIVACY = 'PRIVACY'; 53 public const string VALUE_CONFIDENTIAL = 'CONFIDENTIAL'; 54 public const string VALUE_LOCKED = 'LOCKED'; 55 56 private const array 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 private const string ICON_CONFIDENTIAL = '<i class="icon-resn-confidential"></i>'; 66 private const string ICON_LOCKED = '<i class="icon-resn-locked"></i> '; 67 private const string ICON_NONE = '<i class="icon-resn-none"></i>'; 68 private const string ICON_PRIVACY = '<i class="icon-resn-privacy"></i>'; 69 70 /** 71 * Convert a value to a canonical form. 72 * 73 * @param string $value 74 * 75 * @return string 76 */ 77 public function canonical(string $value): string 78 { 79 $value = strtoupper(parent::canonical($value)); 80 $value = trim($value, ', '); 81 $value = preg_replace('/[, ]+/', ', ', $value); 82 83 return self::CANONICAL[$value] ?? $value; 84 } 85 86 /** 87 * A list of controlled values for this element 88 * 89 * @return array<int|string,string> 90 */ 91 public function values(): array 92 { 93 // Note: "1 RESN none" is not valid gedcom. 94 // However, webtrees privacy rules will interpret it as "show an otherwise private record to public". 95 96 $confidential = I18N::translate('Show to managers'); 97 $locked = I18N::translate('Only managers can edit'); 98 $none = I18N::translate('Show to visitors'); 99 $privacy = I18N::translate('Show to members'); 100 101 return [ 102 '' => '', 103 self::VALUE_NONE => self::ICON_NONE . ' ' . $none, 104 self::VALUE_NONE . ', ' . self::VALUE_LOCKED => self::ICON_NONE . self::ICON_LOCKED . ' ' . $none . ' — ' . $locked, 105 self::VALUE_PRIVACY => self::ICON_PRIVACY . ' ' . $privacy, 106 self::VALUE_PRIVACY . ', ' . self::VALUE_LOCKED => self::ICON_PRIVACY . self::ICON_LOCKED . ' ' . $privacy . ' — ' . $locked, 107 self::VALUE_CONFIDENTIAL => self::ICON_CONFIDENTIAL . ' ' . $confidential, 108 self::VALUE_CONFIDENTIAL . ', ' . self::VALUE_LOCKED => self::ICON_CONFIDENTIAL . ' ' . self::ICON_LOCKED . ' ' . $confidential . ' — ' . $locked, 109 self::VALUE_LOCKED => self::ICON_LOCKED . ' ' . $locked, 110 ]; 111 } 112} 113