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 Indi |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param \PhpGedcom\Record\Indi $indi |
21
|
|
|
* @param string $format |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public static function convert(\PhpGedcom\Record\Indi &$indi) |
26
|
|
|
{ |
27
|
|
|
$level = 0; |
28
|
|
|
|
29
|
|
|
// id |
30
|
|
|
$id = $indi->getId(); |
31
|
|
|
$output = $level.' @'.$id."@ INDI\n"; |
32
|
|
|
|
33
|
|
|
// increase level after start indi |
34
|
|
|
$level++; |
35
|
|
|
|
36
|
|
|
// name |
37
|
|
|
// $name = $indi->getName(); |
38
|
|
|
// if(!empty($name)){ |
39
|
|
|
// $output.=$level." NAME ".$name."\n"; |
40
|
|
|
// } |
41
|
|
|
|
42
|
|
|
// chan |
43
|
|
|
$chan = $indi->getChan(); |
44
|
|
|
if (!empty($chan)) { |
45
|
|
|
$output .= $level.' CHAN '.$chan."\n"; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// $attr |
49
|
|
|
// PhpGedcom/Record/Attr extend PhpGedcom/Record/Even and there is no change. |
50
|
|
|
// So used convert Even |
51
|
|
|
$attr = $indi->getAllAttr(); |
52
|
|
|
if (!empty($attr) && count($attr) > 0) { |
53
|
|
|
foreach ($attr as $item) { |
54
|
|
|
$_convert = \PhpGedcom\Writer\Indi\Even::convert($item, $level); |
55
|
|
|
$output .= $_convert; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// $even |
60
|
|
|
$even = $indi->getAllEven(); |
61
|
|
|
if (!empty($even) && count($even) > 0) { |
62
|
|
|
foreach ($even as $item) { |
63
|
|
|
$_convert = \PhpGedcom\Writer\Indi\Even::convert($item, $level); |
64
|
|
|
$output .= $_convert; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// $note |
69
|
|
|
|
70
|
|
|
$note = $indi->getNote(); |
71
|
|
|
if (!empty($note) && count($note) > 0) { |
72
|
|
|
foreach ($note as $item) { |
73
|
|
|
$_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level); |
74
|
|
|
$output .= $_convert; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// $obje |
79
|
|
|
$obje = $indi->getObje(); |
80
|
|
|
if (!empty($obje) && count($obje) > 0) { |
81
|
|
|
foreach ($obje as $item) { |
82
|
|
|
$_convert = \PhpGedcom\Writer\ObjeRef::convert($item, $level); |
|
|
|
|
83
|
|
|
$output .= $_convert; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// $sour |
88
|
|
|
$sour = $indi->getSour(); |
89
|
|
|
if (!empty($sour) && count($sour) > 0) { |
90
|
|
|
foreach ($sour as $item) { |
91
|
|
|
$_convert = \PhpGedcom\Writer\SourRef::convert($item, $level); |
|
|
|
|
92
|
|
|
$output .= $_convert; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// $name |
97
|
|
|
$name = $indi->getName(); |
98
|
|
|
if (!empty($name) && count($name) > 0) { |
99
|
|
|
foreach ($name as $item) { |
100
|
|
|
$_convert = \PhpGedcom\Writer\Indi\Name::convert($item, $level); |
101
|
|
|
$output .= $_convert; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// $alia |
106
|
|
|
$alia = $indi->getAlia(); |
107
|
|
|
if (!empty($alia) && count($alia) > 0) { |
108
|
|
|
foreach ($alia as $item) { |
109
|
|
|
if (!empty($item)) { |
110
|
|
|
$_convert = $level.' ALIA '.$item."\n"; |
111
|
|
|
$output .= $_convert; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// $sex |
117
|
|
|
$sex = $indi->getSex(); |
118
|
|
|
if (!empty($sex)) { |
119
|
|
|
$output .= $level.' SEX '.$sex."\n"; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// $rin |
123
|
|
|
$rin = $indi->getRin(); |
124
|
|
|
if (!empty($rin)) { |
125
|
|
|
$output .= $level.' RIN '.$rin."\n"; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// $resn |
129
|
|
|
$resn = $indi->getResn(); |
130
|
|
|
if (!empty($resn)) { |
131
|
|
|
$output .= $level.' RESN '.$resn."\n"; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// $rfn |
135
|
|
|
$rfn = $indi->getRfn(); |
136
|
|
|
if (!empty($rfn)) { |
137
|
|
|
$output .= $level.' RFN '.$rfn."\n"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// $afn |
141
|
|
|
$afn = $indi->getAfn(); |
142
|
|
|
if (!empty($afn)) { |
143
|
|
|
$output .= $level.' AFN '.$afn."\n"; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// Fams[] |
147
|
|
|
$fams = $indi->getFams(); |
148
|
|
|
if (!empty($fams) && count($fams) > 0) { |
149
|
|
|
foreach ($fams as $item) { |
150
|
|
|
$_convert = \PhpGedcom\Writer\Indi\Fams::convert($item, $level); |
151
|
|
|
$output .= $_convert; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// Famc[] |
156
|
|
|
$famc = $indi->getFamc(); |
157
|
|
|
if (!empty($famc) && count($famc) > 0) { |
158
|
|
|
foreach ($famc as $item) { |
159
|
|
|
$_convert = \PhpGedcom\Writer\Indi\Famc::convert($item, $level); |
160
|
|
|
$output .= $_convert; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
// Asso[] |
165
|
|
|
$asso = $indi->getAsso(); |
166
|
|
|
if (!empty($asso) && count($asso) > 0) { |
167
|
|
|
foreach ($asso as $item) { |
168
|
|
|
$_convert = \PhpGedcom\Writer\Indi\Asso::convert($item, $level); |
169
|
|
|
$output .= $_convert; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// $subm |
174
|
|
|
$subm = $indi->getSubm(); |
175
|
|
|
if (!empty($subm) && count($subm) > 0) { |
176
|
|
|
foreach ($subm as $item) { |
177
|
|
|
if (!empty($item)) { |
178
|
|
|
$_convert = $level.' SUBM '.$item."\n"; |
179
|
|
|
$output .= $_convert; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
// $anci |
185
|
|
|
$anci = $indi->getAnci(); |
186
|
|
|
if (!empty($anci) && count($anci) > 0) { |
187
|
|
|
foreach ($anci as $item) { |
188
|
|
|
$_convert = $level.' ANCI '.$item."\n"; |
189
|
|
|
$output .= $_convert; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
// $desi |
194
|
|
|
$desi = $indi->getDesi(); |
195
|
|
|
if (!empty($desi) && count($desi) > 0) { |
196
|
|
|
foreach ($desi as $item) { |
197
|
|
|
$_convert = $level.' DESI '.$item."\n"; |
198
|
|
|
$output .= $_convert; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
// Refn[] |
203
|
|
|
$refn = $indi->getRefn(); |
204
|
|
|
if (!empty($refn) && count($refn) > 0) { |
205
|
|
|
foreach ($refn as $item) { |
206
|
|
|
$_convert = \PhpGedcom\Writer\Refn::convert($item, $level); |
207
|
|
|
$output .= $_convert; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// Bapl |
212
|
|
|
// Currently Bapl is empty |
213
|
|
|
// $bapl = $indi->getBapl(); |
214
|
|
|
// if(!empty($bapl)){ |
215
|
|
|
// $_convert = \PhpGedcom\Writer\Indi\Bapl::convert($bapl, $level); |
216
|
|
|
// $output.=$_convert; |
217
|
|
|
// } |
218
|
|
|
|
219
|
|
|
// Conl |
220
|
|
|
// Currently Conl is empty |
221
|
|
|
// $conl = $indi->getConl(); |
222
|
|
|
// if(!empty($conl)){ |
223
|
|
|
// $_convert = \PhpGedcom\Writer\Indi\Conl::convert($conl, $level); |
224
|
|
|
// $output.=$_convert; |
225
|
|
|
// } |
226
|
|
|
|
227
|
|
|
// Endl |
228
|
|
|
// Currently Endl is empty |
229
|
|
|
// $endl = $indi->getEndl(); |
230
|
|
|
// if(!empty($endl)){ |
231
|
|
|
// $_convert = \PhpGedcom\Writer\Indi\Endl::convert($endl, $level); |
232
|
|
|
// $output.=$_convert; |
233
|
|
|
// } |
234
|
|
|
|
235
|
|
|
// Slgc |
236
|
|
|
// Currently Endl is empty |
237
|
|
|
// $slgc = $indi->getSlgc(); |
238
|
|
|
// if(!empty($slgc)){ |
239
|
|
|
// $_convert = \PhpGedcom\Writer\Indi\Slgc::convert($slgc, $level); |
240
|
|
|
// $output.=$_convert; |
241
|
|
|
// } |
242
|
|
|
|
243
|
|
|
return $output; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|