forked from hartenthaler/hh_relation_is_descriptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtendedRelationIsDescriptor.php
100 lines (89 loc) · 3.27 KB
/
ExtendedRelationIsDescriptor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* class ExtendedRelationIsDescriptor
* module RelationIsDescriptorAddon
* custom module to add more relation descriptors which are used in ASSO:TYPE or _ASSO:TYPE
*
* webtrees: online genealogy
* Copyright (C) 2022 Hermann Hartenthaler
* Copyright (C) 2022 webtrees development team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Hartenthaler\Webtrees\Module\RelationIsDescriptorAddon;
use Fisharebest\Webtrees\Elements\RelationIsDescriptor;
use Fisharebest\Webtrees\I18N;
use function uasort;
/*
* class extends original class RelationIsDescriptor with custom descriptor values
*/
class ExtendedRelationIsDescriptor extends RelationIsDescriptor
{
protected const SEX = ['M', 'F', 'U'];
/**
* provides additional custom relation descriptors
* Replace the example lines in this function by your custom descriptors!
*
* @return array
*/
private function valuesAddon(): array
{
return [
'M' => [
'guru' => I18N::translateContext('MALE', 'Guru'),
'godparent' => I18N::translate('Godfather'),
'landlord' => I18N::translateContext('MALE', 'Landlord'),
],
'F' => [
'guru' => I18N::translateContext('FEMALE', 'Guru'),
'godparent' => I18N::translate('Godmother'),
'landlord' => I18N::translateContext('FEMALE', 'Landlord'),
],
'U' => [
'guru' => I18N::translate('Guru'),
'godfather' => I18N::translate('Godfather'),
'godmother' => I18N::translate('Godmother'),
'godparent' => I18N::translate('Godparent'),
'landlord' => I18N::translate('Landlord'),
],
];
}
/**
* original value list as a copy from /app/Elements/RelationIsDescriptor
*
* @return array
*/
private function valuesOriginal(): array
{
foreach (self::SEX as $sexPart) {
$values[$sexPart] = RelationIsDescriptor::values($sexPart);
}
return $values;
}
/**
* @param string $sex - the text depends on the sex of the *linked* individual
* @return array
*/
public function values(string $sex = 'U'): array
{
$values = [];
$valuesOriginal = $this->valuesOriginal();
$valuesAddon = $this->valuesAddon();
foreach (self::SEX as $sexPart) {
$values[$sexPart] = array_merge($valuesOriginal[$sexPart], $valuesAddon[$sexPart]);
}
$tmp = $values[$sex] ?? $values['U'];
uasort($tmp, I18N::comparator());
return $tmp;
}
}