forked from oguz463/php-gedcom
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from familytree365/fix/gedcom_import_export
Fix Titl error and fix not filled for titl, fams, famc, and chr when …
- Loading branch information
Showing
8 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <kristopherwilson@gmail.com> | ||
* @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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <kristopherwilson@gmail.com> | ||
* @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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters