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 Sour |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param \PhpGedcom\Record\Sour $sour |
21
|
|
|
* @param int $level |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public static function convert(\PhpGedcom\Record\Sour &$sour, $level) |
26
|
|
|
{ |
27
|
|
|
$output = ''; |
28
|
|
|
$_sour = $sour->getSour(); |
29
|
|
|
if (empty($_sour)) { |
30
|
|
|
return $output; |
31
|
|
|
} else { |
32
|
|
|
$output .= $level.' '.$_sour.' SOUR '."\n"; |
33
|
|
|
} |
34
|
|
|
// level up |
35
|
|
|
$level++; |
36
|
|
|
|
37
|
|
|
// TITL |
38
|
|
|
$titl = $sour->getType(); |
|
|
|
|
39
|
|
|
if (!empty($type)) { |
|
|
|
|
40
|
|
|
$output .= $level.' TITL '.$titl."\n"; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// RIN |
44
|
|
|
$rin = $sour->getRin(); |
45
|
|
|
if (!empty($rin)) { |
46
|
|
|
$output .= $level.' RIN '.$rin."\n"; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// AUTH |
50
|
|
|
$auth = $sour->getAuth(); |
51
|
|
|
if (!empty($auth)) { |
52
|
|
|
$output .= $level.' AUTH '.$auth."\n"; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// TEXT |
56
|
|
|
$text = $sour->getText(); |
57
|
|
|
if (!empty($text)) { |
58
|
|
|
$output .= $level.' TEXT '.$text."\n"; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// PUBL |
62
|
|
|
$publ = $sour->getPubl(); |
63
|
|
|
if (!empty($publ)) { |
64
|
|
|
$output .= $level.' PUBL '.$publ."\n"; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// ABBR |
68
|
|
|
$abbr = $sour->getAbbr(); |
69
|
|
|
if (!empty($abbr)) { |
70
|
|
|
$output .= $level.' ABBR '.$abbr."\n"; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// REPO |
74
|
|
|
$repo = $sour->getRepo(); |
75
|
|
|
if (!empty($repo)) { |
76
|
|
|
$_convert = \PhpGedcom\Writer\RepoRef::convert($repo, $level); |
|
|
|
|
77
|
|
|
$output .= $_convert; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// NOTE array |
81
|
|
|
$note = $sour->getNote(); |
82
|
|
|
if (!empty($note) && count($note) > 0) { |
83
|
|
|
foreach ($note as $item) { |
84
|
|
|
$_convert = \PhpGedcom\Writer\NoteRef::convert($item, $level); |
85
|
|
|
$output .= $_convert; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// DATA |
90
|
|
|
$data = $sour->getData(); |
91
|
|
|
if (!empty($data)) { |
92
|
|
|
$_convert = \PhpGedcom\Writer\Sour\Data::convert($data, $level); |
|
|
|
|
93
|
|
|
$output .= $_convert; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// OBJE array |
97
|
|
|
$obje = $sour->getObje(); |
98
|
|
|
if (!empty($obje) && count($obje) > 0) { |
99
|
|
|
foreach ($obje as $item) { |
100
|
|
|
$_convert = \PhpGedcom\Writer\ObjeRef::convert($item, $level); |
101
|
|
|
$output .= $_convert; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// REFN array |
106
|
|
|
$refn = $sour->getRefn(); |
107
|
|
|
if (!empty($refn) && count($refn) > 0) { |
108
|
|
|
foreach ($refn as $item) { |
109
|
|
|
$_convert = \PhpGedcom\Writer\Refn::convert($item, $level); |
110
|
|
|
$output .= $_convert; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// chan |
115
|
|
|
$chan = $sour->getChan(); |
116
|
|
|
if (!empty($chan)) { |
117
|
|
|
$_convert = \PhpGedcom\Writer\Chan::convert($chan, $level); |
118
|
|
|
$output .= $_convert; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $output; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|