diff --git a/src/Parser/Birt.php b/src/Parser/Birt.php new file mode 100644 index 00000000..4cc08d5a --- /dev/null +++ b/src/Parser/Birt.php @@ -0,0 +1,57 @@ + + * @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; + } +} diff --git a/src/Parser/Buri.php b/src/Parser/Buri.php new file mode 100644 index 00000000..2bf72b8c --- /dev/null +++ b/src/Parser/Buri.php @@ -0,0 +1,57 @@ + + * @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; + } +} diff --git a/src/Parser/Chan.php b/src/Parser/Chan.php index ffefe485..57e11f3a 100644 --- a/src/Parser/Chan.php +++ b/src/Parser/Chan.php @@ -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; diff --git a/src/Parser/Deat.php b/src/Parser/Deat.php new file mode 100644 index 00000000..0f989ded --- /dev/null +++ b/src/Parser/Deat.php @@ -0,0 +1,60 @@ + + * @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; + } +} diff --git a/src/Parser/Indi.php b/src/Parser/Indi.php index e9ed8784..a7968a1c 100644 --- a/src/Parser/Indi.php +++ b/src/Parser/Indi.php @@ -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])); @@ -61,16 +65,16 @@ 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': @@ -78,8 +82,8 @@ public static function parse(\Gedcom\Parser $parser) 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': diff --git a/src/Record/Birt.php b/src/Record/Birt.php new file mode 100644 index 00000000..d9899814 --- /dev/null +++ b/src/Record/Birt.php @@ -0,0 +1,128 @@ + + * @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']); + } +} diff --git a/src/Record/Buri.php b/src/Record/Buri.php new file mode 100644 index 00000000..468600f7 --- /dev/null +++ b/src/Record/Buri.php @@ -0,0 +1,129 @@ + + * @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 Buri 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 = null; + + 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->dateFormatted = null; + $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']); + } +} diff --git a/src/Record/Chan.php b/src/Record/Chan.php index cad77e39..d92a9ee3 100644 --- a/src/Record/Chan.php +++ b/src/Record/Chan.php @@ -42,7 +42,7 @@ class Chan extends \Gedcom\Record /** * @var string */ - protected $datetime; + protected $datetime = ''; /** * @var array @@ -109,7 +109,7 @@ public function getTime() return $this->time; } - public function setDatetime($date) + public function setDatetime($date = '') { $this->datetime = $date .' '. $this->time; diff --git a/src/Record/Deat.php b/src/Record/Deat.php new file mode 100644 index 00000000..bd7facf7 --- /dev/null +++ b/src/Record/Deat.php @@ -0,0 +1,138 @@ + + * @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 Deat 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 = null; + + public $dati; + + public $plac; + + public $caus; + + 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 setCaus($caus) { + $this->caus = $caus; + } + + public function getCaus() { + return $this->caus; + } + + 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']); + } +} diff --git a/src/Record/Indi.php b/src/Record/Indi.php index 2d9324c5..8ccdc8fb 100644 --- a/src/Record/Indi.php +++ b/src/Record/Indi.php @@ -144,46 +144,36 @@ class Indi extends \Gedcom\Record implements Noteable, Objectable, Sourceable */ protected $asso = []; - protected $birthday; + protected $deathday = []; - protected $deathday; + protected $birt; - protected $burialday; + protected $buri; + + protected $deat; - public function setBirthday($birthday = '') - { - $this->birthday = $birthday; - - return $this; + public function setBirt($birt) { + $this->birt = $birt; } - public function getBirthday() - { - return $this->birthday; + public function getBirt() { + return $this->birt; } - public function setDeathday($deathday = '') - { - $this->deathday = $deathday; - - return $this; + public function setBuri($buri) { + $this->buri = $buri; } - public function getDeathday() - { - return $this->deathday; + public function getBuri() { + return $this->buri; } - public function setBurialday($burialday = '') - { - $this->burialday = $burialday; - - return $this; + public function setDeat($deat) { + $this->deat = $deat; } - public function getBurialday() - { - return $this->burialday; + public function getDeat() { + return $this->deat; } /**