Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 698ad91

Browse files
authoredAug 27, 2021
Merge pull request #31 from familytree365/fix/gedcom_import_export
Fix Titl error and fix not filled for titl, fams, famc, and chr when …
2 parents ca48496 + 71734f6 commit 698ad91

File tree

8 files changed

+190
-8
lines changed

8 files changed

+190
-8
lines changed
 

‎src/Parser/Chr.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 <kristopherwilson@gmail.com>
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 Chr 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+
$chr = new \Gedcom\Record\Chr();
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+
$chr->setDate(trim($record[2]));
41+
break;
42+
case 'PLAC':
43+
$chr->setPlac(trim($record[2]));
44+
break;
45+
default:
46+
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
47+
}
48+
49+
$parser->forward();
50+
}
51+
52+
return $chr;
53+
}
54+
}

‎src/Parser/Indi.php

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public static function parse(\Gedcom\Parser $parser)
7878
break;
7979
case 'CENS':
8080
case 'CHR':
81+
$chr = \Gedcom\Parser\Chr::parse($parser);
82+
$indi->setChr($chr);
83+
break;
8184
case 'CHRA':
8285
case 'CONF':
8386
case 'CREM':

‎src/Parser/Indi/Attr.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function parse(\Gedcom\Parser $parser)
2121
$record = $parser->getCurrentLineRecord();
2222
$depth = (int) $record[0];
2323
if (isset($record[1])) {
24-
$className = 'GedcomRecordIndi'.ucfirst(strtolower(trim($record[1])));
24+
$className = '\\Gedcom\\Record\\Indi\\'.ucfirst(strtolower(trim($record[1])));
2525
$attr = new $className();
2626

2727
$attr->setType(trim($record[1]));

‎src/Record/Birt.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Birt extends \Gedcom\Record
2727
];
2828

2929
public $date;
30+
31+
public $month;
3032

3133
public $year;
3234

@@ -42,8 +44,8 @@ public function setDate($date) {
4244
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
4345
}
4446
else {
45-
$this->year = $date;
46-
$this->date = null;
47+
$this->month = $this->getMonth();
48+
$this->year = $this->getYear();
4749
}
4850
}
4951

‎src/Record/Buri.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Buri extends \Gedcom\Record
2828

2929
public $date;
3030

31+
public $month;
32+
3133
public $year;
3234

3335
public $dateFormatted = null;
@@ -42,9 +44,8 @@ public function setDate($date) {
4244
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
4345
}
4446
else {
45-
$this->dateFormatted = null;
46-
$this->year = $date;
47-
$this->date = null;
47+
$this->month = $this->getMonth();
48+
$this->year = $this->getYear();
4849
}
4950
}
5051

‎src/Record/Chr.php

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 <kristopherwilson@gmail.com>
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 Chr 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 $dateFormatted = null;
32+
33+
public $plac;
34+
35+
public function setDate($date) {
36+
$this->date = $date;
37+
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
38+
}
39+
40+
public function getDateFormatted() {
41+
return $this->dateFormatted;
42+
}
43+
44+
public function getDate() {
45+
return $this->date;
46+
}
47+
48+
public function setPlac($plac) {
49+
$this->plac = $plac;
50+
}
51+
52+
public function getPlac() {
53+
return $this->plac;
54+
}
55+
56+
public function getDay()
57+
{
58+
$record = explode(' ', $this->date);
59+
if (!empty($record[0])) {
60+
if ($this->isPrefix($record[0])) {
61+
unset($record[0]);
62+
}
63+
if (count($record) > 0) {
64+
$day = (int) reset($record);
65+
if ($day >= 1 && $day <= 31) {
66+
return $day;
67+
}
68+
}
69+
}
70+
71+
return null;
72+
}
73+
74+
public function getMonth()
75+
{
76+
$record = explode(' ', $this->date);
77+
if (count($record) > 0) {
78+
if ($this->isPrefix($record[0])) {
79+
unset($record[0]);
80+
}
81+
foreach ($record as $part) {
82+
if (isset($this->months[trim($part)])) {
83+
return $this->months[trim($part)];
84+
}
85+
}
86+
}
87+
88+
return null;
89+
}
90+
91+
public function getYear()
92+
{
93+
$record = explode(' ', $this->date);
94+
if (count($record) > 0) {
95+
if ($this->isPrefix($record[0])) {
96+
unset($record[0]);
97+
}
98+
if (count($record) > 0) {
99+
return (int) end($record);
100+
}
101+
}
102+
103+
return null;
104+
}
105+
106+
private function isPrefix($datePart)
107+
{
108+
return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']);
109+
}
110+
}

‎src/Record/Deat.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Deat extends \Gedcom\Record
2828

2929
public $date;
3030

31+
public $month;
32+
3133
public $year;
3234

3335
public $dateFormatted = null;
@@ -44,8 +46,8 @@ public function setDate($date) {
4446
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
4547
}
4648
else {
47-
$this->year = $date;
48-
$this->date = null;
49+
$this->month = $this->getMonth();
50+
$this->year = $this->getYear();
4951
}
5052
}
5153

‎src/Record/Indi.php

+10
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class Indi extends \Gedcom\Record implements Noteable, Objectable, Sourceable
151151
protected $buri;
152152

153153
protected $deat;
154+
155+
protected $chr;
154156

155157
public function setBirt($birt) {
156158
$this->birt = $birt;
@@ -176,6 +178,14 @@ public function getDeat() {
176178
return $this->deat;
177179
}
178180

181+
public function setChr($chr) {
182+
$this->chr = $chr;
183+
}
184+
185+
public function getChr() {
186+
return $this->chr;
187+
}
188+
179189
/**
180190
* @param string $id
181191
*

0 commit comments

Comments
 (0)
Please sign in to comment.