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
54 changes: 54 additions & 0 deletions src/Parser/Chr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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 Chr extends \Gedcom\Parser\Component
{
public static function parse(\Gedcom\Parser $parser)
{
$record = $parser->getCurrentLineRecord();
$depth = (int) $record[0];

$parser->forward();

$chr = new \Gedcom\Record\Chr();

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

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

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

$parser->forward();
}

return $chr;
}
}
3 changes: 3 additions & 0 deletions src/Parser/Indi.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public static function parse(\Gedcom\Parser $parser)
break;
case 'CENS':
case 'CHR':
$chr = \Gedcom\Parser\Chr::parse($parser);
$indi->setChr($chr);
break;
case 'CHRA':
case 'CONF':
case 'CREM':
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Indi/Attr.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function parse(\Gedcom\Parser $parser)
$record = $parser->getCurrentLineRecord();
$depth = (int) $record[0];
if (isset($record[1])) {
$className = 'GedcomRecordIndi'.ucfirst(strtolower(trim($record[1])));
$className = '\\Gedcom\\Record\\Indi\\'.ucfirst(strtolower(trim($record[1])));
$attr = new $className();

$attr->setType(trim($record[1]));
Expand Down
6 changes: 4 additions & 2 deletions src/Record/Birt.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Birt extends \Gedcom\Record
];

public $date;

public $month;

public $year;

Expand All @@ -42,8 +44,8 @@ public function setDate($date) {
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
}
else {
$this->year = $date;
$this->date = null;
$this->month = $this->getMonth();
$this->year = $this->getYear();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/Record/Buri.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Buri extends \Gedcom\Record

public $date;

public $month;

public $year;

public $dateFormatted = null;
Expand All @@ -42,9 +44,8 @@ public function setDate($date) {
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
}
else {
$this->dateFormatted = null;
$this->year = $date;
$this->date = null;
$this->month = $this->getMonth();
$this->year = $this->getYear();
}
}

Expand Down
110 changes: 110 additions & 0 deletions src/Record/Chr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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 Chr 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 $dateFormatted = null;

public $plac;

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

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

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

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']);
}
}
6 changes: 4 additions & 2 deletions src/Record/Deat.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Deat extends \Gedcom\Record

public $date;

public $month;

public $year;

public $dateFormatted = null;
Expand All @@ -44,8 +46,8 @@ public function setDate($date) {
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2);
}
else {
$this->year = $date;
$this->date = null;
$this->month = $this->getMonth();
$this->year = $this->getYear();
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/Record/Indi.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class Indi extends \Gedcom\Record implements Noteable, Objectable, Sourceable
protected $buri;

protected $deat;

protected $chr;

public function setBirt($birt) {
$this->birt = $birt;
Expand All @@ -176,6 +178,14 @@ public function getDeat() {
return $this->deat;
}

public function setChr($chr) {
$this->chr = $chr;
}

public function getChr() {
return $this->chr;
}

/**
* @param string $id
*
Expand Down