Skip to content

Commit

Permalink
add Head and related writer
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyblue committed Jun 18, 2020
1 parent 4cd2125 commit c1e846b
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 19 deletions.
88 changes: 83 additions & 5 deletions library/PhpGedcom/Writer/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,91 @@ class Head
*/
public static function convert(\PhpGedcom\Record\Head &$head, $format = self::GEDCOM55)
{
$output = "0 HEAD\n" .
$level = 0;
$output = $level." HEAD\n";

($head->getSour() ? Head\Sour::convert($head->getSour(), $format) : '') .
//"1 DEST " . $head-> . "\n" .
"1 DATE " . date("d M Y") . "\n" .
"2 TIME " . date("H:i:s") . "\n";
// level up
$level++;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SOUR
$sour = $head->getSour();
if($sour){
$_convert = \PhpGedcom\Writer\Head\Sour::convert($sour, $level);
$output.=$_convert;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// DEST
$dest = $head->getDest();
if($dest){
$output.=$level." DEST ".$dest."\n";
}

//Subm
$subm = $head->getSubm();
if($subm){
$output.=$level." SUBM ".$subm."\n";
}

// SUBN
$subn = $head->getSubn();
if($subn){
$output.=$level." SUBN ".$subn."\n";
}

// FILE
$file = $head->getFile();
if($file){
$output.=$level." FILE ".$file."\n";
}

// COPR
$copr = $head->getCopr();
if($copr){
$output.=$level." COPR ".$copr."\n";
}

// LANG
$lang = $head->getLang();
if($lang){
$output.=$level." LANG ".$lang."\n";
}
// DATE
$date = $head->getDate();
if($date){
$_convert = \PhpGedcom\Writer\Head\Date::convert($date, $level);
$output.=$_convert;
}


// GEDC
$gedc = $head->getGedc();
if($gedc){
$_convert = \PhpGedcom\Writer\Head\Gedc::convert($gedc, $level);
$output.=$_convert;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CHAR
$char = $head->getChar();
if($char){
$_convert = \PhpGedcom\Writer\Head\Char::convert($char, $level);
$output.=$_convert;
}
// PLAC
$plac = $head->getPlac();
if($plac){
$_convert = \PhpGedcom\Writer\Head\Plac::convert($plac, $level);
$output.=$_convert;
}

// NOTE
$note = $head->getNote();
if($note){
$output.=$level." NOTE ".$note."\n";
}
//
/*
+1 SUBM @<XREF:SUBM>@ {1:1}
+1 SUBN @<XREF:SUBN>@ {0:1}
Expand Down
50 changes: 50 additions & 0 deletions library/PhpGedcom/Writer/Head/Char.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* php-gedcom
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Xiang Ming <wenqiangliu344@gmail.com>
* @copyright Copyright (c) 2010-2013, Xiang Ming
* @package php-gedcom
* @license GPL-3.0
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace PhpGedcom\Writer\Head;

/**
*
*/
class Char
{
/**
* @param \PhpGedcom\Record\Head\Char $char
* @param string $format
* @param int $level
* @return string
*/
public static function convert(\PhpGedcom\Record\Head\Char &$char, $level)
{
$output ="";
// char
$_char = $char->getChar();
if($_char){
$output.=$level." CHAR ".$_char."\n";
}else{
return $output;
}

// level up
$level++;
// VERS
$vers = $char->getVersion();
if($vers){
$output.=$level." VERS ".$vers."\n";
}


return $output;
}
}
48 changes: 48 additions & 0 deletions library/PhpGedcom/Writer/Head/Date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* php-gedcom
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Xiang Ming <wenqiangliu344@gmail.com>
* @copyright Copyright (c) 2010-2013, Xiang Ming
* @package php-gedcom
* @license GPL-3.0
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace PhpGedcom\Writer\Head;

/**
*
*/
class Date
{
/**
* @param \PhpGedcom\Record\Head\Date $date
* @param string $format
* @param int $level
* @return string
*/
public static function convert(\PhpGedcom\Record\Head\Date &$date, $level)
{
$output = "";
$_date = $date->getDate();
if($_date){
$output .=$level." DATE ".$_date."\n";
}else{
return $output;
}

// level up
$level++;
// Time
$time = $date->getTime();
if($time){
$output.=$level." TIME ".$time."\n";
}

return $output;
}
}
47 changes: 47 additions & 0 deletions library/PhpGedcom/Writer/Head/Gedc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* php-gedcom
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Xiang Ming <wenqiangliu344@gmail.com>
* @copyright Copyright (c) 2010-2013, Xiang Ming
* @package php-gedcom
* @license GPL-3.0
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace PhpGedcom\Writer\Head;

/**
*
*/
class Gedc
{
/**
* @param \PhpGedcom\Record\Head\Gedc $gedc
* @param string $format
* @param int $level
* @return string
*/
public static function convert(\PhpGedcom\Record\Head\Gedc &$gedc, $level)
{
$output = $level." GEDC \n";

// level up
$level++;
// VERS
$vers = $gedc->getVersion();
if($vers){
$output.=$level." VERS ".$vers."\n";
}

// FORM
$form = $gedc->getForm();
if($form){
$output.=$level." FORM ".$form."\n";
}
return $output;
}
}
42 changes: 42 additions & 0 deletions library/PhpGedcom/Writer/Head/Plac.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* php-gedcom
*
* php-gedcom is a library for parsing, manipulating, importing and exporting
* GEDCOM 5.5 files in PHP 5.3+.
*
* @author Xiang Ming <wenqiangliu344@gmail.com>
* @copyright Copyright (c) 2010-2013, Xiang Ming
* @package php-gedcom
* @license GPL-3.0
* @link http://github.com/mrkrstphr/php-gedcom
*/

namespace PhpGedcom\Writer\Head;

/**
*
*/
class Plac
{
/**
* @param \PhpGedcom\Record\Head\Plac $plac
* @param string $format
* @param int $level
* @return string
*/
public static function convert(\PhpGedcom\Record\Head\Plac &$plac, $level)
{
$output = $level." PLAC \n";

// level up
$level++;
// FORM
$form = $plac->getForm();
if($form){
$output.=$level." FORM ".$form."\n";
}

return $output;
}
}
47 changes: 39 additions & 8 deletions library/PhpGedcom/Writer/Head/Sour.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 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
* @author Xiang Ming <wenqiangliu344@gmail.com>
* @copyright Copyright (c) 2010-2013, Xiang Ming
* @package php-gedcom
* @license GPL-3.0
* @link http://github.com/mrkrstphr/php-gedcom
Expand All @@ -25,13 +25,44 @@ class Sour
* @param int $level
* @return string
*/
public static function convert(\PhpGedcom\Record\Head\Sour &$sour, $format = self::GEDCOM55, $level = 0)
public static function convert(\PhpGedcom\Record\Head\Sour &$sour, $level)
{
$output = "1 SOUR " . $sour->sour . "\n" .
"2 VERS " . $sour->vers . "\n" .
\PhpGedcom\Writer\Head\Sour\Corp::convert($sour->corp, $format, 2) .
// TODO DATA;
"";
$output = "";
$_sour = $sour->getSour();
if($_sour){
$output.=$level." SOUR ".$_sour."\n";
}else{
return $output;
}

// level up
$level++;

// VERS
$vers = $sour->getVersion();
if($vers){
$output.=$level." VERS ".$vers."\n";
}

// NAME
$name = $sour->getName();
if($name){
$output.=$level." NAME ".$name."\n";
}

// CORP
$corp = $sour->getCorp();
if($corp){
$_convert = \PhpGedcom\Writer\Head\Sour\Corp::convert($corp, $level);
$output.=$_convert;
}

// DATA
$data = $sour->getData();
if($data){
$_convert = \PhpGedcom\Writer\Head\Sour\Data::convert($data, $level);
$output.=$_convert;
}
return $output;
}
}
34 changes: 28 additions & 6 deletions library/PhpGedcom/Writer/Head/Sour/Corp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,35 @@ class Corp
* @param int $level
* @return string
*/
public static function convert(\PhpGedcom\Record\Head\Sour\Corp &$corp, $format = self::GEDCOM55, $level = 2)
public static function convert(\PhpGedcom\Record\Head\Sour\Corp &$corp, $level)
{
$output = "{$level} CORP " . $corp->corp . "\n" .
\PhpGedcom\Writer\Addr::convert($corp->addr, $format, $level + 1);

foreach ($corp->phon as $phon) {
$output .= \PhpGedcom\Writer\Phon::convert($phon, $format, $level + 1);
$output = "";
$_corp = $corp->getCorp();
if($_corp){
$output.=$level." CORP ".$_corp."\n";
}else{
return $output;
}

// level up
$level++;

// ADDR
$addr = $corp->getAddr();
if($addr){
$_convert = \PhpGedcom\Writer\Addr::convert($addr, $level);
$output.=$_convert;
}

// phon
$phon = $corp->getPhon();
if($phon && count($phon) > 0){
foreach($phon as $item){
if($item){
$_convert = \PhpGedcom\Writer\Phon::convert($item, $level);
$output.=$_convert;
}
}
}

return $output;
Expand Down
Loading

0 comments on commit c1e846b

Please sign in to comment.