-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAllAncestors.php
55 lines (45 loc) · 1.38 KB
/
AllAncestors.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
<?php
namespace Cissee\Webtrees\Module\ExtendedRelationships;
use Cissee\WebtreesExt\MoreI18N;
use Fisharebest\Webtrees\Individual;
//code taken from BranchesListModule
class AllAncestors {
/**
* Find all ancestors of an individual, indexed by the Sosa-Stradonitz number.
*
* @param Individual $individual
*
* @return Individual[]
*/
public static function allAncestors(Individual $individual): array
{
$ancestors = [
1 => $individual,
];
do {
$sosa = key($ancestors);
$family = $ancestors[$sosa]->childFamilies()->first();
if ($family !== null) {
if ($family->husband() !== null) {
$ancestors[$sosa * 2] = $family->husband();
}
if ($family->wife() !== null) {
$ancestors[$sosa * 2 + 1] = $family->wife();
}
}
} while (next($ancestors));
return $ancestors;
}
/**
* Convert a SOSA number into a generation number. e.g. 8 = great-grandfather = 3 generations
*
* @param int $sosa
*
* @return string
*/
public static function sosaGeneration(int $sosa): string
{
$generation = (int) log($sosa, 2) + 1;
return '<sup title="' . MoreI18N::xlate('Generation') . '">' . $generation . '</sup>';
}
}