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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
*/
namespace Fisharebest\Webtrees\Controller;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\Functions\FunctionsCharts;
use Fisharebest\Webtrees\Functions\FunctionsPrint;
use Fisharebest\Webtrees\GedcomTag;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Theme;
use Rhumsaa\Uuid\Uuid;
/**
* Controller for the descendancy chart
*/
class DescendancyController extends ChartController {
/** @var int Show boxes for cousins */
public $show_cousins;
/** @var int Determines style of chart */
public $chart_style;
/** @var int Number of generations to display */
public $generations;
/** @var array d'Aboville numbering system <http://www.saintclair.org/numbers/numdob.html> */
public $dabo_num = array();
/** @var array d'Aboville numbering system <http://www.saintclair.org/numbers/numdob.html> */
public $dabo_sex = array();
/**
* Create the descendancy controller
*/
public function __construct() {
global $WT_TREE;
parent::__construct();
// Extract parameters from form
$this->chart_style = Filter::getInteger('chart_style', 0, 3, 0);
$this->generations = Filter::getInteger('generations', 2, $WT_TREE->getPreference('MAX_DESCENDANCY_GENERATIONS'), $WT_TREE->getPreference('DEFAULT_PEDIGREE_GENERATIONS'));
if ($this->root && $this->root->canShowName()) {
$this->setPageTitle(
/* I18N: %s is an individual’s name */
I18N::translate('Descendants of %s', $this->root->getFullName())
);
} else {
$this->setPageTitle(I18N::translate('Descendants'));
}
}
/**
* Print a child family
*
* @param Individual $person
* @param int $depth the descendancy depth to show
* @param string $label
* @param string $gpid
*/
public function printChildFamily(Individual $person, $depth, $label = '1.', $gpid = '') {
if ($depth < 2) {
return;
}
foreach ($person->getSpouseFamilies() as $family) {
FunctionsCharts::printSosaFamily($family->getXref(), '', -1, $label, $person->getXref(), $gpid, 0, $this->showFull());
$i = 1;
foreach ($family->getChildren() as $child) {
$this->printChildFamily($child, $depth - 1, $label . ($i++) . '.', $person->getXref());
}
}
}
/**
* print a child descendancy
*
* @param Individual $person
* @param int $depth the descendancy depth to show
*/
public function printChildDescendancy(Individual $person, $depth) {
echo "<li>";
echo "<table><tr><td>";
if ($depth == $this->generations) {
echo "<img src=\"" . Theme::theme()->parameter('image-spacer') . "\" height=\"3\" width=\"", Theme::theme()->parameter('chart-descendancy-indent'), "\" alt=\"\"></td><td>";
} else {
echo "<img src=\"" . Theme::theme()->parameter('image-spacer') . "\" height=\"3\" width=\"3\" alt=\"\">";
echo "<img src=\"" . Theme::theme()->parameter('image-hline') . "\" height=\"3\" width=\"", Theme::theme()->parameter('chart-descendancy-indent') - 3, "\" alt=\"\"></td><td>";
}
FunctionsPrint::printPedigreePerson($person, $this->showFull());
echo '</td>';
// check if child has parents and add an arrow
echo '<td></td>';
echo '<td>';
foreach ($person->getChildFamilies() as $cfamily) {
foreach ($cfamily->getSpouses() as $parent) {
FunctionsCharts::printUrlArrow('?rootid=' . $parent->getXref() . '&generations=' . $this->generations . '&chart_style=' . $this->chart_style . '&show_full=' . $this->showFull() . '&ged=' . $parent->getTree()->getNameUrl(), I18N::translate('Start at parents'), 2);
// only show the arrow for one of the parents
break;
}
}
// d'Aboville child number
$level = $this->generations - $depth;
if ($this->showFull()) {
echo '<br><br> ';
}
echo '<span dir="ltr">'; //needed so that RTL languages will display this properly
if (!isset($this->dabo_num[$level])) {
$this->dabo_num[$level] = 0;
}
$this->dabo_num[$level]++;
$this->dabo_num[$level + 1] = 0;
$this->dabo_sex[$level] = $person->getSex();
for ($i = 0; $i <= $level; $i++) {
$isf = $this->dabo_sex[$i];
if ($isf === 'M') {
$isf = '';
}
if ($isf === 'U') {
$isf = 'NN';
}
echo "<span class=\"person_box" . $isf . "\"> " . $this->dabo_num[$i] . " </span>";
if ($i < $level) {
echo '.';
}
}
echo "</span>";
echo "</td></tr>";
echo "</table>";
echo "</li>";
// loop for each spouse
foreach ($person->getSpouseFamilies() as $family) {
$this->printFamilyDescendancy($person, $family, $depth);
}
}
/**
* print a family descendancy
*
* @param Individual $person
* @param Family $family
* @param int $depth the descendancy depth to show
*/
private function printFamilyDescendancy(Individual $person, Family $family, $depth) {
$uid = Uuid::uuid4(); // create a unique ID
// print marriage info
echo '<li>';
echo '<img src="', Theme::theme()->parameter('image-spacer'), '" height="2" width="', Theme::theme()->parameter('chart-descendancy-indent') + 4, '" alt="">';
echo '<span class="details1">';
echo "<a href=\"#\" onclick=\"expand_layer('" . $uid . "'); return false;\" class=\"top\"><i id=\"" . $uid . "_img\" class=\"icon-minus\" title=\"" . I18N::translate('View family') . "\"></i></a>";
if ($family->canShow()) {
foreach ($family->getFacts(WT_EVENTS_MARR) as $fact) {
echo ' <a href="', $family->getHtmlUrl(), '" class="details1">', $fact->summary(), '</a>';
}
}
echo '</span>';
// print spouse
$spouse = $family->getSpouse($person);
echo '<ul id="' . $uid . '" class="generation">';
echo '<li>';
echo '<table><tr><td>';
FunctionsPrint::printPedigreePerson($spouse, $this->showFull());
echo '</td>';
// check if spouse has parents and add an arrow
echo '<td></td>';
echo '<td>';
if ($spouse) {
foreach ($spouse->getChildFamilies() as $cfamily) {
foreach ($cfamily->getSpouses() as $parent) {
FunctionsCharts::printUrlArrow('?rootid=' . $parent->getXref() . '&generations=' . $this->generations . '&chart_style=' . $this->chart_style . '&show_full=' . $this->showFull() . '&ged=' . $parent->getTree()->getNameUrl(), I18N::translate('Start at parents'), 2);
// only show the arrow for one of the parents
break;
}
}
}
if ($this->showFull()) {
echo '<br><br> ';
}
echo '</td></tr>';
// children
$children = $family->getChildren();
echo '<tr><td colspan="3" class="details1" > ';
if ($children) {
echo GedcomTag::getLabel('NCHI') . ': ' . count($children);
} else {
// Distinguish between no children (NCHI 0) and no recorded
// children (no CHIL records)
if (strpos($family->getGedcom(), '\n1 NCHI 0')) {
echo GedcomTag::getLabel('NCHI') . ': ' . count($children);
} else {
echo I18N::translate('No children');
}
}
echo '</td></tr></table>';
echo '</li>';
if ($depth > 1) {
foreach ($children as $child) {
$this->printChildDescendancy($child, $depth - 1);
}
}
echo '</ul>';
echo '</li>';
}
/**
* Find all the individuals that are descended from an individual.
*
* @param Individual $person
* @param int $n
* @param Individual[] $array
*
* @return Individual[]
*/
public function individualDescendancy(Individual $person, $n, $array) {
if ($n < 1) {
return $array;
}
$array[$person->getXref()] = $person;
foreach ($person->getSpouseFamilies() as $family) {
$spouse = $family->getSpouse($person);
if ($spouse) {
$array[$spouse->getXref()] = $spouse;
}
foreach ($family->getChildren() as $child) {
$array = $this->individualDescendancy($child, $n - 1, $array);
}
}
return $array;
}
/**
* Find all the families that are descended from an individual.
*
* @param Individual $person
* @param int $n
* @param Family[] $array
*
* @return Family[]
*/
public function familyDescendancy($person, $n, $array) {
if ($n < 1) {
return $array;
}
foreach ($person->getSpouseFamilies() as $family) {
$array[$family->getXref()] = $family;
foreach ($family->getChildren() as $child) {
$array = $this->familyDescendancy($child, $n - 1, $array);
}
}
return $array;
}
}
|