-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExtendedRelationshipUtils.php
73 lines (60 loc) · 1.91 KB
/
ExtendedRelationshipUtils.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
<?php
namespace Cissee\Webtrees\Module\ExtendedRelationships;
use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Individual;
class ExtendedRelationshipUtils {
public static function getBornNoLaterThan(Individual $individual): Date {
$date = $individual->getBirthDate();
if ($date->isOK()) {
return $date;
}
$dates = array();
foreach ($individual->facts() as $event) {
$date = $event->date();
if ($date->isOK()) {
$dates[] = $date;
}
}
$minDate = null;
foreach ($dates as $date) {
if ($minDate === null) {
$minDate = $date;
} else if (Date::compare($date, $minDate) < 0) {
$minDate = $date;
}
}
if ($minDate === null) {
return new Date('');
}
return $minDate;
}
//for proper family-related relationship names,
//('ex-husband', 'partner's xy')
//we strictly need up to three dates with different types here (pre-marriage, marriage, post-divorce)
public static function getFamilyEstablishedNoLaterThan(Family $family): Date {
$dates = array();
$date = $family->getMarriageDate();
if ($date->isOK()) {
$dates[] = $date;
}
foreach ($family->children() as $child) {
$date = ExtendedRelationshipUtils::getBornNoLaterThan($child);
if ($date->isOK()) {
$dates[] = $date;
}
}
$minDate = null;
foreach ($dates as $date) {
if ($minDate === null) {
$minDate = $date;
} else if (Date::compare($date, $minDate) < 0) {
$minDate = $date;
}
}
if ($minDate === null) {
return new Date('');
}
return $minDate;
}
}