|
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 Kristopher Wilson <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2010-2013, Kristopher Wilson |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* |
|
12
|
|
|
* @link http://github.com/mrkrstphr/php-gedcom |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace PhpGedcom\Parser; |
|
16
|
|
|
|
|
17
|
|
|
class Note extends \PhpGedcom\Parser\Component |
|
18
|
|
|
{ |
|
19
|
|
|
public static function parse(\PhpGedcom\Parser $parser) |
|
20
|
|
|
{ |
|
21
|
|
|
$record = $parser->getCurrentLineRecord(4); |
|
22
|
|
|
$depth = (int) $record[0]; |
|
23
|
|
|
if (isset($record[1])) { |
|
24
|
|
|
$identifier = $parser->normalizeIdentifier($record[1]); |
|
25
|
|
|
} else { |
|
26
|
|
|
$parser->skipToNextLevel($depth); |
|
27
|
|
|
|
|
28
|
|
|
return null; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$note = new \PhpGedcom\Record\Note(); |
|
32
|
|
|
$note->setId($identifier); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
if (isset($record[3])) { |
|
35
|
|
|
$note->setNote($record[3]); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$parser->forward(); |
|
39
|
|
|
|
|
40
|
|
|
while (!$parser->eof()) { |
|
41
|
|
|
$record = $parser->getCurrentLineRecord(); |
|
42
|
|
|
$currentDepth = (int) $record[0]; |
|
43
|
|
|
$recordType = strtoupper(trim($record[1])); |
|
44
|
|
|
|
|
45
|
|
|
if ($currentDepth <= $depth) { |
|
46
|
|
|
$parser->back(); |
|
47
|
|
|
break; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
switch ($recordType) { |
|
51
|
|
|
case 'CONT': |
|
52
|
|
|
$note->setNote($note->getNote()."\n"); |
|
|
|
|
|
|
53
|
|
|
if (isset($record[2])) { |
|
54
|
|
|
$note->setNote($note->getNote().$record[2]); |
|
55
|
|
|
} |
|
56
|
|
|
break; |
|
57
|
|
|
case 'CONC': |
|
58
|
|
|
if (isset($record[2])) { |
|
59
|
|
|
$note->setNote($note->getNote().$record[2]); |
|
60
|
|
|
} |
|
61
|
|
|
break; |
|
62
|
|
|
case 'REFN': |
|
63
|
|
|
$refn = \PhpGedcom\Parser\Refn::parse($parser); |
|
64
|
|
|
$note->addRefn($refn); |
|
65
|
|
|
break; |
|
66
|
|
|
case 'RIN': |
|
67
|
|
|
$note->setRin(trim($record[2])); |
|
|
|
|
|
|
68
|
|
|
break; |
|
69
|
|
|
case 'SOUR': |
|
70
|
|
|
$sour = \PhpGedcom\Parser\SourRef::parse($parser); |
|
71
|
|
|
$note->addSour($sour); |
|
72
|
|
|
break; |
|
73
|
|
|
case 'CHAN': |
|
74
|
|
|
$chan = \PhpGedcom\Parser\Chan::parse($parser); |
|
75
|
|
|
$note->setChan($chan); |
|
|
|
|
|
|
76
|
|
|
break; |
|
77
|
|
|
default: |
|
78
|
|
|
$parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$parser->forward(); |
|
82
|
|
|
} |
|
83
|
|
|
$parser->getGedcom()->addNote($note); |
|
84
|
|
|
|
|
85
|
|
|
return $note; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|