-
Notifications
You must be signed in to change notification settings - Fork 4
/
FunctionsPrintRels.php
184 lines (147 loc) · 6.08 KB
/
FunctionsPrintRels.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace Cissee\Webtrees\Module\ExtendedRelationships;
use Cissee\Webtrees\Module\ExtendedRelationships\ExtendedRelationshipController;
use Cissee\WebtreesExt\Modules\RelationshipPath;
use Cissee\WebtreesExt\Modules\RelationshipUtils;
use Exception;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Registry;
class FunctionsPrintRels {
public static function printSlcasWrtDefaultIndividual($moduleName, $person, $mode, $recursion, $showCa) {
if ($person === null) {
return;
}
$person1 = $person->tree()->significantIndividual(Auth::user());
if ($person1 === null) {
return;
}
if (!$person1->canShow()) {
return;
}
if ($person === null) {
return;
}
if (!$person->canShow()) {
return;
}
FunctionsPrintRels::printSlcasBetween($moduleName, $person1, $person, $mode, $recursion, $showCa);
}
public static function printSlcas($moduleName, Family $family, $access_level, $mode, $recursion, $showCa, $beforeJD = null) {
$person1 = null;
foreach ($family->facts(['HUSB'], false, $access_level) as $fact) {
$person = $fact->target();
if ($person instanceof Individual) {
$person1 = $person;
}
}
$person2 = null;
foreach ($family->facts(['WIFE'], false, $access_level) as $fact) {
$person = $fact->target();
if ($person instanceof Individual) {
$person2 = $person;
}
}
if ($person1 === null) {
return;
}
if (!$person1->canShow()) {
return;
}
if ($person2 === null) {
return;
}
if (!$person2->canShow()) {
return;
}
FunctionsPrintRels::printSlcasBetween($moduleName, $person1, $person2, $mode, $recursion, $showCa, $beforeJD);
}
public static function printSlcasBetween(
$moduleName,
$person1,
$person2,
$mode,
$recursion,
$showCa,
$beforeJD = null) {
$slcaController = new ExtendedRelationshipController;
$caAndPaths = $slcaController->calculateCaAndPaths_123456($person1, $person2, $mode, $recursion, $beforeJD);
$printed = array();
foreach ($caAndPaths as $caAndPath) {
$slcaKey = $caAndPath->getCommonAncestor();
$path = $caAndPath->getPath();
// Extract the relationship names between pairs of individuals
$relationshipPath = RelationshipPath::create($person1->tree(), $path, $beforeJD);
if ($relationshipPath === null) {
// Cannot see one of the families/individuals, due to privacy;
continue;
}
$rel = RelationshipUtils::getRelationshipName($relationshipPath);
if ($rel === '') {
continue;
}
$link = ExtendedRelationshipModule::getRelationshipLink(
$moduleName,
$person1->tree(),
$rel,
$person1->xref(),
$person2->xref(),
$mode,
$beforeJD);
$print = /* I18N: (person 1) is (relative, e.g. father) of (person2) */ I18N::translate('%1$s is %2$s of %3$s.',
$person2->fullName(),
$link,
$person1->fullName());
$print .= "<br/>";
if (($slcaKey !== null) && ($showCa)) {
//add actual common ancestor(s), unless already mentioned)
//not correct in all cases: INDIs may use different prefixes!
//$caIsIndi = (substr($slcaKey, 0, 1) === "I");
$record = Registry::gedcomRecordFactory()->make($slcaKey, $person1->tree());
$caIsIndi = ($record instanceof Individual);
if ($caIsIndi) {
$indi = $record;
if (($person1 !== $indi) && ($person2 !== $indi)) {
$html = "";
$html .= '<a href="' . $indi->url() . '" title="' . strip_tags($indi->fullName()) . '">';
$html .= $indi->fullName() . '</a>';
$print .= "(" . I18N::translate('Common ancestor: ') . $html . ")";
$print .= "<br />";
}
} else {
$caIsFam = ($record instanceof Family);
if (!$caIsFam) {
throw new Exception("unexpected class " . get_class($record));
}
$fam = $record;
//huh - just use the standard family name!
/*
$names = array();
foreach ($fam->spouses() as $indi) {
$html = "";
$html .= '<a href="' . $indi->url() . '" title="' . strip_tags($indi->fullName()) . '">';
$html .= $indi->fullName() . '</a>';
$names[] = $indi->fullName();
}
$famName = implode(' & ', $names);
*/
$famName = $record->fullName();
$html = "";
$html .= '<a href="' . $fam->url() . '" title="' . strip_tags($famName) . '">';
$html .= $famName . '</a>';
$print .= "(" . I18N::translate('Common ancestors: ') . $html . ")";
$print .= "<br />";
}
}
//there may be different paths leading to the same text (same relationship, same common ancestor)
//it seems pointless to list these texts here multiple times (in the chart it's ok because the actual - different - paths are shown)
if (in_array($print, $printed)) {
continue;
}
$printed[] = $print;
echo $print;
}
}
}