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