Skip to content

Commit ca48496

Browse files
Merge pull request #30 from familytree365/fix/gedcom_import_export
Fix not filled for birt dati, birt plac, deat dati, deat plac, deat c…
2 parents 3f892b3 + b6ced1a commit ca48496

File tree

10 files changed

+599
-36
lines changed

10 files changed

+599
-36
lines changed

src/Parser/Birt.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 Gedcom\Parser;
16+
17+
class Birt extends \Gedcom\Parser\Component
18+
{
19+
public static function parse(\Gedcom\Parser $parser)
20+
{
21+
$record = $parser->getCurrentLineRecord();
22+
$depth = (int) $record[0];
23+
24+
$parser->forward();
25+
26+
$birt = new \Gedcom\Record\Birt();
27+
28+
while (!$parser->eof()) {
29+
$record = $parser->getCurrentLineRecord();
30+
$recordType = trim($record[1]);
31+
$currentDepth = (int) $record[0];
32+
33+
if ($currentDepth <= $depth) {
34+
$parser->back();
35+
break;
36+
}
37+
38+
switch ($recordType) {
39+
case 'DATE':
40+
$birt->setDate(trim($record[2]));
41+
break;
42+
case '_DATI':
43+
$birt->setDati(trim($record[2]));
44+
break;
45+
case 'PLAC':
46+
$birt->setPlac(trim($record[2]));
47+
break;
48+
default:
49+
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
50+
}
51+
52+
$parser->forward();
53+
}
54+
55+
return $birt;
56+
}
57+
}

src/Parser/Buri.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 Gedcom\Parser;
16+
17+
class Buri extends \Gedcom\Parser\Component
18+
{
19+
public static function parse(\Gedcom\Parser $parser)
20+
{
21+
$record = $parser->getCurrentLineRecord();
22+
$depth = (int) $record[0];
23+
24+
$parser->forward();
25+
26+
$buri = new \Gedcom\Record\Buri();
27+
28+
while (!$parser->eof()) {
29+
$record = $parser->getCurrentLineRecord();
30+
$recordType = trim($record[1]);
31+
$currentDepth = (int) $record[0];
32+
33+
if ($currentDepth <= $depth) {
34+
$parser->back();
35+
break;
36+
}
37+
38+
switch ($recordType) {
39+
case 'DATE':
40+
$buri->setDate(trim($record[2]));
41+
break;
42+
case '_DATI':
43+
$buri->setDati(trim($record[2]));
44+
break;
45+
case 'PLAC':
46+
$buri->setPlac(trim($record[2]));
47+
break;
48+
default:
49+
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
50+
}
51+
52+
$parser->forward();
53+
}
54+
55+
return $buri;
56+
}
57+
}

src/Parser/Chan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function parse(\Gedcom\Parser $parser)
5555
$parser->forward();
5656
}
5757

58-
$date = $chan->getYear() .'-'. $chan->getMonth() .'-'. $chan->getDay() ;
58+
$date = $chan->getYear() .'-'. $chan->getMonth() .'-'. $chan->getDay();
5959
$chan->setDatetime($date);
6060

6161
return $chan;

src/Parser/Deat.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 Gedcom\Parser;
16+
17+
class Deat extends \Gedcom\Parser\Component
18+
{
19+
public static function parse(\Gedcom\Parser $parser)
20+
{
21+
$record = $parser->getCurrentLineRecord();
22+
$depth = (int) $record[0];
23+
24+
$parser->forward();
25+
26+
$deat = new \Gedcom\Record\Deat();
27+
28+
while (!$parser->eof()) {
29+
$record = $parser->getCurrentLineRecord();
30+
$recordType = trim($record[1]);
31+
$currentDepth = (int) $record[0];
32+
33+
if ($currentDepth <= $depth) {
34+
$parser->back();
35+
break;
36+
}
37+
38+
switch ($recordType) {
39+
case 'DATE':
40+
$deat->setDate(trim($record[2]));
41+
break;
42+
case '_DATI':
43+
$deat->setDati(trim($record[2]));
44+
break;
45+
case 'PLAC':
46+
$deat->setPlac(trim($record[2]));
47+
break;
48+
case 'CAUS':
49+
$deat->setCaus(trim($record[2]));
50+
break;
51+
default:
52+
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
53+
}
54+
55+
$parser->forward();
56+
}
57+
58+
return $deat;
59+
}
60+
}

src/Parser/Indi.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public static function parse(\Gedcom\Parser $parser)
4545
break;
4646
}
4747

48+
if ($recordType == 'BURI') {
49+
$a='';
50+
}
51+
4852
switch ($recordType) {
4953
case '_UID':
5054
$indi->setUid(trim($record[2]));
@@ -61,25 +65,25 @@ public static function parse(\Gedcom\Parser $parser)
6165
break;
6266
case 'ADOP':
6367
case 'BIRT':
64-
$birthday = \Gedcom\Parser\Date::parse($parser);
65-
$indi->setBirthday($birthday);
68+
$birt = \Gedcom\Parser\Birt::parse($parser);
69+
$indi->setBirt($birt);
6670
break;
6771
case 'BAPM':
6872
case 'BARM':
6973
case 'BASM':
7074
case 'BLES':
7175
case 'BURI':
72-
$burialday = \Gedcom\Parser\Date::parse($parser);
73-
$indi->setBurialday($burialday);
76+
$buri = \Gedcom\Parser\Buri::parse($parser);
77+
$indi->setBuri($buri);
7478
break;
7579
case 'CENS':
7680
case 'CHR':
7781
case 'CHRA':
7882
case 'CONF':
7983
case 'CREM':
8084
case 'DEAT':
81-
$deathday = \Gedcom\Parser\Date::parse($parser);
82-
$indi->setDeathday($deathday);
85+
$deat = \Gedcom\Parser\Deat::parse($parser);
86+
$indi->setDeat($deat);
8387
break;
8488
case 'EMIG':
8589
case 'FCOM':

src/Record/Birt.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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 Gedcom\Record;
16+
17+
use Gedcom\Record;
18+
19+
/**
20+
* Class Chan.
21+
*/
22+
class Birt extends \Gedcom\Record
23+
{
24+
private $months = [
25+
'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06',
26+
'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12',
27+
];
28+
29+
public $date;
30+
31+
public $year;
32+
33+
public $dateFormatted;
34+
35+
public $dati;
36+
37+
public $plac;
38+
39+
public function setDate($date) {
40+
$this->date = $date;
41+
if ($this->getDay()) {
42+
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
43+
}
44+
else {
45+
$this->year = $date;
46+
$this->date = null;
47+
}
48+
}
49+
50+
public function getDateFormatted() {
51+
return $this->dateFormatted;
52+
}
53+
54+
public function getDate() {
55+
return $this->date;
56+
}
57+
58+
public function setDati($dati) {
59+
$this->dati = $dati;
60+
}
61+
62+
public function getDati() {
63+
return $this->dati;
64+
}
65+
66+
public function setPlac($plac) {
67+
$this->plac = $plac;
68+
}
69+
70+
public function getPlac() {
71+
return $this->plac;
72+
}
73+
74+
public function getDay()
75+
{
76+
$record = explode(' ', $this->date);
77+
if (!empty($record[0])) {
78+
if ($this->isPrefix($record[0])) {
79+
unset($record[0]);
80+
}
81+
if (count($record) > 0) {
82+
$day = (int) reset($record);
83+
if ($day >= 1 && $day <= 31) {
84+
return $day;
85+
}
86+
}
87+
}
88+
89+
return null;
90+
}
91+
92+
public function getMonth()
93+
{
94+
$record = explode(' ', $this->date);
95+
if (count($record) > 0) {
96+
if ($this->isPrefix($record[0])) {
97+
unset($record[0]);
98+
}
99+
foreach ($record as $part) {
100+
if (isset($this->months[trim($part)])) {
101+
return $this->months[trim($part)];
102+
}
103+
}
104+
}
105+
106+
return null;
107+
}
108+
109+
public function getYear()
110+
{
111+
$record = explode(' ', $this->date);
112+
if (count($record) > 0) {
113+
if ($this->isPrefix($record[0])) {
114+
unset($record[0]);
115+
}
116+
if (count($record) > 0) {
117+
return (int) end($record);
118+
}
119+
}
120+
121+
return null;
122+
}
123+
124+
private function isPrefix($datePart)
125+
{
126+
return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']);
127+
}
128+
}

0 commit comments

Comments
 (0)