1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* php-gedcom. |
4
|
|
|
* |
5
|
|
|
* php-gedcom is a library for parsing, manipulating, importing and exporting |
6
|
|
|
* GEDCOM 5.5 files in PHP 5.3+. |
7
|
|
|
* |
8
|
|
|
* @author Xiang Ming <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2010-2013, Xiang Ming |
10
|
|
|
* @license MIT |
11
|
|
|
* |
12
|
|
|
* @link http://github.com/mrkrstphr/php-gedcom |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace PhpGedcom\Writer; |
16
|
|
|
|
17
|
|
|
class Fam |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param \PhpGedcom\Record\Fam $sour |
21
|
|
|
* @param int $level |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public static function convert(\PhpGedcom\Record\Fam &$fam, $level = 0) |
26
|
|
|
{ |
27
|
|
|
$output = ''; |
28
|
|
|
$id = $fam->getId(); |
|
|
|
|
29
|
|
|
if (empty($id)) { |
30
|
|
|
return $output; |
31
|
|
|
} else { |
32
|
|
|
$output .= $level.' @'.$id.'@ FAM '."\n"; |
|
|
|
|
33
|
|
|
} |
34
|
|
|
// level up |
35
|
|
|
$level++; |
36
|
|
|
|
37
|
|
|
// HUSB |
38
|
|
|
$husb = $fam->getHusb(); |
|
|
|
|
39
|
|
|
if (!empty($husb)) { |
40
|
|
|
$output .= $level.' HUSB @'.$husb."@\n"; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// WIFE |
44
|
|
|
$wife = $fam->getWife(); |
|
|
|
|
45
|
|
|
if (!empty($wife)) { |
46
|
|
|
$output .= $level.' WIFE @'.$wife."@\n"; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// CHIL |
50
|
|
|
$chil = $fam->getChil(); |
|
|
|
|
51
|
|
|
if (!empty($chil) && count($chil) > 0) { |
|
|
|
|
52
|
|
|
foreach ($chil as $item) { |
53
|
|
|
if ($item) { |
54
|
|
|
$_convert = $level.' CHIL @'.$item."@\n"; |
55
|
|
|
$output .= $_convert; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
// NCHI |
60
|
|
|
$nchi = $fam->getNchi(); |
|
|
|
|
61
|
|
|
if (!empty($nchi)) { |
62
|
|
|
$output .= $level.' NCHI '.$nchi."\n"; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
// SUBM array |
66
|
|
|
$subm = $fam->getSubm(); |
|
|
|
|
67
|
|
|
|
68
|
|
|
if (!empty($subm) && count($subm) > 0) { |
69
|
|
|
foreach ($subm as $item) { |
70
|
|
|
if ($item) { |
71
|
|
|
$output .= $level.' SUBM '.$item."\n"; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// RIN |
77
|
|
|
$rin = $fam->getRin(); |
|
|
|
|
78
|
|
|
if (!empty($rin)) { |
79
|
|
|
$output .= $level.' RIN '.$rin."\n"; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
// CHAN |
82
|
|
|
$chan = $fam->getChan(); |
|
|
|
|
83
|
|
|
if (!empty($chan)) { |
84
|
|
|
$_convert = \PhpGedcom\Writer\Chan::convert($chan, $level); |
|
|
|
|
85
|
|
|
$output .= $_convert; |
86
|
|
|
} |
87
|
|
|
// SLGS |
88
|
|
|
$slgs = $fam->getSlgs(); |
|
|
|
|
89
|
|
|
if (!empty($slgs) && count($slgs) > 0) { |
90
|
|
|
if ($slgs) { |
91
|
|
|
$_convert = \PhpGedcom\Writer\Fam\Slgs::convert($item, $level); |
92
|
|
|
$output .= $_convert; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// REFN array |
97
|
|
|
$refn = $fam->getRefn(); |
|
|
|
|
98
|
|
|
if (!empty($refn) && count($refn) > 0) { |
99
|
|
|
foreach ($refn as $item) { |
100
|
|
|
if ($item) { |
101
|
|
|
$_convert = \PhpGedcom\Writer\Refn::convert($item, $level); |
102
|
|
|
$output .= $_convert; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// NOTE array |
108
|
|
|
$note = $fam->getNote(); |
|
|
|
|
109
|
|
|
if (!empty($note) && count($note) > 0) { |
110
|
|
|
foreach ($note as $item) { |
111
|
|
|
if ($item) { |
112
|
|
|
$_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level); |
113
|
|
|
$output .= $_convert; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// SOUR |
119
|
|
|
$sour = $fam->getSour(); |
|
|
|
|
120
|
|
|
if (!empty($sour) && count($sour) > 0) { |
121
|
|
|
foreach ($sour as $item) { |
122
|
|
|
if ($item) { |
123
|
|
|
$_convert = \PhpGedcom\Writer\SourRef::convert($item, $level); |
124
|
|
|
$output .= $_convert; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// OBJE |
130
|
|
|
$obje = $fam->getObje(); |
|
|
|
|
131
|
|
|
if (!empty($obje) && count($obje) > 0) { |
132
|
|
|
foreach ($obje as $item) { |
133
|
|
|
if ($item) { |
134
|
|
|
$_convert = \PhpGedcom\Writer\ObjeRef::convert($item, $level); |
135
|
|
|
$output .= $_convert; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// EVEN |
141
|
|
|
$even = $fam->getAllEven(); |
142
|
|
|
if (!empty($even) && count($even) > 0) { |
143
|
|
|
foreach ($even as $item) { |
144
|
|
|
if ($item) { |
145
|
|
|
$_convert = \PhpGedcom\Writer\Fam\Even::convert($item, $level); |
146
|
|
|
$output .= $_convert; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $output; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|