Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/Parser/Birt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* php-gedcom.
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Kristopher Wilson <[email protected]>
* @copyright Copyright (c) 2010-2013, Kristopher Wilson
* @license MIT
*
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace Gedcom\Parser;

class Birt extends \Gedcom\Parser\Component
{
public static function parse(\Gedcom\Parser $parser)
{
$record = $parser->getCurrentLineRecord();
$depth = (int) $record[0];

$parser->forward();

$birt = new \Gedcom\Record\Birt();

while (!$parser->eof()) {
$record = $parser->getCurrentLineRecord();
$recordType = trim($record[1]);
$currentDepth = (int) $record[0];

if ($currentDepth <= $depth) {
$parser->back();
break;
}

switch ($recordType) {
case 'DATE':
$birt->setDate(trim($record[2]));
break;
case '_DATI':
$birt->setDati(trim($record[2]));
break;
case 'PLAC':
$birt->setPlac(trim($record[2]));
break;
default:
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
}

$parser->forward();
}

return $birt;
}
}
57 changes: 57 additions & 0 deletions src/Parser/Buri.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* php-gedcom.
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Kristopher Wilson <[email protected]>
* @copyright Copyright (c) 2010-2013, Kristopher Wilson
* @license MIT
*
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace Gedcom\Parser;

class Buri extends \Gedcom\Parser\Component
{
public static function parse(\Gedcom\Parser $parser)
{
$record = $parser->getCurrentLineRecord();
$depth = (int) $record[0];

$parser->forward();

$buri = new \Gedcom\Record\Buri();

while (!$parser->eof()) {
$record = $parser->getCurrentLineRecord();
$recordType = trim($record[1]);
$currentDepth = (int) $record[0];

if ($currentDepth <= $depth) {
$parser->back();
break;
}

switch ($recordType) {
case 'DATE':
$buri->setDate(trim($record[2]));
break;
case '_DATI':
$buri->setDati(trim($record[2]));
break;
case 'PLAC':
$buri->setPlac(trim($record[2]));
break;
default:
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
}

$parser->forward();
}

return $buri;
}
}
2 changes: 1 addition & 1 deletion src/Parser/Chan.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function parse(\Gedcom\Parser $parser)
$parser->forward();
}

$date = $chan->getYear() .'-'. $chan->getMonth() .'-'. $chan->getDay() ;
$date = $chan->getYear() .'-'. $chan->getMonth() .'-'. $chan->getDay();
$chan->setDatetime($date);

return $chan;
Expand Down
60 changes: 60 additions & 0 deletions src/Parser/Deat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* php-gedcom.
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Kristopher Wilson <[email protected]>
* @copyright Copyright (c) 2010-2013, Kristopher Wilson
* @license MIT
*
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace Gedcom\Parser;

class Deat extends \Gedcom\Parser\Component
{
public static function parse(\Gedcom\Parser $parser)
{
$record = $parser->getCurrentLineRecord();
$depth = (int) $record[0];

$parser->forward();

$deat = new \Gedcom\Record\Deat();

while (!$parser->eof()) {
$record = $parser->getCurrentLineRecord();
$recordType = trim($record[1]);
$currentDepth = (int) $record[0];

if ($currentDepth <= $depth) {
$parser->back();
break;
}

switch ($recordType) {
case 'DATE':
$deat->setDate(trim($record[2]));
break;
case '_DATI':
$deat->setDati(trim($record[2]));
break;
case 'PLAC':
$deat->setPlac(trim($record[2]));
break;
case 'CAUS':
$deat->setCaus(trim($record[2]));
break;
default:
$parser->logUnhandledRecord(self::class.' @ '.__LINE__);
}

$parser->forward();
}

return $deat;
}
}
16 changes: 10 additions & 6 deletions src/Parser/Indi.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static function parse(\Gedcom\Parser $parser)
break;
}

if ($recordType == 'BURI') {
$a='';
}

switch ($recordType) {
case '_UID':
$indi->setUid(trim($record[2]));
Expand All @@ -61,25 +65,25 @@ public static function parse(\Gedcom\Parser $parser)
break;
case 'ADOP':
case 'BIRT':
$birthday = \Gedcom\Parser\Date::parse($parser);
$indi->setBirthday($birthday);
$birt = \Gedcom\Parser\Birt::parse($parser);
$indi->setBirt($birt);
break;
case 'BAPM':
case 'BARM':
case 'BASM':
case 'BLES':
case 'BURI':
$burialday = \Gedcom\Parser\Date::parse($parser);
$indi->setBurialday($burialday);
$buri = \Gedcom\Parser\Buri::parse($parser);
$indi->setBuri($buri);
break;
case 'CENS':
case 'CHR':
case 'CHRA':
case 'CONF':
case 'CREM':
case 'DEAT':
$deathday = \Gedcom\Parser\Date::parse($parser);
$indi->setDeathday($deathday);
$deat = \Gedcom\Parser\Deat::parse($parser);
$indi->setDeat($deat);
break;
case 'EMIG':
case 'FCOM':
Expand Down
128 changes: 128 additions & 0 deletions src/Record/Birt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* php-gedcom.
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Kristopher Wilson <[email protected]>
* @copyright Copyright (c) 2010-2013, Kristopher Wilson
* @license MIT
*
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace Gedcom\Record;

use Gedcom\Record;

/**
* Class Chan.
*/
class Birt extends \Gedcom\Record
{
private $months = [
'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06',
'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12',
];

public $date;

public $year;

public $dateFormatted;

public $dati;

public $plac;

public function setDate($date) {
$this->date = $date;
if ($this->getDay()) {
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
}
else {
$this->year = $date;
$this->date = null;
}
}

public function getDateFormatted() {
return $this->dateFormatted;
}

public function getDate() {
return $this->date;
}

public function setDati($dati) {
$this->dati = $dati;
}

public function getDati() {
return $this->dati;
}

public function setPlac($plac) {
$this->plac = $plac;
}

public function getPlac() {
return $this->plac;
}

public function getDay()
{
$record = explode(' ', $this->date);
if (!empty($record[0])) {
if ($this->isPrefix($record[0])) {
unset($record[0]);
}
if (count($record) > 0) {
$day = (int) reset($record);
if ($day >= 1 && $day <= 31) {
return $day;
}
}
}

return null;
}

public function getMonth()
{
$record = explode(' ', $this->date);
if (count($record) > 0) {
if ($this->isPrefix($record[0])) {
unset($record[0]);
}
foreach ($record as $part) {
if (isset($this->months[trim($part)])) {
return $this->months[trim($part)];
}
}
}

return null;
}

public function getYear()
{
$record = explode(' ', $this->date);
if (count($record) > 0) {
if ($this->isPrefix($record[0])) {
unset($record[0]);
}
if (count($record) > 0) {
return (int) end($record);
}
}

return null;
}

private function isPrefix($datePart)
{
return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']);
}
}
Loading